RosettaCodeData/Task/Least-common-multiple/Jq/least-common-multiple.jq
2017-09-25 22:28:19 +02:00

6 lines
230 B
Text

# Define the helper function to take advantage of jq's tail-recursion optimization
def lcm(m; n):
def _lcm:
# state is [m, n, i]
if (.[2] % .[1]) == 0 then .[2] else (.[0:2] + [.[2] + m]) | _lcm end;
[m, n, m] | _lcm;