Summation of primes: Difference between revisions

no edit summary
(Created Nim solution.)
No edit summary
 
(4 intermediate revisions by 4 users not shown)
Line 355:
!!s;</syntaxhighlight>
{{out}}<pre>142913828922</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn IsPrime( n as NSUInteger ) as BOOL
BOOL isPrime = YES
NSUInteger i
if n < 2 then exit fn = NO
if n = 2 then exit fn = YES
if n mod 2 == 0 then exit fn = NO
for i = 3 to int(n^.5) step 2
if n mod i == 0 then exit fn = NO
next
end fn = isPrime
 
 
local fn SumOfPrimes as long
long sum = 2, i, n = 1
for i = 3 to 2000000 step 2
if ( fn IsPrime(i) )
sum += i
n++
end if
next
end fn = sum
 
print fn SumOfPrimes
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
142913828922
</pre>
 
 
=={{header|Go}}==
Line 432 ⟶ 468:
142913828922
</pre>
 
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
block(primes(2,2000000),apply("+",%%));
</syntaxhighlight>
Output
<syntaxhighlight lang="maxima">
/* 142913828922 */
</syntaxhighlight>
 
=={{header|Nim}}==
Line 702 ⟶ 748:
142,913,828,922
done...
</pre>
 
=={{header|RPL}}==
{{works with|HP|49}}
≪ 0 1
'''WHILE''' NEXTPRIME DUP 2E6 <
'''REPEAT''' SWAP OVER + SWAP
'''END''' DROP
≫ '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: 142913828922
</pre>
 
Line 708 ⟶ 766:
{{out}}
<pre>142913828922
</pre>
 
=={{header|Rust}}==
<syntaxhighlight lang="Rust">use primes::is_prime ;
 
fn main() {
println!("{}" , (2u64..2000000u64).filter( | &d | is_prime( d )).sum::<u64>() ) ;
}</syntaxhighlight>
{{out}}
<pre>
142913828922
</pre>
 
Line 759 ⟶ 828:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int, Nums
import "./fmt" for Fmt
 
258

edits