ruby - How to work in nested `for`-loop -


i need output of floyd triangle like:

1 0 1 1 0 1 0 1 0 1 

i tried. didn't exactly. can explain logic?

this code tried:

k = 0 in 1..5    j in 1..5      if (i%2)==0;        k = (j%2==0) ? 1:0;      else;        k = (j%2==0) ? 0:1;        puts k,'';      end   end   puts end 

the main issue here in order "triangle" shape of output, need inner loop increment 1 instead of 1 5.

k = 0 in 1..5    j in 1..i     if (i%2)==0       k = j + 1     else       k = j     end     print "#{k%2} "   end   puts end 

Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -