def f(x) x[Y-1]?puts(x*' '):((x[-1]||0)+1..X).map{|d|f(x+[d])} end gets=~/ / X=$`.to_i Y=$'.to_i f([])