18
4
This question is about abelian sandpiles. Read this previous challenge and watch this numberphile video to learn more.
An abelian sandpile of size n by n is a grid containing the number 0, 1, 2 and 3 (representing the number of grains of sand). Adding two sandpiles works by first adding element by element, and then toppling any element that goes above 3. The order in which you topple doesn't matter, the end result is the same. When a cell topples its number decreases by 4, and each of its direct neighbors increases by 1. This can cause a chain reaction. If a cell is on the edge of the grid, any grains that fall off the grid while toppling disappear.
For example, I'm adding two 3 by 3 sandpiles (giving a rather extreme chain reaction):
3 3 3 1 2 1 4 5 4 4 6 4 6 2 6 6 3 6 2 5 2 4 1 4 4 2 4 0 4 0 2 0 2 2 1 2
3 3 3 + 2 1 2 = 5 4 5 -> 6 0 6 -> 2 4 2 -> 3 0 3 -> 5 0 5 -> 1 4 1 -> 2 0 2 -> 4 0 4 -> 0 4 0 -> 1 0 1
3 3 3 1 2 1 4 5 4 4 6 4 6 2 6 6 3 6 2 5 2 4 1 4 4 2 4 0 4 0 2 0 2 2 1 2
In this challenge we're interested in a subset of all possible n by n sandpiles. This subset contains any sandpile that you can get by adding an arbitrary sandpile to the all-3s n by n sandpile. For example, just above we saw that 212 | 101 | 212
is in the subset, because we got it by adding something to the all-3 sandpile.
Now this subset has an interesting element: the identity element. If you take this element and add it to any other element in the subset, the sum is unchanged. In other words, this sandpile acts like a zero of this subset. It just so happens that 212 | 101 | 212
is the zero element for the subset of 3 by 3. For example:
2 2 2 2 1 2 4 3 4 0 5 0 2 1 2 2 2 2
2 2 2 + 1 0 1 = 3 2 3 -> 5 2 5 -> 1 6 1 -> 2 2 2
2 2 2 2 1 2 4 3 4 0 5 0 2 1 2 2 2 2
Now this is your challenge: given n, find the identity element of the subset of the n by n grid. Output it by assigning a unique color with sufficient contrast of your choice to each of 0, 1, 2, 3
and outputting an n by n image. Your code must be able to produce the 50 by 50 case in under a minute on a reasonable modern PC.
For example, the 500 by 500 identity element:
Here is blue = 3, green = 2, red = 1, white = 0. But you don't have to use this color scheme in your answer.
2A word of warning to competitors: I described what the solution is, not how to compute it. Your code must be able to produce the 50 by 50 case in under a minute, so brute forcing is not a possibility. There are algorithms for solving this, and I'm not giving you them. That's intentional. I feel that too many challenges present you with pre-chewed food. I will give a +100 bounty to the first answer that doesn't trivialize the problem with a builtin (looking at you, Mathematica), at my discretion. – orlp – 2017-01-15T22:19:37.370
2I think the image of the 500x500 identity would benefit from saying what number each color corresponds to. – xnor – 2017-01-15T22:21:29.860
What constitutes "sufficient contrast"? – Conor O'Brien – 2017-01-15T22:44:54.603
@ConorO'Brien Any set of colors that are sufficiently distinguishable. I could make it 100% objective with some color measure, but I feel that's overkill. I don't care if you use red, yellow, green, grayscale, or whatever, just don't use 4 shades of grey that are within 1% of eachother (like #000000, #000001, #000002, #000003). – orlp – 2017-01-15T22:51:39.607
ahem I believe this question is now eligible for bounty. Could I get the +100 bonus? :) – JungHwan Min – 2017-02-01T01:48:14.630
@JungHwanMin Gotta wait 24 hours :) – orlp – 2017-02-01T11:31:15.463