diff options
| author | Abigail <abigail@abigail.be> | 2020-12-17 02:54:35 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2020-12-20 01:57:10 +0100 |
| commit | c5ddab618e42c74be87e07c12026e797734804ab (patch) | |
| tree | 751be83d1da3563d6543934a95c54c09e80b02cd /challenge-091 | |
| parent | 2f67539c644274244d8166f5f94704abcf697e0d (diff) | |
| download | perlweeklychallenge-club-c5ddab618e42c74be87e07c12026e797734804ab.tar.gz perlweeklychallenge-club-c5ddab618e42c74be87e07c12026e797734804ab.tar.bz2 perlweeklychallenge-club-c5ddab618e42c74be87e07c12026e797734804ab.zip | |
Node.js solution for week 091/part 2
Diffstat (limited to 'challenge-091')
| -rw-r--r-- | challenge-091/abigail/node/ch-2.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-091/abigail/node/ch-2.js b/challenge-091/abigail/node/ch-2.js new file mode 100644 index 0000000000..5c65b9763a --- /dev/null +++ b/challenge-091/abigail/node/ch-2.js @@ -0,0 +1,22 @@ +// +// Read STDIN. Split on newlines, filter out empty lines, +// split each line on white space, then call "show" +// + require ("fs") +. readFileSync (0) // Read all. +. toString () // Turn it into a string. +. split ("\n") // Split on newlines. +. filter (_ => _ . length) // Filter out empty lines. +. map (_ => _ . split (/\s+/) // Split on whitespace. + . map (_ => +_)) // And numify the parts. +. map (_ => hop (_)) +; + +// +// Do the main work +// +function hop (array) { + let i; + for (i = 0; i < array . length - 1; i += array [i]) {} + process . stdout . write (i == (array . length - 1) ? "1\n" : "0\n"); +} |
