diff options
| author | Abigail <abigail@abigail.be> | 2021-01-30 17:01:45 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-01-30 17:51:27 +0100 |
| commit | 7de0601266583815c0bfb3f00cb71672997b19c3 (patch) | |
| tree | 46c1abc7925da4426abd93df53ae01feca60d531 /challenge-097/abigail/node | |
| parent | 19e332207808276edd1ed1bebd3e907136acc438 (diff) | |
| download | perlweeklychallenge-club-7de0601266583815c0bfb3f00cb71672997b19c3.tar.gz perlweeklychallenge-club-7de0601266583815c0bfb3f00cb71672997b19c3.tar.bz2 perlweeklychallenge-club-7de0601266583815c0bfb3f00cb71672997b19c3.zip | |
Swap the role of sections and section length (size).
We initially implemented the algorithm where the number of sections
is passed in as a parameter. However, it's not the number of sections,
it's the length of each section.
This was an easy fix, as the algorithm is pretty symmetric.
Diffstat (limited to 'challenge-097/abigail/node')
| -rw-r--r-- | challenge-097/abigail/node/ch-2.js | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/challenge-097/abigail/node/ch-2.js b/challenge-097/abigail/node/ch-2.js index c28c3fb2b8..835b675ccc 100644 --- a/challenge-097/abigail/node/ch-2.js +++ b/challenge-097/abigail/node/ch-2.js @@ -5,7 +5,7 @@ // // -// Run as: node ch-2.js -s SECTIONS < input-file +// Run as: node ch-2.js -s SIZE < input-file // const NR_OF_LETTERS = 26 @@ -20,7 +20,7 @@ const argv = require ('yargs') . demandOption ('s') . argv; -const sections = argv . s +const size = argv . s // // Iterate over the input @@ -28,18 +28,18 @@ const sections = argv . s require ('readline') . createInterface ({input: process . stdin}) . on ('line', _ => { - let sum = 0 - let s_len = _ . length / sections // Length of a segment + let sum = 0 + let sections = _ . length / size // // Iterate over the positions // - for (let i = 0; i < s_len; i ++) { + for (let i = 0; i < size; i ++) { // // Count the number of zeros in a specific position // let zeros = 0 for (let j = 0; j < sections; j ++) { - let index = j * s_len + i; + let index = j * size + i; if (_ . substring (index, index + 1) == "0") { zeros ++ } |
