ruby - Pascal triangle using nested for loop -


i need primed shape. need output like:

    1    0 1    0 1 0   1 0 1 0 

i tried print left side of triangle, don't know print full triangle. code printing left side of triangle:

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

i output this:

1  0 1  1 0 1  0 1 0 1  1 0 1 0 1 

just add print " "*(5-i) , this:

for in 1..5   print " "*(5-i)   j in 1..i   if (i%2 == 0);     k = (j%2 == 0) ? 1:0;   else;      k = (j%2 ==0) ? 0:1;    end   print k," "  end  puts end 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -