Skip to content

Commit cd1def4

Browse files
committed
Standardize scala output.
Fixed bug in the original implementation (euclid -> euclid_sub).
1 parent 7edccc7 commit cd1def4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

contents/euclidean_algorithm/code/scala/euclidean.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ object Euclid {
33
def euclid_sub(a: Int, b: Int): Int =
44
(Math.abs(a), Math.abs(b)) match {
55
case (0, _) | (_, 0) => 0
6-
case (x, y) if x < y => euclid(x, y - x)
7-
case (x, y) if x > y => euclid(x - y, y)
6+
case (x, y) if x < y => euclid_sub(x, y - x)
7+
case (x, y) if x > y => euclid_sub(x - y, y)
88
case _ => a
99
}
1010

@@ -15,8 +15,10 @@ object Euclid {
1515
}
1616

1717
def main(args: Array[String]): Unit = {
18-
println(euclid_sub(151 * 899, 151 * 182))
19-
println(euclid_mod(151 * 899, 151 * 182))
18+
println("[#]\nModulus-based euclidean algorithm result:")
19+
println(euclid_mod(64 * 67, 64 * 81))
20+
println("[#]\nSubtraction-based euclidean algorithm result:")
21+
println(euclid_sub(128 * 12, 128 * 77))
2022
}
2123

2224
}

0 commit comments

Comments
 (0)