E2C2S - try harder!

Problem #383

Tags: c-1 puzzle data-structures

Who solved this?

No translations... yet

Thanks a lot to Mathias Kern aka gardengnome for this new story from the secret life of the Easter Bunnies!

Easter eggs come in millions of colours, and these colours are numbered from 0 to 2097151. The Easter bunnies explain to you that some colours match much better than others, and the Easter Egg Colour Compatibility Score – well-known as E2C2S – of two colours c1 and c2 is calculated as the bitwise XOR of c1 and c2. For example, the E2C2S of 3 and 4 is 7.

Having introduced you to the science behind E2C2S, you are immediately set a challenge: find the sum of the maximum possible E2C2S scores for each egg from a list of eggs when they can be paired with any egg from the same list. The bunnies give you the list [5, 9, 4], and after a short moment you have worked out 5 XOR 9 = 12, 9 XOR 4 = 13 and 4 XOR 9 = 13, and you answer 12+13+13 = 38. That was easy, and you tell the bunnies to try harder!

‘No problem’ reply the bunnies, do the same for N=777,777 eggs.

Input: A single integer X0 that is used as the seed for the Linear Congruential Generator introduced in the problem 25 - use A=445, C=700001 and M=2097152. Generate N=777,777 random values – this gives you a list of N egg colours (some colours might well feature multiple times).

Output: The sum of the maximum possible E2C2S scores for each egg from the generated list of eggs when they can be paired with any egg from the same list (for X0=0, the answer is 1631114497593).

You need to login to get test data and submit solution.