aboutsummaryrefslogtreecommitdiff
path: root/challenge-117/abigail/node/ch-2.js
blob: 2cc510bd696b9fb08527f32eb96abd645c47a1c6 (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
26
27
#!/usr/local/bin/node

//
// See ../README.md
//

//
// Run as: node ch-2.js < input-file
//

function steps (x, y, path) {
    if (x == 0 && y == 0) {
        console . log (path)
        return
    }
    if (x > 0) {
        steps (x - 1, y,     path + "R")
        steps (x - 1, y + 1, path + "L")
    }
    if (y > 0) {
        steps (x,     y - 1, path + "H")
    }
}

  require         ('readline')
. createInterface ({input: process . stdin})   
. on              ('line', number => steps (+number, 0, ""))