Javaの10、195の 194 184 182バイト
n->{var L=new java.util.Stack();int i=1,k,x,s,r=0;for(;i++<n;){for(k=1;i%++k>0;);if(k==i)L.add(i);}for(x=L.size(),i=0;i<x;)for(k=i++,s=0;k<x;r+=s==n?1:0)s+=(int)L.get(k++);return r;}
@ceilingcatのおかげで-1バイト。@SaraJの
おかげで-10バイト。
オンラインでお試しください。
説明:
n->{ // Method with integer as both parameter and return-type
var L=new java.util.Stack();
// List of primes, starting empty
int i=1,k,x,s, // Temp integers
r=0; // Result-counter, starting at 0
for(;i++<n;){ // Loop `i` in the range [2, `n`]
for(k=1; // Set `k` to 1
i%++k>0;); // Inner loop which increases `k` by 1 before every iteration,
// and continues as long as `i` is not divisible by `k`
if(k==i) // If `k` is now still the same as `i`; a.k.a. if `i` is a prime:
L.add(i);} // Add the prime to the List
for(x=L.size(), // Get the amount of primes in the List
i=0;i<x;) // Loop `i` in the range [0, amount_of_primes)
for(s=0, // (Re)set the sum to 0
k=i++;k<x; // Inner loop `k` in the range [`i`, amount_of_primes)
r+=s==n? // After every iteration, if the sum is equal to the input:
1 // Increase the result-counter by 1
: // Else:
0) // Leave the result-counter the same by adding 0
s+=(int)L.get(k++);
// Add the next prime (at index `k`) to the sum
return r;} // And finally return the result-counter
それは、基本的に似てゼリーや05AB1E答え、ちょうど190バイト詳細.. XDは
ちょうど楽しみのために追加の部品のそれぞれについて、ここでの比較、(およびJavaはとても冗長である理由を参照し、これらのゴルフ言語はとても強力であるため)。
- 入力を受け取ります:(Jelly:0バイト)暗黙的に ; (05AB1E:0バイト)暗黙的に ; (Java 10:5バイト)
n->{}
- 範囲内の素数のリストを作成します
[2, n]
:(Jelly:2 bytes)ÆR
; (05AB1E:2バイト)ÅP
; (Java 10:95バイト)var L=new java.util.Stack();int i=1,k,x,s,r=0;for(;i++<n;){for(k=1;i%++k>0;);if(k==i)L.add(i);}
- すべての連続サブリストを取得します:(ゼリー:1バイト)
Ẇ
; (05AB1E:1バイト)Œ
; (Java 10:55バイト)for(x=L.size(),i=0;i<x;)for(k=i++;k<x;)
および(int)L.get(k++);
- 各サブリストの合計:(ゼリー:1バイト)
§
; (05AB1E:1バイト)O
; (Javaの10:9バイト),s
と,s=0
とs+=
- 入力に等しいものを数えます:(ゼリー:1バイト)
ċ
; (05AB1E:2バイト)QO
; (Java 10:15バイト),r=0
およびr+=s==n?1:0
- 結果を出力します:(Jelly:0 bytes)implicitly ; (05AB1E:0バイト)暗黙的に ; (Java 10:9バイト)
return r;
2æR
と同じですÆR