-
-
Save anonymous/d5466bec84e01c761c4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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