From 120ddabba9a2e7583c5eeb66d4cc4a463f8cedc2 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 4 May 2021 17:18:05 +0200 Subject: Node.js solution for week 111, part 1 --- challenge-111/abigail/README.md | 1 + challenge-111/abigail/node/ch-1.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 challenge-111/abigail/node/ch-1.js diff --git a/challenge-111/abigail/README.md b/challenge-111/abigail/README.md index bd9ef31d26..a7ac678775 100644 --- a/challenge-111/abigail/README.md +++ b/challenge-111/abigail/README.md @@ -35,6 +35,7 @@ languages, the fact input is sorted does not offer additional benefits. * [Bash](bash/ch-1.sh) * [C](c/ch-1.c) * [Lua](lua/ch-1.lua) +* [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) ### Blog 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) +} + -- cgit