aboutsummaryrefslogtreecommitdiff
path: root/challenge-151/abigail/node/ch-2.js
blob: 11a88c6bc7e3ade4600a457a8a85be12d1f82605 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/local/bin/node

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

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

  require ('readline')
. createInterface ({input: process . stdin})   
. on              ('line', line => {
    let h = line . trim () . split (/ +/) . map (n => +n)
    h [h . length] = 0
    h [h . length] = 0
    for (let i = h . length - 3; i >= 2; i --) {
        h [i] = Math . max (h [i] + h [i + 2], h [i + 1])
    }
    console . log (h [0] + h [2])
})