Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created September 5, 2015 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d5466bec84e01c761c4d to your computer and use it in GitHub Desktop.
Save anonymous/d5466bec84e01c761c4d to your computer and use it in GitHub Desktop.
$iterations=2
aArr=[1,1,0]
def fold (arr)
fArr=arr
hArr=[]
j=0
while j<(fArr.length+1)/2 do
gArr=[]
gArr.push(fArr.shift,fArr.shift)
switch gArr
when [1,nil]
hArr.push(1,1,0)
when [1,1]
hArr.push(1,1,0,1)
when [1,0]
hArr.push(1,1,0,0)
when [0,1]
hArr.push(1,0,0,1)
when [0,0]
hArr.push(1,0,0,0)
when [0,nil]
hArr.push(1,0,0)
else
hArr.push("ERROR")
end
j+=1
end
return hArr.flatten
end
i=1
while i<$iterations do
aArr=fold(aArr)
i+=1
end
aArr.each {|x| print x}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment