f=->i{i=i.split.map(&:to_i);(1..4).each{|n|i[-n-1]+=i[-n]/2;i[-n]%=2};i} p f.call("3 8 6 0 2")
Standard input is empty
[8, 1, 0, 1, 0]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!