Abelian sandpile model: Difference between revisions

Content added Content deleted
(Added a Scheme implementation.)
m (syntax highlighting fixup automation)
Line 30: Line 30:
</pre>
</pre>
=={{header|11l}}==
=={{header|11l}}==
<lang 11l>V grid = [[0] * 10] * 10
<syntaxhighlight lang=11l>V grid = [[0] * 10] * 10
grid[5][5] = 64
grid[5][5] = 64


Line 77: Line 77:
L(row) grid
L(row) grid
L(c) row
L(c) row
ppm.write_bytes(colors[c])</lang>
ppm.write_bytes(colors[c])</syntaxhighlight>


{{out}}
{{out}}
Line 109: Line 109:
{{works with|as|Raspberry Pi 3B version Buster 64 bits
{{works with|as|Raspberry Pi 3B version Buster 64 bits
or android 64 bits with application Termux }}
or android 64 bits with application Termux }}
<lang AArch64 Assembly>
<syntaxhighlight lang=AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */
/* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */
/* program abelian64.s */
/* program abelian64.s */
Line 306: Line 306:
/* for this file see task include a file in language AArch64 assembly */
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
{{Output}}
{{Output}}
<pre>
<pre>
Line 340: Line 340:
=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}
<lang ARM Assembly>
<syntaxhighlight lang=ARM Assembly>
/* ARM assembly Raspberry PI or android 32 bits */
/* ARM assembly Raspberry PI or android 32 bits */
/* program abelian.s */
/* program abelian.s */
Line 532: Line 532:
/***************************************************/
/***************************************************/
.include "../affichage.inc"
.include "../affichage.inc"
</syntaxhighlight>
</lang>
{{output}}
{{output}}
<pre>
<pre>
Line 565: Line 565:
=={{header|C}}==
=={{header|C}}==
Writes out the initial and final sand piles to the console and the final sand pile to a PPM file.
Writes out the initial and final sand piles to the console and the final sand pile to a PPM file.
<syntaxhighlight lang=C>
<lang C>
#include<stdlib.h>
#include<stdlib.h>
#include<string.h>
#include<string.h>
Line 686: Line 686:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>


Console output :
Console output :
Line 725: Line 725:
<!-- c++ bindings -->
<!-- c++ bindings -->
<br>
<br>
<lang cpp>#include <iostream>
<syntaxhighlight lang=cpp>#include <iostream>
#include "xtensor/xarray.hpp"
#include "xtensor/xarray.hpp"
#include "xtensor/xio.hpp"
#include "xtensor/xio.hpp"
Line 798: Line 798:


return 0;
return 0;
}</lang>
}</syntaxhighlight>
Compile with following <tt>CMakeList.txt</tt>:
Compile with following <tt>CMakeList.txt</tt>:
<lang cmake>cmake_minimum_required(VERSION 3.1)
<syntaxhighlight lang=cmake>cmake_minimum_required(VERSION 3.1)
project(abelian_sandpile)
project(abelian_sandpile)


Line 814: Line 814:


target_compile_options(abelian_sandpile PRIVATE -march=native -std=c++14)
target_compile_options(abelian_sandpile PRIVATE -march=native -std=c++14)
target_link_libraries(abelian_sandpile xtensor ${OIIO})</lang>
target_link_libraries(abelian_sandpile xtensor ${OIIO})</syntaxhighlight>


=={{header|Delphi}}==
=={{header|Delphi}}==
{{Trans|Python}}
{{Trans|Python}}
<lang Delphi>
<syntaxhighlight lang=Delphi>
program Abelian_sandpile_model;
program Abelian_sandpile_model;


Line 978: Line 978:
Readln;
Readln;
end.
end.
</syntaxhighlight>
</lang>




Line 984: Line 984:
{{works with|gforth|0.7.3}}
{{works with|gforth|0.7.3}}
<br>
<br>
<lang forth>#! /usr/bin/gforth -d 20M
<syntaxhighlight lang=forth>#! /usr/bin/gforth -d 20M
\ Abelian Sandpile Model
\ Abelian Sandpile Model


Line 1,049: Line 1,049:
: simulate prepare begin stack-full? while 2dup 2>r reduce 2r> inc-all repeat drop to-pgm ." written to " filename type cr ;
: simulate prepare begin stack-full? while 2dup 2>r reduce 2r> inc-all repeat drop to-pgm ." written to " filename type cr ;


simulate bye</lang>
simulate bye</syntaxhighlight>


{{out}}
{{out}}
Line 1,065: Line 1,065:
{{works with|gfortran|9.2.0}}
{{works with|gfortran|9.2.0}}
The Abelian sandpile operations are defined here.
The Abelian sandpile operations are defined here.
<lang fortran>module abelian_sandpile_m
<syntaxhighlight lang=fortran>module abelian_sandpile_m


implicit none
implicit none
Line 1,156: Line 1,156:
end subroutine
end subroutine


end module</lang>
end module</syntaxhighlight>


The <code>main</code> program calls the <code>abelian_sandpile_m</code> and creates an ppm bitmap file by loading <code>rgbimage_m</code> module, which is defined [[Basic bitmap storage#Fortran|here]].
The <code>main</code> program calls the <code>abelian_sandpile_m</code> and creates an ppm bitmap file by loading <code>rgbimage_m</code> module, which is defined [[Basic bitmap storage#Fortran|here]].
<lang fortran>program main
<syntaxhighlight lang=fortran>program main


use rgbimage_m
use rgbimage_m
Line 1,194: Line 1,194:
call im%write('fig.ppm')
call im%write('fig.ppm')


end program</lang>
end program</syntaxhighlight>


=={{header|Fōrmulæ}}==
=={{header|Fōrmulæ}}==
Line 1,205: Line 1,205:


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>
<syntaxhighlight lang=fsharp>
// Abelian sandpile model. Nigel Galloway: July 20th., 2020
// Abelian sandpile model. Nigel Galloway: July 20th., 2020
type Sandpile(x,y,N:int[])=
type Sandpile(x,y,N:int[])=
Line 1,232: Line 1,232:
let e1=Array.zeroCreate<int> 25 in e1.[12]<-6; printfn "%s\n" (Sandpile(5,5,e1)).toS
let e1=Array.zeroCreate<int> 25 in e1.[12]<-6; printfn "%s\n" (Sandpile(5,5,e1)).toS
let e1=Array.zeroCreate<int> 25 in e1.[12]<-16; printfn "%s\n" (Sandpile(5,5,e1)).toS
let e1=Array.zeroCreate<int> 25 in e1.[12]<-16; printfn "%s\n" (Sandpile(5,5,e1)).toS
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,260: Line 1,260:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>ScreenRes 320, 200, 8
<syntaxhighlight lang=freebasic>ScreenRes 320, 200, 8
WindowTitle "Abelian sandpile model"
WindowTitle "Abelian sandpile model"


Line 1,290: Line 1,290:
Loop Until partic < 4
Loop Until partic < 4
Bsave "abelian_sandpile.bmp",0
Bsave "abelian_sandpile.bmp",0
Sleep</lang>
Sleep</syntaxhighlight>
{{out}}
{{out}}
<pre>[https://www.dropbox.com/s/lky2ji9n15gn5u6/abelian_sandpile.bmp?dl=0 Abelian sandpile model FreeBasic image]
<pre>[https://www.dropbox.com/s/lky2ji9n15gn5u6/abelian_sandpile.bmp?dl=0 Abelian sandpile model FreeBasic image]
Line 1,300: Line 1,300:
<br>
<br>
Stack management in Go is automatic, starting very small (2KB) for each goroutine and expanding as necessary until the maximum allowed size is reached.
Stack management in Go is automatic, starting very small (2KB) for each goroutine and expanding as necessary until the maximum allowed size is reached.
<lang go>package main
<syntaxhighlight lang=go>package main


import (
import (
Line 1,408: Line 1,408:
// after the recursive algorithm has ended.
// after the recursive algorithm has ended.
// writePile(pile)
// writePile(pile)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,438: Line 1,438:
<br>
<br>
Using a custom monad to make the code cleaner.
Using a custom monad to make the code cleaner.
<lang haskell>{-# LANGUAGE FlexibleContexts #-}
<syntaxhighlight lang=haskell>{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ScopedTypeVariables #-}
Line 1,553: Line 1,553:
fp = printf "sandpile_%d_%d.pgm" size height
fp = printf "sandpile_%d_%d.pgm" size height
toPGM b fp
toPGM b fp
putStrLn $ "wrote image to " ++ fp</lang>
putStrLn $ "wrote image to " ++ fp</syntaxhighlight>


{{out}}
{{out}}
Line 1,563: Line 1,563:
=={{header|J}}==
=={{header|J}}==


<lang J>grid=: 4 : 'x (<<.-:2$y)} (2$y)$0' NB. y by y grid with x grains in middle
<syntaxhighlight lang=J>grid=: 4 : 'x (<<.-:2$y)} (2$y)$0' NB. y by y grid with x grains in middle
ab=: - [: +/@(-"2 ((,-)=/~i.2)|.!.0]) 3&< NB. abelian sand pile for grid graph
ab=: - [: +/@(-"2 ((,-)=/~i.2)|.!.0]) 3&< NB. abelian sand pile for grid graph
require 'viewmat' NB. viewmat utility
require 'viewmat' NB. viewmat utility
viewmat ab ^: _ (1024 grid 25) NB. visual </lang>
viewmat ab ^: _ (1024 grid 25) NB. visual </syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
This is based on the JavaScript implementation linked to in the task description.
This is based on the JavaScript implementation linked to in the task description.
<lang java>import java.awt.*;
<syntaxhighlight lang=java>import java.awt.*;
import java.awt.event.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.*;
Line 1,682: Line 1,682:
};
};
private static final int GRID_LENGTH = 300;
private static final int GRID_LENGTH = 300;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,689: Line 1,689:
=={{header|Julia}}==
=={{header|Julia}}==
Modified from code by Hayk Aleksanyan, viewable at github.com/hayk314/Sandpiles, license viewable there.
Modified from code by Hayk Aleksanyan, viewable at github.com/hayk314/Sandpiles, license viewable there.
<lang julia>module AbelSand
<syntaxhighlight lang=julia>module AbelSand


# supports output functionality for the results of the sandpile simulations
# supports output functionality for the results of the sandpile simulations
Line 1,964: Line 1,964:


Z_lat, Odometer = AbelSand.move(100000)
Z_lat, Odometer = AbelSand.move(100000)
</lang>{{out}}
</syntaxhighlight>{{out}}
[http://alahonua.com/temp/Abel_Z_color_100000.png Link to PNG output file for N=100000 ie. AbelSand.move(100000)] <br />
[http://alahonua.com/temp/Abel_Z_color_100000.png Link to PNG output file for N=100000 ie. AbelSand.move(100000)] <br />
[http://alahonua.com/temp/Abel_Z_color_1000000.png Link to PNG output file (run time >90 min) for N=1000000 (move(1000000))]
[http://alahonua.com/temp/Abel_Z_color_1000000.png Link to PNG output file (run time >90 min) for N=1000000 (move(1000000))]


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>local sandpile = {
<syntaxhighlight lang=lua>local sandpile = {
init = function(self, dim, val)
init = function(self, dim, val)
self.cell, self.dim = {}, dim
self.cell, self.dim = {}, dim
Line 2,006: Line 2,006:
sandpile:init(15, 256)
sandpile:init(15, 256)
sandpile:iter()
sandpile:iter()
sandpile:draw()</lang>
sandpile:draw()</syntaxhighlight>
{{out}}
{{out}}
<pre>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
<pre>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Line 2,025: Line 2,025:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>ClearAll[sp]
<syntaxhighlight lang=Mathematica>ClearAll[sp]
sp[s_List] + sp[n_Integer] ^:= sp[s] + sp[ConstantArray[n, Dimensions[s]]]
sp[s_List] + sp[n_Integer] ^:= sp[s] + sp[ConstantArray[n, Dimensions[s]]]
sp[s_List] + sp[t_List] ^:= Module[{dim, r, tmp, neighbours}, dim = Dimensions[s];
sp[s_List] + sp[t_List] ^:= Module[{dim, r, tmp, neighbours}, dim = Dimensions[s];
Line 2,039: Line 2,039:
u = sp[CenterArray[250, {15, 15}]];
u = sp[CenterArray[250, {15, 15}]];
u += sp[0];
u += sp[0];
StringRiffle[StringJoin /@ Map[ToString, u[[1]], {2}], "\n"]</lang>
StringRiffle[StringJoin /@ Map[ToString, u[[1]], {2}], "\n"]</syntaxhighlight>
{{out}}
{{out}}
<pre>000000000000000
<pre>000000000000000
Line 2,061: Line 2,061:
Our program uses Rust algorithm (and also its colors 🙂) and the formula to compute grid size from number of particles comes from Pascal algorithm.
Our program uses Rust algorithm (and also its colors 🙂) and the formula to compute grid size from number of particles comes from Pascal algorithm.
Number of particles is an input from user. The program displays the values on the terminal if there are not too many and produce a PNG image. Code to produce a PPM image is also provided but not used.
Number of particles is an input from user. The program displays the values on the terminal if there are not too many and produce a PNG image. Code to produce a PPM image is also provided but not used.
<lang Nim>
<syntaxhighlight lang=Nim>
# Abelian sandpile.
# Abelian sandpile.


Line 2,208: Line 2,208:
#grid.writePpmFile(fmt"grid_{initVal}.ppm")
#grid.writePpmFile(fmt"grid_{initVal}.ppm")
grid.writePngFile(fmt"grid_{initVal}.png")
grid.writePngFile(fmt"grid_{initVal}.png")
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 2,235: Line 2,235:
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>
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.
[http://rosettacode.org/wiki/Abelian_sandpile_model#Python Python] shows 64 too.
<lang pascal>
<syntaxhighlight lang=pascal>
program Abelian2;
program Abelian2;
{$IFDEF FPC}
{$IFDEF FPC}
Line 2,423: Line 2,423:
OneTurn(100000);
OneTurn(100000);
END.
END.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,487: Line 2,487:
{{works with|OCaml|4.11}}
{{works with|OCaml|4.11}}
In Sandpile module (sandpile.ml)
In Sandpile module (sandpile.ml)
<lang OCaml>
<syntaxhighlight lang=OCaml>
module Make =
module Make =
functor (M : sig val m : int val n : int end)
functor (M : sig val m : int val n : int end)
Line 2,567: Line 2,567:
; S.avalanche ()
; S.avalanche ()
; S.print ()
; S.print ()
</syntaxhighlight>
</lang>


=={{header|Perl}}==
=={{header|Perl}}==
<lang Perl>#!/usr/bin/perl
<syntaxhighlight lang=Perl>#!/usr/bin/perl


use strict; # http://www.rosettacode.org/wiki/Abelian_sandpile_model
use strict; # http://www.rosettacode.org/wiki/Abelian_sandpile_model
Line 2,593: Line 2,593:
}
}
select undef, undef, undef, 0.1; # comment out for full speed
select undef, undef, undef, 0.1; # comment out for full speed
}</lang>
}</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
Line 2,599: Line 2,599:
Generates moving images similar to the julia output.
Generates moving images similar to the julia output.
The distributed version also has variable speed, additional display modes, and a random dropping toggle.
The distributed version also has variable speed, additional display modes, and a random dropping toggle.
<!--<lang Phix>-->
<!--<syntaxhighlight lang=Phix>-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Abelian_sandpile_model.exw</span>
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Abelian_sandpile_model.exw</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 2,692: Line 2,692:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|Python}}==
=={{header|Python}}==
===Python: Original, with output===
===Python: Original, with output===
<lang Python>import numpy as np
<syntaxhighlight lang=Python>import numpy as np
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt


Line 2,734: Line 2,734:
plt.figure()
plt.figure()
plt.gray()
plt.gray()
plt.imshow(final_grid)</lang>
plt.imshow(final_grid)</syntaxhighlight>
{{Out}}
{{Out}}
Before:
Before:
<lang Python>[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
<syntaxhighlight 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.]
Line 2,746: Line 2,746:
[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>
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]</syntaxhighlight>
After:
After:
<lang Python>[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
<syntaxhighlight lang=Python>[[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,757: Line 2,757:
[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.]]</lang>
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]</syntaxhighlight>


An interactive variant to the above solution:
An interactive variant to the above solution:
<lang Python>from os import system, name
<syntaxhighlight lang=Python>from os import system, name
from time import sleep
from time import sleep


Line 2,825: Line 2,825:
run(area)
run(area)
print('\nAfter:')
print('\nAfter:')
show_area(area)</lang>
show_area(area)</syntaxhighlight>
{{Out}}
{{Out}}
<lang Python>
<syntaxhighlight lang=Python>
Before:
Before:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Line 2,851: Line 2,851:
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
</syntaxhighlight>
</lang>


===Python: using tkinter===
===Python: using tkinter===
<lang Python>
<syntaxhighlight 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.'''
Line 2,970: Line 2,970:
## 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
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
Line 2,978: Line 2,978:
Defaults to a stack of 1000 and showing progress. Pass in a custom stack size if desired and -hide-progress to run without displaying progress (much faster.)
Defaults to a stack of 1000 and showing progress. Pass in a custom stack size if desired and -hide-progress to run without displaying progress (much faster.)


<lang perl6>sub cleanup { print "\e[0m\e[?25h\n"; exit(0) }
<syntaxhighlight lang=perl6>sub cleanup { print "\e[0m\e[?25h\n"; exit(0) }


signal(SIGINT).tap: { cleanup(); exit(0) }
signal(SIGINT).tap: { cleanup(); exit(0) }
Line 3,024: Line 3,024:
print "\e[1;1H", @buffer.map( { @color[$_ min 4] }).join;
print "\e[1;1H", @buffer.map( { @color[$_ min 4] }).join;


cleanup;</lang>
cleanup;</syntaxhighlight>


Passing in 2048 as a stack size results in: [https://github.com/thundergnat/rc/blob/master/img/Abelian-sandpile-model-perl6.png Abelian-sandpile-model-perl6.png] (offsite .png image)
Passing in 2048 as a stack size results in: [https://github.com/thundergnat/rc/blob/master/img/Abelian-sandpile-model-perl6.png Abelian-sandpile-model-perl6.png] (offsite .png image)


===SDL2 Animation===
===SDL2 Animation===
<lang perl6>use NativeCall;
<syntaxhighlight lang=perl6>use NativeCall;
use SDL2::Raw;
use SDL2::Raw;


Line 3,125: Line 3,125:
}
}
$fps
$fps
}</lang>
}</syntaxhighlight>


Passing in a stack size of 20000 results in: [https://github.com/thundergnat/rc/blob/master/img/Abelian-sandpile-sdl2.png Abelian-sandpile-sdl2.png] (offsite .png image)
Passing in a stack size of 20000 results in: [https://github.com/thundergnat/rc/blob/master/img/Abelian-sandpile-sdl2.png Abelian-sandpile-sdl2.png] (offsite .png image)


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>// This is the main algorithm.
<syntaxhighlight lang=rust>// This is the main algorithm.
//
//
// It loops over the current state of the sandpile and updates it on-the-fly.
// It loops over the current state of the sandpile and updates it on-the-fly.
Line 3,251: Line 3,251:
display(&playfield);
display(&playfield);
//write_pile(&playfield);
//write_pile(&playfield);
}</lang>
}</syntaxhighlight>


'''Output:'''
'''Output:'''
Line 3,274: Line 3,274:
=={{header|Scheme}}==
=={{header|Scheme}}==
{{works with|Chez Scheme}}
{{works with|Chez Scheme}}
<lang scheme>; A two-dimensional grid of values...
<syntaxhighlight lang=scheme>; A two-dimensional grid of values...


; Create an empty (all cells 0) grid of the specified size.
; Create an empty (all cells 0) grid of the specified size.
Line 3,377: Line 3,377:
(asm-stabilize asm)
(asm-stabilize asm)
(printf "After:~%")
(printf "After:~%")
(grid-display asm digcnt)))</lang>
(grid-display asm digcnt)))</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,403: Line 3,403:


=={{header|VBA}}==
=={{header|VBA}}==
<lang VBA>Sub SetupPile(a As Integer, b As Integer)
<syntaxhighlight lang=VBA>Sub SetupPile(a As Integer, b As Integer)
Application.ScreenUpdating = False
Application.ScreenUpdating = False
For i = 1 To a
For i = 1 To a
Line 3,549: Line 3,549:
Debug.Print "End:" & Now()
Debug.Print "End:" & Now()


End Sub</lang>
End Sub</syntaxhighlight>
'''Output:'''
'''Output:'''
<pre>
<pre>
Line 3,558: Line 3,558:
{{trans|Go}}
{{trans|Go}}


<lang vlang>import os
<syntaxhighlight lang=vlang>import os
import strings
import strings


Line 3,653: Line 3,653:
// after the recursive algorithm has ended.
// after the recursive algorithm has ended.
// write_pile(pile)
// write_pile(pile)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 3,678: Line 3,678:
=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/fmt" for Fmt
<syntaxhighlight lang=ecmascript>import "/fmt" for Fmt


class Sandpile {
class Sandpile {
Line 3,747: Line 3,747:
var str2 = s.toString
var str2 = s.toString
printAcross.call(str1, str2)
printAcross.call(str1, str2)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 3,782: Line 3,782:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>def Size = 200;
<syntaxhighlight lang=XPL0>def Size = 200;
char Pile1(Size*Size), Pile2(Size*Size);
char Pile1(Size*Size), Pile2(Size*Size);
int Spigot, I, X, Y;
int Spigot, I, X, Y;
Line 3,808: Line 3,808:
I:= Pile1; Pile1:= Pile2; Pile2:= I;
I:= Pile1; Pile1:= Pile2; Pile2:= I;
until Spigot < 4;
until Spigot < 4;
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}