blob: 2a2a41279f25cf7d1a43463ef6930db1089c6ee3 (
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-152
//
//
// Run as: node ch-1.js < input-file
//
require ('readline')
. createInterface ({input: process . stdin})
. on ('line', line => {
let numbers = line . trim () . split (/ +/) . map (n => +n)
let minsum = 0
let n = 1
while (numbers . length) {
minsum += Math . min (... numbers . splice (0, n ++))
}
console . log (minsum)
})
|