124 lines
2.6 KiB
Text
124 lines
2.6 KiB
Text
void local fn SandpilePrint( s(2,2) as ^long )
|
|
long r, c
|
|
for r = 0 to 2
|
|
for c = 0 to 2
|
|
printf @"%ld\t",s(r,c)
|
|
next
|
|
print
|
|
next
|
|
print
|
|
end fn
|
|
|
|
void local fn SandpileTopple( s(2,2) as ^long )
|
|
BOOL stable = NO
|
|
long r, c, value
|
|
|
|
while ( stable == NO )
|
|
stable = YES
|
|
for r = 0 to 2
|
|
for c = 0 to 2
|
|
value = s(r,c)
|
|
if ( value > 3 )
|
|
s(r,c) -= 4
|
|
if ( r > 0 ) then s(r-1,c)++
|
|
if ( r < 2 ) then s(r+1,c)++
|
|
if ( c > 0 ) then s(r,c-1)++
|
|
if ( c < 2 ) then s(r,c+1)++
|
|
print @"⇣ ⇣ ⇣ ⇣ ⇣"
|
|
print
|
|
fn SandpilePrint( s(0,0) )
|
|
stable = NO : break
|
|
end if
|
|
next
|
|
if ( stable == NO ) then break
|
|
next
|
|
wend
|
|
end fn
|
|
|
|
void local fn SandpileLoad( s(2,2) as ^long, values as CFStringRef )
|
|
long r, c, i = 0
|
|
for r = 0 to 2
|
|
for c = 0 to 2
|
|
s(r,c) = intval(mid(values,i,1))
|
|
i++
|
|
next
|
|
next
|
|
end fn
|
|
|
|
void local fn DoIt
|
|
long r, c, s(2,2), s1(2,2), s2(2,2), s3(2,2), s3_id(2,2)
|
|
|
|
// s
|
|
text @"Menlo-Bold" : print @"avalanche"
|
|
text @"Menlo" : print @"----------"
|
|
fn SandpileLoad( s(0,0), @"433312023" )
|
|
fn SandpilePrint( s(0,0) )
|
|
fn SandpileTopple( s(0,0) )
|
|
|
|
// s1
|
|
fn SandpileLoad( s1(0,0), @"120211013" )
|
|
|
|
// s2
|
|
fn SandpileLoad( s2(0,0), @"213101010" )
|
|
|
|
// s1 + s2
|
|
for r = 0 to 2
|
|
for c = 0 to 2
|
|
s(r,c) = s1(r,c) + s2(r,c)
|
|
next
|
|
next
|
|
text @"Menlo-Bold" : print @"s1 + s2"
|
|
text @"Menlo" : print @"----------"
|
|
fn SandpileTopple( s(0,0) )
|
|
fn SandpilePrint( s(0,0) )
|
|
|
|
// s2 + s1
|
|
for r = 0 to 2
|
|
for c = 0 to 2
|
|
s(r,c) = s2(r,c) + s1(r,c)
|
|
next
|
|
next
|
|
text @"Menlo-Bold" : print @"s2 + s1"
|
|
text @"Menlo" : print @"----------"
|
|
fn SandpileTopple( s(0,0) )
|
|
fn SandpilePrint( s(0,0) )
|
|
|
|
// s3
|
|
fn SandpileLoad( s3(0,0), @"333333333" )
|
|
text @"Menlo-Bold" : print @"s3"
|
|
text @"Menlo" : print @"----------"
|
|
fn SandpilePrint( s3(0,0) )
|
|
|
|
// s3_id
|
|
fn SandpileLoad( s3_id(0,0), @"212101212" )
|
|
text @"Menlo-Bold" : print @"s3_id"
|
|
text @"Menlo" : print @"----------"
|
|
fn SandpilePrint( s3_id(0,0) )
|
|
|
|
// s3 + s3_id
|
|
for r = 0 to 2
|
|
for c = 0 to 2
|
|
s(r,c) = s3(r,c) + s3_id(r,c)
|
|
next
|
|
next
|
|
text @"Menlo-Bold" : print @"s3+s3_id"
|
|
text @"Menlo" : print @"----------"
|
|
fn SandpilePrint( s(0,0) )
|
|
fn SandpileTopple( s(0,0) )
|
|
|
|
// s3_id + s3_id
|
|
for r = 0 to 2
|
|
for c = 0 to 2
|
|
s(r,c) = s3_id(r,c) + s3_id(r,c)
|
|
next
|
|
next
|
|
text @"Menlo-Bold" : print @"s3_id+s3_id"
|
|
text @"Menlo" : print @"-----------"
|
|
fn SandpilePrint( s(0,0) )
|
|
fn SandpileTopple( s(0,0) )
|
|
|
|
end fn
|
|
|
|
fn DoIt
|
|
|
|
HandleEvents
|