aboutsummaryrefslogtreecommitdiff
path: root/challenge-117/abigail/ruby/ch-2.rb
blob: d80f89616bcf36da34dd8a0dc39a693c3cca11e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/ruby

#
# See ../README.md
#
 
#
# Run as: ruby ch-2.rb < input-file
#

def steps (x, y, path)
    if   x == 0 && y == 0
    then puts (path)
         return
    end
    if   x > 0
    then steps(x - 1, y,     path + "R")
         steps(x - 1, y + 1, path + "L")
    end
    if   y > 0
    then steps(x,     y - 1, path + "H")
    end
end

steps($stdin . read . to_i, 0, "")