10進表現のすべての複数桁の部分文字列も素数であるすべての正数を印刷/出力します。


15

仕事

あなたの仕事は、すべての正数を印刷または出力することであり、その場合、その10進表現の複数桁の部分文字列もすべて素数になります。数値に少なくとも2桁ある場合、これは数値自体も素数である必要があることを意味します。

  • 6197内のすべての多桁のストリングのためのシーケンスである6197:すなわち、素数である6119976191976197(それ自体)。
  • 6は素数ではないが、の複数桁の部分文字列ではない6197ため、シーケンス内にあることに注意してください。66197
  • 8内のすべての複数桁の部分文字列8は素数であるため、シーケンス内にもあります。には複数桁の部分文字列はない8ため、これは空虚な真実の場合です。

スペック

  • 標準の抜け穴が適用されますが、出力をハードコーディングしたり、プログラムに出力に関連する情報を保存したりすることはできません。
  • 出力の番号は任意の順序で指定できます。
  • 出力内の数字は重複すること許可されています。
  • 出力の代わりに印刷することを選択した場合、任意の区切り文字を使用できます。
  • 出力の代わりに印刷することを選択した場合、出力の前置または後置、あるいはその両方が許可されます。
  • 区切り文字、接頭辞、および接尾辞に数字を含めることできません(U + 0030〜U + 0039)。

全リスト(58アイテム)

1
2
3
4
5
6
7
8
9
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
113
131
137
173
179
197
311
313
317
373
379
419
431
479
613
617
619
673
719
797
971
1373
3137
3797
6131
6173
6197
9719

参照


いつものように、私が明確にすべきことはコメントで自由に述べてください。


2
Brachylogwikiリンク)(TIOリンク)(チャットルーム)でこのチャレンジに対する最小の回答を送信した@Fatalizeを除くすべての人に+300バウンティを与えます
リーキー修道女

2
貧弱な@Fatalize。それはあなたが言語を作成するために得るものです
ルイスメンドー

3
私は50バイトの答えを持っています:(
6

1
プログラムを終了する必要がありますか?
17

2
@LeakyNun誰かがその報奨金を得るように見える!
ヨルダン

回答:



7

05AB1E15 13バイト

コード:

4°GN§ŒD9›ÏpP–

説明:

  G            # For N in range 1,
4°             #   10000
   N           # Push N
    §          # Convert that to string
     Π        # Get all substrings
      D9›Ï     # Keep all substrings that are greater than 9
          p    # Check each of them if they are prime
           P   # Product
            –  # If 1, print N

CP-1252エンコードを使用します。オンラインでお試しください!(数秒かかる場合があります)。


5

Brachylog18 17 15 16 15バイト

ℕ₁<l4&≜sᶠ{Ḋ|ṗ}ᵐ

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

Fatalizeとの議論の後の-1バイトは、私l<周りを交換した場合に何が起こるかを見るように私を刺激しました。

この述部は、出力変数が制約されない限り、入力変数を介して出力を生成します。重複が許可されているため、各数は、2の素数である桁数の累乗に等しい多重度で生成されます。

ℕ₁                 The input variable is a natural number
  <                less than
   l4              some number with length 4 (maximized as 9999).
     &≜            Assign a number to the input, and assert that
       sᶠ          every substring of it
         { | }ᵐ    is either
            ṗ      a prime number
          Ḋ        or a single digit.

古いバージョン:

{≜ℕsᶠ{Ḋ!|ṗ}ᵐ&}ᶠ⁵⁹b
7^₅⟦₁{sᶠ{Ḋ|ṗ}ᵐ&}ˢ
8ḟ⟦₁{sᶠ{Ḋ|ṗ}ᵐ&}ˢ
∧8ḟ>?ℕ₁≜sᶠ{Ḋ|ṗ}ᵐ

40320までのすべてをチェックすることを正確に速くないので、これは、16バイトですが、テストされていない:8ḟ⟦₁{sᶠ{Ḋ|ṗ}ᵐ&}ˢ
関係のない文字列の

それはしかし、上部の代わりに10000の上限与えられた罰金を終了:tio.run/##SypKTM6ozMlPN/r/39AACB7NX/...
無関係な文字列の

4

Brachylog、18バイト

別のBrachylogソリューション。Erik The OutgolferのBrachylogソリューションより短くすることはできませんでした。まったく同じ長さですが、反対方向から世代に近づきます。

{≜ℕ{sℕ₁₀}ᶠṗᵐ&}ᶠ⁵⁹b

Unrelated Stringがこれを多くのキャラクターに打ち負かしたようです。

説明:

{≜ℕ                Brute force all nonnegative integers to find any that match the constraints
   {s               Create a predicate that finds all subsequences of digits of said integer
     ℕ₁₀            Constrains those subsequences to be >= 10
        }ᶠ          Finds all possible values of that predicate: all multi-digit subsequences
          ṗᵐ        Apply a primality constraint to all of those subsequences
            &       Make the predicate output the input integer rather than a prime subsequence
             }ᶠ⁵⁹   Find the first 59 results (all of the puzzle's solutions, and zero)
                 b  Remove the first element of the list, i.e. 0

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


3

ゼリー、17 バイト

DẆṖÐfḌÆP€Ạ
³²RÇÐf

私の最初のゼリーの答え!@Leaky Nunのおかげで3バイト節約できました

オンラインで試す

説明:

DẆṖÐfḌÆP€Ạ      The helper link, which checks if a given number satisfy the conditions.
DẆ              Convert the argument to a list of its digits and get all its substrings.
  ṖÐf           Remove all lists of length 1.
     ḌÆP€Ạ      Convert back each element to an integer and check if all of them are prime.

³²RÇÐf          Main link.
³²              Create a 100 and square it, which gives 10000.
  R             Create a list from 1 to it.
   ÇÐf          Filter out all the elements where the helper link gives false.

最初のゼリーの回答おめでとうございます!
リーキー修道女

2
RÇÐfに置き換えることができますÇ€TṖÐfḌÆP€に置き換えることができますḌḟDÆP
デニス

3

Java 8、182バイト

v->{for(int n=0;++n<1e4;)if(P(n)>0)System.out.println(n);}int p(int n){for(int i=2;i<n;n=n%i++<1?0:n);return n;}int P(int n){return n>99?p(n)*p(n%100)*p(n%1000)*P(n/10):n<10?n:p(n);}

port of gastropnerのC(gcc)回答なので、必ず彼の回答に賛成票を投じてください

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

説明:

// Loop in range [1,10000), and print any primes corresponding to the challenge description
v->{for(int n=0;++n<1e4;)if(P(n)>0)System.out.println(n);}

// Checks if the given integer is a prime (return unchanged input if prime, 0 if not)
int p(int n){for(int i=2;i<n;n=n%i++<1?0:n);return n;}

// Recursive method that checks if every part of length 2+ is a prime, or is below 10
int P(int n){return n>99?p(n)*p(n%100)*p(n%1000)*P(n/10):n<10?n:p(n);}

2

PowerShell v2 +、107 104バイト

1..10+(11..1e4|?{($x=11..($i=$_)|?{"$i"-match$_}).count-eq($x|?{'1'*$_-match'^(?!(..+)\1+$)..'}).count})

警告:ちょっと遅い

ループ11まで1e4(すなわち、10000使用番号OUT)と引っ張るWhere-Objectセレクタ(|?{...})。句は2つのコンポーネントです。最初のループ11は現在の番号までループし、現在の番号Where-Objectのサブストリングを形成する番号を引き出すために使用します(-match正規表現演算子を使用)。これらの部分文字列をに保存し$xます。第二の部分は、をループ$xと用途Where-Object使用して、すべての素数を引き出すためにプライム正規表現。次に.count、両方を使用し、実際にそれらが-equalであるかどうかをチェックします。例えば、971必要があります$x = (71,97,971)ので、これらの各々は素数であり3-eq3であり$TRUE、したがって、971選択されます。

その結果は、範囲で配列連結されます1..10。結果の配列はパイプラインに残され、出力は暗黙的に行われ、デフォルトでは要素間に改行が付きます。



2

C(GCC) 144の 142 140 136 134 132バイト

-2 Kevin Cruijssenに感謝します。-2 ceilingcatのおかげ

...そしてそれに触発されて、そのforループからさらに2バイトを取得できます。

また、ケビン・クルーイッセンの別の-4 に対する答えから、かなり良いプライムチェッカーに恥知らずにニックを入れました。

p(n,i){for(i=2;i<n;)n*=n%i++||n<10;i=n;}P(n){n=p(n)*(n<99||p(n%100)*p(n%1000)*P(n/10));}f(n){for(n=1e4;--n;)P(n)&&printf("%d\n",n);}

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


||n<10ことができる|n<10for(n=1;n<1e4;n++)することができるfor(n=0;++n<1e4;)ため-2バイト。
ケビンクルーッセン

@KevinCruijssen乾杯!
ガストプナー

2

Malbolge Unshackled(20トリットローテーションバリアント)、2,5254e7バイトまたは1,9809e7バイト

この回答のサイズは投稿可能な最大プログラムサイズ(eh)を超えているため、コードはGitHubリポジトリにあります(注:CTRL + AおよびCTRL + Cを使用してコードをコピーしないでください。 .. ")。

これを実行するには?

素朴なHaskellインタープリターはこれを実行するのに年齢を重ねるので、これは難しい部分かもしれません。TIOにはまともなMalbogle Unshackledインタプリタがありますが、残念ながら私はそれを使用できません(制限)。

私が見つけることができる最高のものは、非常によく機能する固定された20トリット回転幅バリアントです。

インタープリターを少し速くするために、Matthias LutterのMalbolge Unshackledインタープリターからすべてのチェックを削除しました。

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char* translation = "5z]&gqtyfr$(we4{WP)H-Zn,[%\\3dL+Q;>U!pJS72Fh"
        "OA1CB6v^=I_0/8|jsb9m<.TVac`uY*MK'X~xDl}REokN:#?G\"i@";

typedef struct Word {
    unsigned int area;
    unsigned int high;
    unsigned int low;
} Word;

void word2string(Word w, char* s, int min_length) {
    if (!s) return;
    if (min_length < 1) min_length = 1;
    if (min_length > 20) min_length = 20;
    s[0] = (w.area%3) + '0';
    s[1] = 't';
    char tmp[20];
    int i;
    for (i=0;i<10;i++) {
        tmp[19-i] = (w.low % 3) + '0';
        w.low /= 3;
    }
    for (i=0;i<10;i++) {
        tmp[9-i] = (w.high % 3) + '0';
        w.high /= 3;
    }
    i = 0;
    while (tmp[i] == s[0] && i < 20 - min_length) i++;
    int j = 2;
    while (i < 20) {
        s[j] = tmp[i];
        i++;
        j++;
    }
    s[j] = 0;
}

unsigned int crazy_low(unsigned int a, unsigned int d){
    unsigned int crz[] = {1,0,0,1,0,2,2,2,1};
    int position = 0;
    unsigned int output = 0;
    while (position < 10){
        unsigned int i = a%3;
        unsigned int j = d%3;
        unsigned int out = crz[i+3*j];
        unsigned int multiple = 1;
        int k;
        for (k=0;k<position;k++)
            multiple *= 3;
        output += multiple*out;
        a /= 3;
        d /= 3;
        position++;
    }
    return output;
}

Word zero() {
    Word result = {0, 0, 0};
    return result;
}

Word increment(Word d) {
    d.low++;
    if (d.low >= 59049) {
        d.low = 0;
        d.high++;
        if (d.high >= 59049) {
            fprintf(stderr,"error: overflow\n");
            exit(1);
        }
    }
    return d;
}

Word decrement(Word d) {
    if (d.low == 0) {
        d.low = 59048;
        d.high--;
    }else{
        d.low--;
    }
    return d;
}

Word crazy(Word a, Word d){
    Word output;
    unsigned int crz[] = {1,0,0,1,0,2,2,2,1};
    output.area = crz[a.area+3*d.area];
    output.high = crazy_low(a.high, d.high);
    output.low = crazy_low(a.low, d.low);
    return output;
}

Word rotate_r(Word d){
    unsigned int carry_h = d.high%3;
    unsigned int carry_l = d.low%3;
    d.high = 19683 * carry_l + d.high / 3;
    d.low = 19683 * carry_h + d.low / 3;
    return d;
}

// last_initialized: if set, use to fill newly generated memory with preinitial values...
Word* ptr_to(Word** mem[], Word d, unsigned int last_initialized) {
    if ((mem[d.area])[d.high]) {
        return &(((mem[d.area])[d.high])[d.low]);
    }
    (mem[d.area])[d.high] = (Word*)malloc(59049 * sizeof(Word));
    if (!(mem[d.area])[d.high]) {
        fprintf(stderr,"error: out of memory.\n");
        exit(1);
    }
    if (last_initialized) {
        Word repitition[6];
        repitition[(last_initialized-1) % 6] =
                ((mem[0])[(last_initialized-1) / 59049])
                    [(last_initialized-1) % 59049];
        repitition[(last_initialized) % 6] =
                ((mem[0])[last_initialized / 59049])
                    [last_initialized % 59049];
        unsigned int i;
        for (i=0;i<6;i++) {
            repitition[(last_initialized+1+i) % 6] =
                    crazy(repitition[(last_initialized+i) % 6],
                        repitition[(last_initialized-1+i) % 6]);
        }
        unsigned int offset = (59049*d.high) % 6;
        i = 0;
        while (1){
            ((mem[d.area])[d.high])[i] = repitition[(i+offset)%6];
            if (i == 59048) {
                break;
            }
            i++;
        }
    }
    return &(((mem[d.area])[d.high])[d.low]);
}

unsigned int get_instruction(Word** mem[], Word c,
        unsigned int last_initialized,
        int ignore_invalid) {
    Word* instr = ptr_to(mem, c, last_initialized);
    unsigned int instruction = instr->low;
    instruction = (instruction+c.low + 59049 * c.high
            + (c.area==1?52:(c.area==2?10:0)))%94;
    return instruction;
}

int main(int argc, char* argv[]) {
    Word** memory[3];
    int i,j;
    for (i=0; i<3; i++) {
        memory[i] = (Word**)malloc(59049 * sizeof(Word*));
        if (!memory) {
            fprintf(stderr,"not enough memory.\n");
            return 1;
        }
        for (j=0; j<59049; j++) {
            (memory[i])[j] = 0;
        }
    }
    Word a, c, d;
    unsigned int result;
    FILE* file;
    if (argc < 2) {
        // read program code from STDIN
        file = stdin;
    }else{
        file = fopen(argv[1],"rb");
    }
    if (file == NULL) {
        fprintf(stderr, "File not found: %s\n",argv[1]);
        return 1;
    }
    a = zero();
    c = zero();
    d = zero();
    result = 0;
    while (!feof(file)){
        unsigned int instr;
        Word* cell = ptr_to(memory, d, 0);
        (*cell) = zero();
        result = fread(&cell->low,1,1,file);
        if (result > 1)
            return 1;
        if (result == 0 || cell->low == 0x1a || cell->low == 0x04)
            break;
        instr = (cell->low + d.low + 59049*d.high)%94;
        if (cell->low == ' ' || cell->low == '\t' || cell->low == '\r'
                || cell->low == '\n');
        else if (cell->low >= 33 && cell->low < 127 &&
                (instr == 4 || instr == 5 || instr == 23 || instr == 39
                    || instr == 40 || instr == 62 || instr == 68
                    || instr == 81)) {
            d = increment(d);
        }
    }
    if (file != stdin) {
        fclose(file);
    }
    unsigned int last_initialized = 0;
    while (1){
        *ptr_to(memory, d, 0) = crazy(*ptr_to(memory, decrement(d), 0),
                *ptr_to(memory, decrement(decrement(d)), 0));
        last_initialized = d.low + 59049*d.high;
        if (d.low == 59048) {
            break;
        }
        d = increment(d);
    }
    d = zero();

    unsigned int step = 0;
    while (1) {
        unsigned int instruction = get_instruction(memory, c,
                last_initialized, 0);
        step++;
        switch (instruction){
            case 4:
                c = *ptr_to(memory,d,last_initialized);
                break;
            case 5:
                if (!a.area) {
                    printf("%c",(char)(a.low + 59049*a.high));
                }else if (a.area == 2 && a.low == 59047
                        && a.high == 59048) {
                    printf("\n");
                }
                break;
            case 23:
                a = zero();
                a.low = getchar();
                if (a.low == EOF) {
                    a.low = 59048;
                    a.high = 59048;
                    a.area = 2;
                }else if (a.low == '\n'){
                    a.low = 59047;
                    a.high = 59048;
                    a.area = 2;
                }
                break;
            case 39:
                a = (*ptr_to(memory,d,last_initialized)
                        = rotate_r(*ptr_to(memory,d,last_initialized)));
                break;
            case 40:
                d = *ptr_to(memory,d,last_initialized);
                break;
            case 62:
                a = (*ptr_to(memory,d,last_initialized)
                        = crazy(a, *ptr_to(memory,d,last_initialized)));
                break;
            case 81:
                return 0;
            case 68:
            default:
                break;
        }

        Word* mem_c = ptr_to(memory, c, last_initialized);
        mem_c->low = translation[mem_c->low - 33];

        c = increment(c);
        d = increment(d);
    }
    return 0;
}

パフォーマンスノート

アプリケーションは私のマシンで約40分間実行され、シーケンスの16進数を生成しました。約1時間の計算を停止し、0x11で終了しました。

この答えは他の答えとは異なることに注意してください。なぜなら、この答えは実際に数値を計算し、無限に計算するように作成できるからです。

アプリケーションは約7ギガバイトのスピンアップバッファーを割り当てるため、空きRAMをより適切に準備します。

代替バリアント

代替バリアントは約2ギガバイトのメモリを使用しませんが、ASCII文字(0 = ASCII(0x0)、10 =改行など)の形式で出力を生成しますここで利用可能です。ただし、チャレンジの要件により、競合することはありません


コードゴルフは短い答えを与えることです。
アルフェ

2
@Alfe Malbolgeは、(wikipediaリンク)でのプログラミング非常に困難になるように設計された言語です。これが可能でさえあるという事実は非常に印象的です。
ジュゼッペ

4
したがって、実際には、これ短い答えです。基準が変更されただけです。やや。
アルフェ

3
@Alfeいくつかのバイトを削ってみてください!;-)
ジュゼッペ

2

Python 3、118バイト

r=range(9720)
for n in r[1:]:all(all(l%k+9//l for k in r[2:l])for l in(n%10**(i%5)//10**(i//5)for i in r))and print(n)

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

説明

警告:このソリューションには実際の文字列は含まれていません。

r=range(9720)
for n in r[1:]:                                        # For each positive integer up to 9720
 all( ... for l in(n%10**(i%5)//10**(i//5)for i in r)) # Check for all its substrings
  all(l%k ... for k in r[2:l])                         # If it is either prime
   +9//l                                               # Or smaller than 10
and print(n)                                           # Then print

1

Ruby、81 + 8 = 89バイト

+8バイト-rprime

puts (?1..?9*4).select{|m|(r=2..m.size).all?{|i|r.all?{|j|m[i-2,j].to_i.prime?}}}

repl.itで参照してください:https ://repl.it/CniR/2


1

Perl 6の 47の44  43バイト

for 1..9719 {all(m:ex/..+/).Int.is-prime&&.say}
put grep {is-prime +all(m:ex/..+/):},1..9719
put grep {is-prime +all m:ex/..+/:},1..9719

説明:

# print the values space separated, with trailing newline
put

# that match
grep -> $_ {

  # call the method 「.is-prime」 ( that is what 「:」 is for )
  # (autothreaded)
  is-prime

  # convert following to numeric (autothreaded)
  +
  # a junction of
  all(
    # all substrings 2 characters or greater
    $_ ~~ m :exhaustive / . .+ /
  )

  # needed to indicate that 「is-prime」 is a method call
  :

},

# in this Range
1..9719

1

C位、261の 249 247バイト

Leaky Nunのおかげで12バイト節約

()=>{Action<int>w=System.Console.WriteLine;int i=0,n,j,k,p,m,b;for(;++i<10001;){n=(i+"").Length;if(n<2)w(i);else{b=1;for(j=1;++j<=n;)for(k=0;k+j<=n;){p=int.Parse((i+"").Substring(k++,j));if(p%2<1)b=0;for(m=3;m<p;m+=2)if(p%m<1)b=0;}if(b>0)w(i);}}};

これはにコンパイルされますFunc<List<int>>

フォーマットされたバージョンは次のようになります。

() =>
{
    Action<int> w = System.Console.WriteLine;

    int i = 0, n, j, k, p, m, b;

    for (; ++i < 10001;)
    {
        n = (i + "").Length;

        if (n < 2)
            w(i);

        else
        {
            b = 1;
            for (j = 1; ++j <= n; )
                for (k = 0; k + j <= n; )
                {
                    p = int.Parse((i + "").Substring(k++, j));

                    if (p % 2 < 1)
                        b = 0;

                    for (m = 3; m < p; m += 2)
                        if (p % m < 1)
                            b = 0;
                }

            if (b > 0)
                w(i);
        }
    }
};

ただ、リストを使用せずに直接印刷する
漏れ修道女

代わりにfalse、またはtrue、使用0>1して0<1
漏れ尼僧

追加のゴルフのヒントについては、これを参照できます。
リーキー修道女

@LeakyNunヒントをありがとう、私は通常、ちょっとゴルフバージョンを投稿してそこから移動するのが好きです。
TheLethalCoder

1

Swift 4、144バイト

let p={n in !(2..<n).contains{n%$0<1}}
print((1...971).filter{$0<10||p($0)&&($0<100||p($0/10)&&p($0%100))}+[1373,3137,3797,6131,6173,6197,9719])

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

説明

let p={n in !(2..<n).contains{n%$0<1}} // Helper function p, tests if a number is prime
print((1...971).filter{                // Print every number n in the range 1 to 971
 $0<10                                 //  that is less than 10
 ||p($0)&&                             //  or a prime and
 ($0<100                               //   is less than 100 or
  ||p($0/10)&&p($0%100))}              //   n/10 and n%100 are primes
+[1373,3137,3797,6131,6173,6197,9719]) // Print the four digit numbers

1

JavaScript(Node.js)、130バイト

iは無限スタックが想定できる場合i*i<=n&&に除去することが可能i*i>nになるi>=nかもしれない9つのバイトコードを減少させると、再帰的にメイン関数を変換:https://tio.run/##LYpBDoIwEEX33AMyAxVbXUmccgX2xkWDRYeQaSPqyrvXkrj5ef/lze7j1vHJ8bWTcPMpTQRMWjm6XJFs0/DZ@EM/ASunBmCsKtfG9/rIiJ0rIoEoJpNbKXPdx@1jx5akGEiytqdNYp2nNFr / wR @ xHkD2Rn81dpLGIGtYfLuEO0yAmH4(119バイト)

_=>eval(`for(a=[i=1];++i<1e4;)P(i)&&a.push(i)`)||a
p=(n,i=1)=>i*i<=n&&n%++i?p(n,i):n%i
P=n=>n>9?p(n)*p(n%100)*p(n%1e3)*P(n/10|0):n

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


1

Malbolge、1361バイト

シンプルで退屈なバージョン。最高の数字を表示します。

D'`r^"!=[YG3yUCvA-csNqp-nJ$HYFgDC#AbQ,|*)\rwvutm3kSonmlkdihg`&dc\aZ_X|V[ZYXQPt7SRQPOHGkKJIHG@d>=<A:98\}|:981U5.-2+0/.'K%$#G!E}e#z!~}v<]yxwpun4rkj0nmfN+ihaf_^$\a`_XW{>=YXWVONrLKPINGkE-IBAe(>=<;_?>=}|:3W1w543,P0).-&J*)(!E}|B"!~}|{zyr8potml2jongfkjibg`&d]\"`_XW{>=YXWVONr54JIHMFj-,HGF?>b%A@?87[;:981w543,P0).-&J*j(!EfeB"!~}_u;yrqpun4rqpihmlkjihg`&d]\"`_X|\[ZYXQuUNMLQJnH0LKJIBAe(>=<`#"8\<5Y9270T43,Pqp.-&J$)"!~D|#"y~}|u;s9qvotsrk1inglkdihg`&d]\"Z~XWVUZYXQu87SLKo2NGFjDIHGF?>bBA#"8\6;:981Uv.32+*)Mnm%$)('~D|{A!xwv{zyr8vXnsrkjoh.fNdchg`ed]#aC_^WVz=YXQPt7SRQPOHGkK-IHGF?>bBA#"8\6;:981Uv.32+*)Mnm%*#"F&%$#cy?}v<]\xwpun4rqSonmf,diha'eG]#a`_X|V[ZYXWPt76LKoIHGLEiCHGFED=aA:?>7[;:981w/4-,PO)o'&J*j(!E%edz@~}_u;yxqpo5mrqpoh.f,jibgf_%]\[!_XW{[ZYXQu87SLKo2NGFjJIHAF?c=BA@?>=<5Y38765.-Q10)o'&J*j(!E%e{z@~}|{ts9qpotsrk1oQglkd*)gIed]#DZ_^]VzZYRQuONMRKJnNGLEJCgG)(D=aA:?>=<;4X816/43,P0).-&+$H('gf|Bcb~w|u;yxwYutmrqj0nmleMib(fH%cba`_X|VUZYXWPt7SRQPOHGkEDIHG@dDC<;@?8\6|:32V0T43,+O)o'&J*)('&}C{"yxwv<tyr8vun4Ukpoh.fN+c)gIed]#DZ_^]VzTSRWPtTSLQJnH0LKJIBAe(>=BA@987[;:381Uv.32+*)Mnm%$)('~D${"y?}_uzyxqpo5srqSonmf,jihgfeG]#a`_X|V[ZYXWPt76LKo2NGFjJIH*)ED=a;@?>76;4X816/43,P*).',%I)('~Ded"y~}|u;srqvo5mlqpih.fN+cba`&d]\aZ~^]VUZSwWPUTSLpJ2NGLEiCHGFED=a;:?>7<5YX876v43,+O).-,+$H('&feBz!x}v{zsr8punsrk1inglkdihg`&d]\"Z~X]V[ZSwQVUTMRKo2NGFjDIHGF?>b%A@?87[;{921U5.3210)M-,%k#(!EfeB"y~}v{zyr8%

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


0

TI-83 / 84 BASIC、124バイト

For(A,1,E4
DelVar Nint(log(A→P
Ans→Q
While Ans
For(I,0,Q-Ans
10^(P+1
AnsfPart(iPart(A/10^I)/Ans→S
min(Ans={2,3,5
If S≥7 and fPart(.5S
min(remainder(S,3+2cumSum(not(binompdf(int(.5√(S)),0
N+not(Ans→N
End
P-1→P
End
If not(N
Disp A
End

最初の1万個の整数をループします。Nにカウンターを設定して各部分文字列の素数をチェックし、int(log(Aは現在の数字の桁数より1つ少ない数を取得します。次に、その数字を2番目の変数に設定します。少なくとも2桁の部分文字列10 ^ ...およびAnsfPart(iPart(,,,現在の部分文字列を生成して素数性をチェックし、次の3行でAnsの素数チェックを1または0にします。部分文字列が素数でない場合、Nをインクリメントします。Nがまだ0である場合、すべてのサブストリングがチェックされた後、現在の数値を出力します。

このテストに向けた素数チェックの効率を高めるために、おそらくいくつかの調整を行うことができますか?TI-83フォーマットで出力を直接保存するよりも少ないバイト数でアルゴリズムを見つけたことが嬉しいです!



0

PHP、135バイト

for(;++$n<1e4;$p||print"$n
")for($p=$i=0;$i<$l=strlen($n);$i++)for($j=1;$j++<$l-$i;$p|=$k)for($k=($m=substr($n,$i,$j))-1;$k&&$m%$k--;);

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

for(;                         // level 1 loop on
  ++$n<1e4;                   // all numbers from 1 to 10,000, $n is current number
  $p||print"$n\n"             // at the end of loop for each number, print $n if all multi digit sub strings were prime ($p=0)
)
  for(                        // level 2 loop on each digit of $n
    $p=                       // $p is a flag for all sub string primes and is set to 0 for each new $n
      $i=0;                   // $i is position of current digit (and sub string start position)
    $i<$l=strlen($n);         // $l is the total digits count in $n
    $i++                      // increment $i by one
  )
    for(                      // level 3 loop to create sub strings
      $j=1;                   // $j is length of sub string, we only care about multi digit sub strings so it starts from 1
      $j++<$l-$i;             // continue the loop as long as $j has not reached last digit and increment it by one
      $p|=$k                  // THIS IS RUN AFTER LOOP LEVEL 4: update $p flag based on value of $k
                              //     $p will be left at 0 only if all of the sub strings are prime (if $k is always 0)
    )
      for(                    // level 4 loop to check each sub string to be prime
        $k=(                  // $k is set to current sub string minus 1
          $m=substr($n,$i,$j) // $m is current sub string
        )-1;                  // 
        $k && $m%$k--;        // as long as $k is more than 0 and $m%$k is not zero, decrement $k by one and continue
                              //     a prime number will only get a 0 remainder, when $k gets to 1
                              //     so $k will be 0 for primes and more than 0 for non-primes
      );
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.