Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/abelian-sandpile-model/oracle.py # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / abelian-sandpile-model / oracle.py` 26 lines ยท 919 bytes Raw Blame History 1 # Independent reference for "Abelian sandpile model" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 # a work list of full cells, each toppling all its whole fours at once 4 def pile(n, grains): 5 g = {(r, c): 0 for r in range(n) for c in range(n)} 6 g[n // 2, n // 2] = grains 7 work, tops = [(n // 2, n // 2)], 0 8 while work: 9 r, c = work.pop() 10 k = g[r, c] // 4 11 if k == 0: 12 continue 13 g[r, c] -= 4 * k 14 tops += k 15 for p in ((r - 1, c), (r + 1, c), (r, c - 1), (r, c + 1)): 16 if p in g: 17 g[p] += k 18 if g[p] >= 4: 19 work.append(p) 20 for r in range(n): 21 print(" ".join(str(g[r, c]) for c in range(n))) 22 print("topplings:", tops) 23 for t, (n, grains) in enumerate(((5, 16), (7, 64), (9, 200))): 24 if t: 25 print() 26 pile(n, grains)