Goodstein Sequence: Difference between revisions
→{{header|Wren}}: Updated in line with Julia example of which it is a translation.
m (To avoid needing big integer types the Goodstein(n)(n) task has to have n < 11.) |
(→{{header|Wren}}: Updated in line with Julia example of which it is a translation.) |
||
Line 219:
=={{header|Wren}}==
{{trans|Julia}}
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="wren">import "./
import "./fmt" for Fmt
// Given non-negative integer n and base b, return hereditary representation
▲// return tuples (j, k) so sum of all (j * b^(evaluate(k)) = n.
var decompose // recursive
decompose = Fn.new { |n,
var decomp = []
while (n != 0) {
var t =
if (r
e =
}
return decomp
}
// Evaluate hereditary representation d under base b.
var evaluate // recursive
evaluate = Fn.new { |
if (
var
▲ var sum = (p is Num) ? 0 : BigInt.zero
for (a in p) sum = sum + evaluate.call(a, bas)▼
return sum▼
}
}
// Return a vector of up to limitlength values of the Goodstein sequence for n.
var goodstein = Fn.new { |n, limitLength|
var
var
while (
}
return
}
// Get the nth term of the Goodstein(n) sequence counting from 0
var a266201 = Fn.new { |n| goodstein.call
System.print("Goodstein(n) sequence (first 10) for values of n in [0, 7]:")
for (i in
System.print("\nThe
for (i in
Fmt.print("Term $
}</syntaxhighlight>
Line 311 ⟶ 291:
Goodstein of 7: [7, 30, 259, 3127, 46657, 823543, 16777215, 37665879, 77777775, 150051213]
The
Term 0 of Goodstein( 0): 0
Term 1 of Goodstein( 1): 0
|