Jump to content

Abelian sandpile model: Difference between revisions

(Added 11l)
(→‎{{header|11l}}: Write PPM)
Line 37:
print(row.map(c -> ‘#3’.format(c)).join(‘’))
 
F simulate(&grid)
L
L
V changed = 0B
L(arr) grid
VL(arr) ii = L.indexgrid
L(val) arr V ii = L.index
VL(val) jj = L.indexarr
I val > 3V jj = L.index
grid[ii][jj]I -=val 4> 3
I grid[ii][jj] >-= 04
grid[I ii -> 1][jj]++0
I ii < grid.len[ii - 1][jj]++
grid[I ii +< grid.len - 1][jj]++
I jj > 0 grid[ii + 1][jj]++
grid[ii][I jj -> 1]++0
I jj < grid.len[ii][jj - 1]++
grid[ii][I jj +< grid.len - 1]++
changed = 1B grid[ii][jj + 1]++
I ! changed = 1B
L.breakI !changed
L.break
 
simulate(&grid)
 
print("\nAfter:")
L(row) grid
print(row.map(c -> ‘#3’.format(c)).join(‘’))</lang>
 
grid = [[0] * 65] * 65
grid[32][32] = 64 * 64
 
simulate(&grid)
 
V ppm = File(‘sand_pile.ppm’, ‘w’)
ppm.write_bytes(("P6\n#. #.\n255\n".format(grid.len, grid.len)).encode())
V colors = [[Byte(0), 0, 0],
[Byte(255), 0, 0],
[Byte(0), 255, 0],
[Byte(0), 0, 255]]
L(arrrow) grid
L(c) row
ppm.write_bytes(colors[c])</lang>
 
{{out}}
1,481

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.