From 4699f600935129b16a48074d8534411ce935db17 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 3 Jan 2022 12:25:51 +0100 Subject: Week 146 Part 1 is a fixed output challenge, so, just a glorified Hello World program. It's stolen from project Euler, task 7. --- challenge-146/abigail/node/ch-1.js | 11 +++++++++++ challenge-146/abigail/node/ch-2.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 challenge-146/abigail/node/ch-1.js create mode 100644 challenge-146/abigail/node/ch-2.js (limited to 'challenge-146/abigail/node') diff --git a/challenge-146/abigail/node/ch-1.js b/challenge-146/abigail/node/ch-1.js new file mode 100644 index 0000000000..51ce680b89 --- /dev/null +++ b/challenge-146/abigail/node/ch-1.js @@ -0,0 +1,11 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-1.js +// + +console . log ("104743") \ No newline at end of file diff --git a/challenge-146/abigail/node/ch-2.js b/challenge-146/abigail/node/ch-2.js new file mode 100644 index 0000000000..ce7fba74c7 --- /dev/null +++ b/challenge-146/abigail/node/ch-2.js @@ -0,0 +1,31 @@ +#!/usr/local/bin/node + +// +// See ../README.md +// + +// +// Run as: node ch-2.js < input-file +// + + require ('readline') +. createInterface ({input: process . stdin}) +. on ('line', line => { + let [a, b] = line . trim () . split ("/") . map (x => +x) + for (let i = 1; i <= 2; i ++) { + if (a < b) { + b -= a + } + else { + a -= b + } + if (a == 0 || b == 0) { + break + } + process . stdout . write (a . toString ()) + process . stdout . write ("/") + process . stdout . write (b . toString ()) + process . stdout . write (" ") + } + process . stdout . write ("\n") +}) -- cgit