Abelian sandpile model: Difference between revisions

m
→‎{{header|Pascal}}: added link to python abelian (64)
(added pascal)
m (→‎{{header|Pascal}}: added link to python abelian (64))
Line 770:
{{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>
Memorizing the used colums of the rows has little effect when choosing the right size of the grid.12%Only for abelian(10000) but only 611 secs for abelian(1e6) -> 1min 14secs aka 8%9sec<BR>
[http://rosettacode.org/wiki/Abelian_sandpile_model#Python Python] shows 64 too.
<lang pascal>
program Abelian2;
Line 942 ⟶ 943:
procedure OneTurn(count:NativeUint);
begin
Writeln(' Test abilianabelian sandpile( ',count,' )');
MaxVal := count;
InitGrid(Grid,count);
Line 962 ⟶ 963:
{{out}}
<pre>
Test abilianabelian sandpile( 4 )
010
101
010
columns 3 checksum 4 ?=? 4
Test abilianabelian sandpile( 16 )
00100
02120
Line 974 ⟶ 975:
00100
columns 5 checksum 16 ?=? 16
Test abilianabelian sandpile( 64 )
00121000
02222200
Line 984 ⟶ 985:
00000000
columns 8 checksum 64 ?=? 64
Test abilianabelian sandpile( 1000 )
0000000001111111000000000
0000000130233320310000000
Line 1,011 ⟶ 1,012:
0000000001111111000000000
columns 25 checksum 1000 ?=? 1000
Test abilianabelian sandpile( 10000 )
--shortened
columns 77 checksum 10000 ?=? 10000
Test abilianabelian sandpile( 100000 )
columns 241 checksum 100000 ?=? 100000
 
real 0m0,815s
</pre>
 
=={{header|Perl}}==
<lang Perl>#!/usr/bin/perl
Anonymous user