Successive prime differences: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (Added Arturo implementation) |
|||
Line 204: | Line 204: | ||
</pre> |
</pre> |
||
=={{header|Arturo}}== |
|||
<lang rebol>LIM: 1000000 |
|||
findDiffs: function [r][ |
|||
if r=[1] -> return [[2 3]] |
|||
i: 3 |
|||
tupled: map 0..dec size r 'x -> fold slice r 0 x [a b][a+b] |
|||
diffs: new [] |
|||
while [i < LIM][ |
|||
if prime? i [ |
|||
prset: map tupled 't -> i + t |
|||
if every? prset 'elem -> prime? elem [ |
|||
'diffs ++ @[@[i] ++ prset] |
|||
] |
|||
] |
|||
i: i + 2 |
|||
] |
|||
diffs: filter diffs 'dd [ |
|||
some? range (first dd)+1 (last dd)-1 'x -> and? [prime? x][not? contains? dd x] |
|||
] |
|||
return diffs |
|||
] |
|||
loop [[2] [1] [2 2] [2 4] [4 2] [6 4 2]] 'rng [ |
|||
print ["Differences of" join.with:", " to [:string] rng] |
|||
diffs: findDiffs rng |
|||
print ["\tFirst: " join.with:" " to [:string] first diffs] |
|||
print ["\tLast: " join.with:" " to [:string] last diffs] |
|||
print ["\tCount: " size diffs] |
|||
]</lang> |
|||
{{out}} |
|||
<pre>Differences of 2 |
|||
First: 3 5 |
|||
Last: 999959 999961 |
|||
Count: 8169 |
|||
Differences of 1 |
|||
First: 2 3 |
|||
Last: 2 3 |
|||
Count: 1 |
|||
Differences of 2, 2 |
|||
First: 3 5 7 |
|||
Last: 3 5 7 |
|||
Count: 1 |
|||
Differences of 2, 4 |
|||
First: 5 7 11 |
|||
Last: 999431 999433 999437 |
|||
Count: 1393 |
|||
Differences of 4, 2 |
|||
First: 7 11 13 |
|||
Last: 997807 997811 997813 |
|||
Count: 1444 |
|||
Differences of 6, 4, 2 |
|||
First: 31 37 41 43 |
|||
Last: 997141 997147 997151 997153 |
|||
Count: 306</pre> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |