aboutsummaryrefslogtreecommitdiff
path: root/challenge-146/abigail/node/ch-2.js
blob: ce7fba74c7e8e2e176d9733fd44e5b83f671ddff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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")
})