diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-01-04 21:18:09 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-04 21:18:09 +0000 |
| commit | d1581f755d50e5b3a5ccf74a25280f39caa809fc (patch) | |
| tree | 14d50cbd3a19dddf06cb89f16ea57155024e1da6 /challenge-146/abigail/node/ch-2.js | |
| parent | d8abd054e8e70147188d2b57c922ba092e2aecff (diff) | |
| parent | 41c3d16c97874e85d25f28d37e59df3e2d9a9d66 (diff) | |
| download | perlweeklychallenge-club-d1581f755d50e5b3a5ccf74a25280f39caa809fc.tar.gz perlweeklychallenge-club-d1581f755d50e5b3a5ccf74a25280f39caa809fc.tar.bz2 perlweeklychallenge-club-d1581f755d50e5b3a5ccf74a25280f39caa809fc.zip | |
Merge pull request #5463 from Abigail/abigail/week-146
Week 146
Diffstat (limited to 'challenge-146/abigail/node/ch-2.js')
| -rw-r--r-- | challenge-146/abigail/node/ch-2.js | 31 |
1 files changed, 31 insertions, 0 deletions
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") +}) |
