Abelian sandpile model: Difference between revisions
Content added Content deleted
(added pascal) |
m (→{{header|Pascal}}: added link to python abelian (64)) |
||
Line 770: | Line 770: | ||
{{works with|Free Pascal}} |
{{works with|Free Pascal}} |
||
The main optimization was to spread the sand immediatly.<pre>mul := val DIV 4;//not only := val -4 </pre> so that only (sand mod 4) stays in place.runtime for abelian(1e6) down to 1min 20 secs from 9 min<BR> |
The main optimization was to spread the sand immediatly.<pre>mul := val DIV 4;//not only := val -4 </pre> so that only (sand mod 4) stays in place.runtime for abelian(1e6) down to 1min 20 secs from 9 min<BR> |
||
Memorizing the used colums of the rows has little effect when choosing the right size of the grid. |
Memorizing the used colums of the rows has little effect when choosing the right size of the grid.Only 11 secs for abelian(1e6) -> 1min 9sec<BR> |
||
[http://rosettacode.org/wiki/Abelian_sandpile_model#Python Python] shows 64 too. |
|||
<lang pascal> |
<lang pascal> |
||
program Abelian2; |
program Abelian2; |
||
Line 942: | Line 943: | ||
procedure OneTurn(count:NativeUint); |
procedure OneTurn(count:NativeUint); |
||
begin |
begin |
||
Writeln(' Test |
Writeln(' Test abelian sandpile( ',count,' )'); |
||
MaxVal := count; |
MaxVal := count; |
||
InitGrid(Grid,count); |
InitGrid(Grid,count); |
||
Line 962: | Line 963: | ||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Test |
Test abelian sandpile( 4 ) |
||
010 |
010 |
||
101 |
101 |
||
010 |
010 |
||
columns 3 checksum 4 ?=? 4 |
columns 3 checksum 4 ?=? 4 |
||
Test |
Test abelian sandpile( 16 ) |
||
00100 |
00100 |
||
02120 |
02120 |
||
Line 974: | Line 975: | ||
00100 |
00100 |
||
columns 5 checksum 16 ?=? 16 |
columns 5 checksum 16 ?=? 16 |
||
Test |
Test abelian sandpile( 64 ) |
||
00121000 |
00121000 |
||
02222200 |
02222200 |
||
Line 984: | Line 985: | ||
00000000 |
00000000 |
||
columns 8 checksum 64 ?=? 64 |
columns 8 checksum 64 ?=? 64 |
||
Test |
Test abelian sandpile( 1000 ) |
||
0000000001111111000000000 |
0000000001111111000000000 |
||
0000000130233320310000000 |
0000000130233320310000000 |
||
Line 1,011: | Line 1,012: | ||
0000000001111111000000000 |
0000000001111111000000000 |
||
columns 25 checksum 1000 ?=? 1000 |
columns 25 checksum 1000 ?=? 1000 |
||
Test |
Test abelian sandpile( 10000 ) |
||
--shortened |
--shortened |
||
columns 77 checksum 10000 ?=? 10000 |
columns 77 checksum 10000 ?=? 10000 |
||
Test |
Test abelian sandpile( 100000 ) |
||
columns 241 checksum 100000 ?=? 100000 |
columns 241 checksum 100000 ?=? 100000 |
||
real 0m0,815s |
real 0m0,815s |
||
</pre> |
</pre> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
<lang Perl>#!/usr/bin/perl |
<lang Perl>#!/usr/bin/perl |