fork download
  1. f=->n{a=[0]*n;n.times{|i|i.times{|j|a[i]|=1<<j if i%2!=j%2}};a}
  2.  
  3. arr=f.(18)
  4. arr.each { |i| puts "#{i} (#{i.to_s 2})"}
Success #stdin #stdout 0.01s 6104KB
stdin
Standard input is empty
stdout
0 (0)
1 (1)
2 (10)
5 (101)
10 (1010)
21 (10101)
42 (101010)
85 (1010101)
170 (10101010)
341 (101010101)
682 (1010101010)
1365 (10101010101)
2730 (101010101010)
5461 (1010101010101)
10922 (10101010101010)
21845 (101010101010101)
43690 (1010101010101010)
87381 (10101010101010101)