# Making Branko Grünbaum's symmetrical 5-set Venn diagram magic

Place integers 1 to 31 in the 31 regions of Branko Grünbaum's symmetrical 5-set Venn diagram so that the sum inside any of the 5 sets is the same.

First

number the regions 0..31 in the "obvious" way so that set A consists of the regions whose index has bit 0 set, set B consists of those whose index has bit 1 set, etc. That is: set A=1, B=2, C=4, D=8, E=16; and then e.g. the region labelled ACDE gets the number A+C+D+E=1+4+8+16=29. Thus we number the regions with the numbers from 0 (for the external region, not part of any of the sets) to 31 (for the central region, part of them all) consecutively.

Now

construct a 5-bit Gray code using the usual construction: 0, 1, 3, 2, 6, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8, 24, 25, 27, 26, 30, 31, 29, 28, 20, 21, 23, 22, 18, 19, 17, 16. A little adding up reveals that this gives sums of 248 for sets A,B,C,D but 376 for set E. (Note 1: 248 is exactly half of 0+1+...+30+31. Note 2: Why a Gray code? Well, actually, it just seemed like it might work out, and it turned out pretty well. You can probably do something similar using the Morse-Thue sequence duplicated at various power-of-2 scales, but just as with the Gray code it'll only handle four of the sets and leave one that needs fixing up.)

And now

fix it up by hand, swapping entries n and n+16 to adjust the sum for set E until it too has sum 248. We can do this in various ways; I picked this one: 24, 25, 27, 26, 30, 7, 5, 4, 12, 13, 15, 14, 10, 11, 9, 8, 0, 1, 3, 2, 6, 31, 29, 28, 20, 21, 23, 22, 18, 19, 17, 16.

• In the way described in the remainder of the sentence. If it's not clear enough I can say it at greater length. – Gareth McCaughan Feb 15 '19 at 21:35
• Yes, please do. – Bernardo Recamán Santos Feb 15 '19 at 21:50
• OK, done. (And a few comments on the rabbit-out-of-hat in the second spoilered paragraph.) – Gareth McCaughan Feb 15 '19 at 21:59
• In my answer to the previous four ellipses question I have a method that I think generalises to any number of sets. – Jaap Scherphuis Feb 16 '19 at 12:53
• Oh, that's nice! It's closely related to my solution here, too, I think -- what you're doing is very similar to the calculation for converting Gray code to position, whereas I've done the reverse and then had to patch it up. – Gareth McCaughan Feb 16 '19 at 13:40