Goodstein Sequence: Difference between revisions

Content deleted Content added
Petelomax (talk | contribs)
Aerobar (talk | contribs)
 
(2 intermediate revisions by 2 users not shown)
Line 431:
Term 15 of Goodstein(15): 14063084452070776884879
Term 16 of Goodstein(16): 2771517379996516970665566613559367879596937714713289695169887161862950129194382447127464877388711781205972046374648603545513430106433206876557475731408608398953667881600740852227698037876781766310900319669456854530159244376159780346700931210394158247781113134808720678004134212529413831368888355854503034587880113970541681685966414888841800498150131839091463034162026108960280455620621355407543489960326268155088833218122810217973039385643494213235664908254695964740257569988152978579630435471016976693529875691083071137361386386918409765002837648351746984484967203877495399596876291343126699827442908994036031608979805166915596436929638418152127561722561465793969723556331679336828840983098559789555364076924597258115780567651772009250336359472037679350612341393780002377587368649157608579801815531133644879180066181854487069796160774056572568941004114162614925
</pre>
 
=={{header|Raku}}==
{{trans|Phix}}
<syntaxhighlight lang="raku" line># 20240219 Raku programming solution
 
sub bump($n is copy, $b) {
loop ( my ($res, $i) = 0, 0; $n.Bool or return $res; $i++ ) {
if my $d = ($n % $b).Int { $res += $d * (($b+1) ** bump($i,$b)).round }
$n = ($n / $b).floor
}
}
 
sub goodstein($n, $maxterms = 10) {
my @res = $n;
while @res.elems < $maxterms && @res[*-1] != 0 {
@res.push(bump(@res[*-1], (@res.elems + 1)) - 1)
}
return @res
}
 
say "Goodstein(n) sequence (first 10) for values of n from 0 through 7:";
for 0..7 -> $i { say "Goodstein of $i: ", goodstein($i) }
 
say();
my $max = 16;
say "The Nth term of Goodstein(N) sequence counting from 0, for values of N from 0 through $max :";
for 0..$max -> $i { say "Term $i of Goodstein($i): {goodstein($i, $i+1)[*-1]}" }</syntaxhighlight>
 
You may [https://ato.pxeger.com/run?1=XZK_btswEMaBjnqKr4YaUJas2ktTWElRdCm6eMpWdPAfyiIqkQ5FtjUMPUmXDM0LZczT9I5SXTkaCIj33Xe_O97vP3b93T88PHpXzt4_v3pq_QYb3xxErKFabM3hmCHeJDhFAGpjDhBojhCxlS1FVIJbzDPMC8Q6_2RMDWNhpfNWgzV0r9IUgwF9quT8eEd5XOQNu-dftMMp6JHecnAKIeJNukgwnQ5AKiNlklvj9Q7d4EYOvc_b4FMSoeVQF3VRxM3sjdm1TipNIuJt1r-ctE1LWYv5AEU4H7kyFdYFX_ysVC3DXS5rSeKbUeLVVYh8nc4W3_Camj93FhIOvq1EAD6rMoiRV4pFkmBGZ89JxzAuFgXs9RGTz2dunaCV917qrYQolW1dQC9pzj_WtSdwU0KjtKYhGFfRgPYVrpeTImLNPM-vMftAz0ATvrTmxFgtMcnGY6In7SFEUkT8VNQ6j-td0ZPdVRIrV4HHwQ7_SVcj0i09k1N6P3BlL3hXL3lDlRFz-L_AvuN69HtRkmiXOI3peSlpb8Lkuwm6frWHDf-36X8B Attempt This Online!]
 
=={{header|RPL}}==
We use here the capability of RPL to evaluate the hereditary representation directly.
{{works with|RPL|HP-49C}}
« -1 → b p
« 0 SWAP
'''WHILE''' DUP '''REPEAT'''
b IDIV2 'p' INCR
'''IF''' OVER '''THEN'''
'''IF''' DUP b ≥ THEN b <span style="color:blue">→HRDT</span> '''END'''
'B' SWAP ^ * ROT + SWAP
'''ELSE''' DROP2 '''END'''
'''END''' DROP
» » '<span style="color:blue">→HRDT</span>' STO <span style="color:grey">''@ ( n base → 'hereditary representation' )''</span>
« → n max
« { 0 }
'''IF''' n '''THEN'''
n ADD n
3 max '''FOR''' m
m 1 - <span style="color:blue">→HRDT</span> m 'B' STO EVAL 1 - <span style="color:grey">''@ compute G(n)(m)'' </span>
SWAP OVER + SWAP
'''IF''' DUP NOT '''THEN''' max 'm' STO '''END'''
'''NEXT'''
DROP 'B' PURGE
'''END'''
» » '<span style="color:blue">GOODSTEIN</span>' STO <span style="color:grey">''@ ( n max → { G(n)(1) .. G(n)(max) )''</span>
« « j 11 <span style="color:blue">GOODSTEIN</span> » 'j' 0 7 1 SEQ
« j DUP 2 + <span style="color:blue">GOODSTEIN</span> » 'j' 0 16 1 SEQ
1 « REVLIST HEAD » DOLIST
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
2: { { 0 } { 1 0 } { 2 2 1 0 } { 3 3 3 2 1 0 } { 4 26 41 60 83 109 139 173 211 253 } { 5 27 255 467 775 1197 1751 2454 3325 4382 } { 6 29 257 3125 46655 98039 187243 332147 555551 885775 } { 7 30 259 3127 46657 823543 16777215 37665879 77777775 150051213 } }
1: { 0 0 1 2 83 1197 187243 37665879 20000000211 855935016215 44580503598539 2120126221988686 155568095557812625 6568408355712901455 295147905179358418247 14063084452070776884879 2771517379996516970665566613559367879596937714713289695169887161862950129194382447127464877388711781205972046374648603545513430106433206876557475731408608398953667881600740852227698037876781766310900319669456854530159244376159780346700931210394158247781113134808720678004134212529413831368888355854503034587880113970541681685966414888841800498150131839091463034162026108960280455620621355407543489960326268155088833218122810217973039385643494213235664908254695964740257569988152978579630435471016976693529875691083071137361386386918409765002837648351746984484967203877495399596876291343126699827442908994036031608979805166915596436929638418152127561722561465793969723556331679336828840983098559789555364076924597258115780567651772009250336359472037679350612341393780002377587368649157608579801815531133644879180066181854487069796160774056572568941004114162614925 }
</pre>