RosettaCodeData/Task/Stern-Brocot-sequence/Jq/stern-brocot-sequence-1.jq
2017-09-25 22:28:19 +02:00

12 lines
337 B
Text

def until(cond; update):
def _until:
if cond then . else (update | _until) end;
try _until catch if .== "break" then empty else . end ;
def gcd(a; b):
# subfunction expects [a,b] as input
# i.e. a ~ .[0] and b ~ .[1]
def rgcd: if .[1] == 0 then .[0]
else [.[1], .[0] % .[1]] | rgcd
end;
[a,b] | rgcd ;