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