-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcd.hespr
33 lines (26 loc) · 838 Bytes
/
gcd.hespr
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
32
33
{{ comment }}
blok gcdIter|a b $divisor, int|
flux newA newB remainder, int
newA =_ a
newB =_ b
whil newA mod newB > 0
remainder =_ newA mod newB
newA =_ newB
newB =_ remainder
divisor =_ newB
blok gcdRec|a b $divisor, int|
when b = 0
divisor =_ a
else
gcdRec! b (a mod b) $divisor
blok load||
flux divisorArg, int
gcdRec! 57 26 $divisorArg
Write! ("GCD of 57 and 26. Expected: 1. Calculated: " + divisorArg)
gcdIter! 55 25 $divisorArg
Write! ("GCD of 55 and 25. Expected: 5. Calculated: " + divisorArg)
gcdRec! 460 64 $divisorArg
Write! ("GCD of 460 and 64. Expected: 4. Calculated: " + divisorArg)
gcdIter! 1035 747 $divisorArg
Write! "GCD of 1035 and 747. Expected: 9. Calculated:" divisorArg
Write! ""