diff options
| author | Abigail <abigail@abigail.be> | 2021-05-04 17:18:05 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-05-04 17:18:05 +0200 |
| commit | 120ddabba9a2e7583c5eeb66d4cc4a463f8cedc2 (patch) | |
| tree | 2975946b95a4be24cc239308f1437bf986b701a9 /challenge-111/abigail/node | |
| parent | 4ead8fc53f6cd3b29d00a1bc526d1754c03217d4 (diff) | |
| download | perlweeklychallenge-club-120ddabba9a2e7583c5eeb66d4cc4a463f8cedc2.tar.gz perlweeklychallenge-club-120ddabba9a2e7583c5eeb66d4cc4a463f8cedc2.tar.bz2 perlweeklychallenge-club-120ddabba9a2e7583c5eeb66d4cc4a463f8cedc2.zip | |
Node.js solution for week 111, part 1
Diffstat (limited to 'challenge-111/abigail/node')
| -rw-r--r-- | challenge-111/abigail/node/ch-1.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-111/abigail/node/ch-1.js b/challenge-111/abigail/node/ch-1.js new file mode 100644 index 0000000000..6e97d03272 --- /dev/null +++ b/challenge-111/abigail/node/ch-1.js @@ -0,0 +1,37 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-1.js < input-file +// + +let MATRIX_SIZE = 5 + +// +// Read in all the numbers, both the matrix and the target numbers +// +let numbers = + require ("fs") +. readFileSync (0) // Read all. +. toString () // Turn it into a string. +. match (/-?[0-9]+/g) + +// +// Populate the matrix +// +let matrix = {} +for (let i = 0; i < MATRIX_SIZE * MATRIX_SIZE; i ++) { + matrix [numbers [i]] = 1 +} + +// +// Check the rest of the numbers whether they're present +// in the matrix. +// +for (let j = MATRIX_SIZE * MATRIX_SIZE; j < numbers . length; j ++) { + console . log (matrix [numbers [j]] ? 1 : 0) +} + |
