RosettaCodeData/Task/Pathological-floating-point-problems/Jq/pathological-floating-point-problems-2.jq
2025-02-27 18:35:13 -05:00

11 lines
317 B
Text

# Given the balance in the prior year, compute the new balance in year n.
# Input: { e: m, c: n } representing m*e + n
def new_balance(n):
if n == 0 then {e: 1, c: -1}
else {e: (.e * n), c: (.c * n - 1) }
end;
def balance(n):
def e: 1|exp;
reduce range(0;n) as $i ({}; new_balance($i) )
| (.e * e) + .c;