23 lines
592 B
Mojo
23 lines
592 B
Mojo
# probe: recursion, // and % on Int
|
|
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
|
|
# expect-stdout: 6 1 9
|
|
# expect-stdout: 12 42
|
|
# expect-stdout: lcm 1..10: 2520
|
|
def gcd(a: Int, b: Int) -> Int:
|
|
if b == 0:
|
|
return a
|
|
return gcd(b, a % b)
|
|
|
|
|
|
def lcm(a: Int, b: Int) -> Int:
|
|
return a // gcd(a, b) * b
|
|
|
|
|
|
def main():
|
|
print(gcd(48, 18), gcd(17, 5), gcd(0, 9))
|
|
print(lcm(4, 6), lcm(21, 6))
|
|
var total = 1
|
|
for k in range(1, 11):
|
|
total = lcm(total, k)
|
|
print("lcm 1..10:", total)
|