Skip to main content
3 of 3
deleted 29 characters in body
138 Aspen
  • 6.6k
  • 1
  • 4
  • 13

Maxima, 93 bytes

A port of @MarcMush's Julia 1.0 answer in Maxima.

93 bytes, it can be golfed much more.


Golfed version. Try it online!

b(n):=block([o],o:fpprec,fpprec:n,r:if n<2 then bfloat(n)else bfloat(cos(b(n-1))),fpprec:o,r)

Ungolfed version. Try it online!

/* Define the recursive function with dynamic precision */
b(n) := block(
    [old_prec],
    /* Save the old precision */
    old_prec: fpprec,
    /* Set the precision relative to n */
    fpprec: n,
    /* Perform the calculation with the new precision */
    result: if n < 2 then bfloat(n) else bfloat(cos(b(n-1))),
    /* Restore the old precision */
    fpprec: old_prec,
    /* Return the result */
    result
);

/* Print the results from 1 to 1000 */
for i:1 thru 1000 do (
    print(b(i))
);
138 Aspen
  • 6.6k
  • 1
  • 4
  • 13