Files
pplus-library/mojo/stress/gcd-lcm.mojo
T
alexm 568474d52f
Test (in pplus-core) / in-core (push) Failing after 28m44s
Initial commit
2026-11-12 22:23:48 -05:00

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)