別のシーケンス、別の課題。*
定義
最初の p
はこの順番であり、 p
のすべての数字
d
に A
d
を d
の
d
のコピーに置き換え、結果の整数は依然として素数です。ゼロは許されません。
たとえば、 11
はこの順番になります(偶然にも最初の数字です)。 3331
も素数であるため、シーケンスの次は 31
です。 55555333
も素数であるため 53
などとなります。
チャレンジ
入力 n
が指定されている場合は、このシーケンスの n
項目の
A(n)
を返します。
例
ここにあなたを始めさせる最初の20の言葉があります。これはOEISの A057628 です。
11, 31, 53, 131, 149, 223, 283, 311, 313, 331, 397, 463, 641, 691, 937, 941, 1439, 1511, 1741, 1871
ゼロインデックスを使用している場合、これは A(0)= 11
、 A(1)=
などを意味します。
31
ルール
- You can choose zero- or one-based indexing; please specify in
your answer which. - Instead of returning just the
n
th element, you can
instead choose to return the firstn
terms. - You can assume that the input/output will not be larger than
your language’s native integer format; however, the repeated-digit
prime may be larger than your language’s native format, so
that will need to be accounted for. - For example,
1871
, the last number of the 例, has a
corresponding prime of18888888877777771
, which is
quite a bit larger than standard INT32. - Either a full program or a function are acceptable. If a
function, you can return the output rather than printing it. - Output can be to the console, returned from a function,
displayed in an alert popup, etc. -
Standard
loopholes are forbidden. - This is code-golf
so all usual golfing ルール apply, and the shortest code (in bytes)
wins.
*公平になるためには、シーケンスの最初のいくつかの項をいくつかの数字で試してみた後、残りのシーケンスを得るためにOEISに行きました。
ベストアンサー
Husk, 15 bytes
!fo§&öεpd´ṘΠdİp
! Index into
İp the list of primes
f for which:
d the digits of p
o§& satisfy both:
öεpd´Ṙ repeated "themselves" times, they form a prime.
Π they are all nonzero.
Erik the Outgolferは1バイトを保存しました。
εp
の代わりにṗ
を使うと、別のバイトを節約できます。