Skip to content

Instantly share code, notes, and snippets.

@danprince
Last active December 20, 2015 14:58
Show Gist options
  • Save danprince/6150241 to your computer and use it in GitHub Desktop.
Save danprince/6150241 to your computer and use it in GitHub Desktop.
Game of Life: Io Golf
f :=File with("l")
f openForUpdating
l :=f readLines
h :=l size
C :=method(x,y,
if(x>=0 and x<h,
if(y>=0 and y<h,
return l at(y) at(x)-48)
)
return 0
)
N :=method(x,y,
c:=0
for(i,-1,1,
for(j,-1,1,
if(C(x + i,y + j)==1,
c:=c + 1
)
)
)
c=c-C(x,y)
return cf
)
w :=list()
for(y,0,h-1,
r :=list()
for(x,0,h-1,
c :=C(x,y);
n :=N(x,y);
if(c==1,
if(n==2 or n==3,
r push(1),r push(0))
,
if(n==3,
r push(1),r push(0))
)
)
w push(r)
)
w foreach(i,r,w atPut(i,r join))
o :=w join("\n")
f rewind
f write(out)
f close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment