-
-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy patheuclidean.go
More file actions
48 lines (37 loc) · 629 Bytes
/
euclidean.go
File metadata and controls
48 lines (37 loc) · 629 Bytes
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Submitted by Chinmaya Mahesh (chin123)
package main
import "fmt"
func abs(a int) int {
if a < 0 {
a = -a
}
return a
}
func euclidMod(a, b int) int {
a = abs(a)
b = abs(b)
for b != 0 {
a, b = b, a%b
}
return a
}
func euclidSub(a, b int) int {
a = abs(a)
b = abs(b)
for a != b {
if a > b {
a -= b
} else {
b -= a
}
}
return a
}
func main() {
check1 := euclidMod(64*67, 64*81)
check2 := euclidSub(128*12, 128*77)
fmt.Println("[#]\nModulus-based euclidean algorithm result:")
fmt.Println(check1)
fmt.Println("[#]\nSubtraction-based euclidean algorithm result:")
fmt.Println(check2)
}