最近は複合体になるのがますます難しくなっています


14

空でないリスト所与Lより大きい整数の1、我々は定義D(L)最小の正の整数であり、その結果として、N + D(L)である複合それぞれについてNLを

シーケンスa nを次のように定義します。

  • 0 = 2
  • a i + 1は、d(a 0、...、a i、a i + 1)> d(a 0、...、a i)となるようなa iより大きい最小の整数です

あなたのタスク

次のいずれかです。

  • 整数Nを取り、シーケンスのN番目の項(0インデックスまたは1インデックス)を返します
  • 整数Nを取り、シーケンスの最初のN項を返します
  • 何も入力せずに、シーケンスを永久に印刷します

これはなので、バイト単位の最短回答が勝ちです!

Nが大きくなるにつれてコードが遅くなっても問題ありませんが、少なくとも2分以内に20個の最初の用語を見つけるはずです。

最初の用語

  • a 0 = 2およびd(2)= 2(2 + 2が合成されるように2を追加する必要があります)
  • d(2、3)= 6であるため、a 1 = 3 2 + 6と3 + 6が合成されるように6を追加する必要があります)
  • d(2、3、5)= 7であるためa 2 = 5 (2 + 7、3 + 7、および5 + 7がすべて複合になるように7を追加する必要があります)、d(2、3、4)はまだです6に等しい

以下は、シーケンスの最初の100の用語です(投稿時のOEISでは不明)。

  2,   3,   5,   6,  10,  15,  17,  19,  22,  24,
 30,  34,  35,  39,  41,  47,  51,  54,  56,  57,
 70,  79,  80,  82,  92,  98, 100, 103, 106, 111,
113, 116, 135, 151, 158, 162, 165, 179, 183, 186,
191, 192, 200, 210, 217, 223, 226, 228, 235, 240,
243, 260, 266, 274, 277, 284, 285, 289, 298, 307,
309, 317, 318, 329, 341, 349, 356, 361, 374, 377,
378, 382, 386, 394, 397, 405, 409, 414, 417, 425,
443, 454, 473, 492, 494, 502, 512, 514, 519, 527,
528, 560, 572, 577, 579, 598, 605, 621, 632, 642

回答:


1

Pyth、24バイト

Pu+GfP_+Tf!fP_+ZYG)eGQ]2

デモンストレーション

基本的に、から始めて[2]、要素を1つずつ追加し、交互に検索してdから要素を追加します。nシーケンスの最初の要素を出力します。

繰り返し適用ループ内の最初の整数フィルター内の最初の整数フィルター内にフィルターが含まれています。

説明:

Pu+GfP_+Tf!fP_+ZYG)eGQ]2
 u                   Q]2    Starting with `[2]`, do the following as many times
                            as the input
         f        )         Starting from 1 and counting upward, find d where
          !f     G          None of the elements in the current list
            P_+ZY           plus d give a prime.
    f              eG       Starting from the end of the current list and counting
                            upward, find the first number which
     P_+T                   plus d gives a prime.
  +G                        Append the new number to the current list
P                           Trim the last element of the list

2つの「プライムの追加と確認」呼び出しの間に明らかに繰り返される努力がありますが、どのようにそれを排除するのかわかりません。



1

網膜、74バイト

K`__;
"$+"{/;(?!(__+)\1+\b)/+`;
;_
.+$
$&¶$&
)/;(__+)\1+$/+`.+$
_$&_
%`\G_

オンラインでお試しください!0インデックス付き。説明:

K`__;

iワークエリアの各行には、2つの単項値が含まれますaᵢ;d+aᵢa₀=2and d+a₀=0から始めます(ゴルファーだからです)。

"$+"{
...
)

ループN時間を繰り返します。

/;(?!(__+)\1+\b)/+`

少なくとも1つの非合成番号がある間に繰り返します。

;
;_

インクリメントd

.+$
$&¶$&

最後の行を複製aᵢ₋₁し、にコピーしaᵢます。

/;(__+)\1+$/+`

d+aᵢ合成中に繰り返します。

.+$
_$&_

インクリメントaᵢ

%`\G_

結果を10進数に変換します。


1

クリーン138の 130 128バイト

import StdEnv
$l=until(\v=all(\n=any((<)1o gcd(n+v))[2..n+v-1])l)inc 1

map hd(iterate(\l=hd[[n:l]\\n<-[hd l..]| $[n:l]> $l])[2])

オンラインでお試しください!

拡張:

$l=until(\v=all(\n=any((<)1o gcd(n+v))[2..n+v-1])l)inc 1
$l=until(                                         )inc 1  // first value from 1 upwards where _
         \v=all(                                )l        // _ is true for everything in l
                \n=any(              )[2..n+v-1]          // any of [2,3..n+v-1] match _
                             gcd(n+v)                     // the gcd of (n+v) and ^
                           o                              // (composed) ^ is _
                       (<)1                               // greater than 1

map hd(iterate(\l=hd[[n:l]\\n<-[hd l..]| $[n:l]> $l])[2]) 
map hd(                                                 ) // the first element of each list in _
       iterate(                                     )[2]  // infinite repeated application of _ to [2]
               \l=hd[                              ]      // the head of _
                     [n:l]                                // n prepended to l
                          \\n<-[hd l..]                   // for every integer n greater than the head of l
                                       | $[n:l]> $l       // where d(n0..ni+1) > d(n0..ni)

1

ジュリア0.6145の 130バイト

~L=(x=1;while any(map(m->all(m%i>0 for i=2:m-1),L+x));x+=1;end;x)
!n=n<1?[2]:(P=!(n-1);t=P[end]+1;while ~[P;t]<=~P;t+=1;end;[P;t])

オンラインでお試しください!

(私の新しい改善されたゴルフスキルを使用して15バイト-演算子のオーバーロード、条件付きを3項に置き換え、returnキーワードを削除します。)

展開

function primecheck(m)
    all(m%i>0 for i2:m-1)
end

function d(L)
    x = 1
    while any(map(primecheck, L+x))
        x += 1
    end
    return x
end

function a(n)
    n > 0 || return [2]
    Prev = a(n-1)
    term = Prev[end] + 1
    while d([Prev;term])  d(Prev)
        term += 1
    end
    return [Prev;term]
end
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.