RosettaCodeData/Task/Pathological-floating-point-problems/Jq/pathological-floating-point-problems-1.jq
2023-07-01 13:44:08 -04:00

17 lines
536 B
Text

# Input: the value at which to compute v
def v:
# Input: cache
# Output: updated cache
def v_(n):
(n|tostring) as $s
| . as $cache
| if ($cache | has($s)) then .
else if n == 1 then $cache["1"] = 2
elif n == 2 then $cache["2"] = -4
else ($cache | v_(n-1) | v_(n - 2)) as $new
| $new[(n-1)|tostring] as $x
| $new[(n-2)|tostring] as $y
| $new + {($s): ((111 - (1130 / $x) + (3000 / ($x * $y)))) }
end
end;
. as $m | {} | v_($m) | .[($m|tostring)] ;