Summarize primes: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (Added Arturo implementation) |
|||
Line 4: | Line 4: | ||
Summarize first n primes (p) and check if it is a prime, where '''p < 1000''' |
Summarize first n primes (p) and check if it is a prime, where '''p < 1000''' |
||
<br><br> |
<br><br> |
||
=={{header|Arturo}}== |
|||
<lang rebol>print (pad "index" 6) ++ " | " ++ |
|||
(pad "prime" 6) ++ " | " ++ |
|||
(pad "prime sum" 11) |
|||
print "------------------------------" |
|||
s: 0 |
|||
idx: 0 |
|||
loop 2..999 'n [ |
|||
if prime? n [ |
|||
idx: idx + 1 |
|||
s: s + n |
|||
if prime? s -> |
|||
print (pad to :string idx 6) ++ " | " ++ |
|||
(pad to :string n 6) ++ " | " ++ |
|||
(pad to :string s 11) |
|||
] |
|||
]</lang> |
|||
{{out}} |
|||
<pre> index | prime | prime sum |
|||
------------------------------ |
|||
1 | 2 | 2 |
|||
2 | 3 | 5 |
|||
4 | 7 | 17 |
|||
6 | 13 | 41 |
|||
12 | 37 | 197 |
|||
14 | 43 | 281 |
|||
60 | 281 | 7699 |
|||
64 | 311 | 8893 |
|||
96 | 503 | 22039 |
|||
100 | 541 | 24133 |
|||
102 | 557 | 25237 |
|||
108 | 593 | 28697 |
|||
114 | 619 | 32353 |
|||
122 | 673 | 37561 |
|||
124 | 683 | 38921 |
|||
130 | 733 | 43201 |
|||
132 | 743 | 44683 |
|||
146 | 839 | 55837 |
|||
152 | 881 | 61027 |
|||
158 | 929 | 66463 |
|||
162 | 953 | 70241</pre> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
Line 61: | Line 107: | ||
Summarized primes 1-999: 21 |
Summarized primes 1-999: 21 |
||
</pre> |
</pre> |
||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |