(これはかなり古典的かもしれませんが、これは私の最初の投稿ですので、まだファンシーなことはできません)
Goodsteinシーケンスは、入力番号に対して次のように定義されています。
開始番号 n を選択し、 b =
2にして繰り返します:
- write n in heriditary base
b notation - substitute all the (b)s to
(b+1)s in n and substract
1 - output the new decimal evaluation of
n - increment b
遺伝的基底表記法は、基数が出現するより大きな数である数の分解です。例:
-
83
in HB3:3^(3+1)+2
-
226
in HB2:
2^(2^(2+1))+2^(2+1)+2
Goodsteinのシーケンスは、常に0になります。しかし、最初は非常に速くなっています完全なシーケンスを出力するように要求されません。
タスク:
任意の合理的なフォーマットの入力番号が与えられた場合、あなたの仕事は少なくとも10 ^
25または0に達するまでこの数字のGoodsteinシーケンスを出力することです
例:
Input: 3
Output: 3, 3, 3, 2, 1, 0
Input: 13
Output: 13, 108, 1279, 16092, 280711, 5765998, 134219479, 3486786855, 100000003325, 3138428381103, 106993205384715, 3937376385706415, 155568095557821073, 6568408355712901455, 295147905179352838943, 14063084452067725006646, 708235345355337676376131, 37589973457545958193377292
Input: 38
Output: 38, 22876792454990
詳細:
- Input number can be an array, a string, an integer, as long as
it is in decimal base - Output follows the same rule
- Separation of the terms in the output can be spaces, new-lines,
or any reasonable separation - As soon as the sequence becomes larger than 10^25, your program
may exit normally, throw an error/exception, or continue (no
restriction) - This is code-golf,
so the shortest answer (in bytes) wins - Of course,
standard loopholes are forbidden - Python ungolfed working example here
ベストアンサー
Pyth, 28 26 bytes
.V2JbL&bs.e*^hJykb_jbJ=ty
末尾改行は重要です。
Try it
online! (This link includes an extra Q
not needed
by the current version of Pyth.)
使い方
.V2JbL&bs.e*^hJykb_jbJ=ty
.V2 for b in [2, 3, 4, ...]:
Jb assign J = b
L def y(b):
&b b and
jbJ convert b to base J
_ reverse
.e enumerated map for values b and indices k:
hJ J + 1
^ yk to the power y(k)
* b times b
(newline) print Q (autoinitialized to the input)
y y(Q)
t subtract 1
= assign back to Q
グローバル変数 J
への変更をメモに記録しないようにするには、各ループの反復で
y
を再定義することが重要です。