aboutsummaryrefslogtreecommitdiff
path: root/challenge-151/abigail/node/ch-1.js
blob: bf67eda21e54ceaa74ab2da2219a88e9271a2287 (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
28
29
30
31
32
33
#!/usr/local/bin/node

//
// See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
//

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

  require ('readline')
. createInterface ({input: process . stdin})   
. on              ('line', line => {
    let tree = line . split ("\|") . map (row => row . trim () . split (/ +/))

    for (let d = 0; d < tree . length; d ++) {
        if (d == tree . length - 1) {
            return
        }
        let c_row = tree [d]
        let n_row = tree [d + 1]
        for (let i = 0; i < c_row . length; i ++) {
            let ch1 = 2 * i
            let ch2 = 2 * i + 1
            if (c_row [i] != "*"                                   &&
                     (ch1 >= n_row . length || n_row [ch1] == "*") &&
                     (ch2 >= n_row . length || n_row [ch2] == "*")) {
                console . log (d + 1)
                return;
            }
        }
    }
})