Abelian sandpile model: Difference between revisions

m
→‎{{header|Python}}: fixed lang tags
(Added XPL0 example.)
m (→‎{{header|Python}}: fixed lang tags)
Line 2,657:
=={{header|Python}}==
===Python: Original, with output===
<lang Python>import numpy as np
import numpy as np
import matplotlib.pyplot as plt
 
Line 2,696 ⟶ 2,695:
plt.figure()
plt.gray()
plt.imshow(final_grid)</lang>
{{Out}}
</lang>
<b>Output:</b> </n>
Before:
<lang Python>[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
Line 2,710 ⟶ 2,707:
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]</lang>
</lang>
After:
<lang Python>[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 1. 2. 1. 0. 0. 0. 0.]
[0. 0. 2. 2. 2. 2. 2. 0. 0. 0.]
Line 2,723 ⟶ 2,718:
[0. 0. 0. 1. 2. 1. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]</lang>
</lang>
 
 
An interactive variant to the above solution:
<lang Python>from os import system, name
<lang python>
from os import system, name
from time import sleep
 
Line 2,794 ⟶ 2,786:
run(area)
print('\nAfter:')
show_area(area)</lang>
{{Out}}
</lang>
</lang Python>
 
Output:
<lang>
Before:
0 0 0 0 0 0 0 0 0 0
Line 2,825 ⟶ 2,815:
 
===Python: using tkinter===
<lang pythonPython>
''' Python 3.6.5 code using Tkinter graphical user
interface (Canvas widget) to display final results.'''
7,806

edits