Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $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}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement