Goldbach's comet: Difference between revisions

Content added Content deleted
m (Uploaded Rust output file)
(Added 11l)
Line 28: Line 28:





=={{header|11l}}==
{{trans|Python}}

<syntaxhighlight lang="11l">
F is_prime(a)
I a == 2
R 1B
I a < 2 | a % 2 == 0
R 0B
L(i) (3 .. Int(sqrt(a))).step(2)
I a % i == 0
R 0B
R 1B

F g(n)
assert(n > 2 & n % 2 == 0, ‘n in goldbach function g(n) must be even’)
V count = 0
L(i) 1 .. n I/ 2
I is_prime(i) & is_prime(n - i)
count++
R count

print(‘The first 100 G numbers are:’)

V col = 1
L(n) (4.<204).step(2)
print(String(g(n)).ljust(4), end' I (col % 10 == 0) {"\n"} E ‘’)
col++

print("\nThe value of G(1000000) is "g(1'000'000))
</syntaxhighlight>

{{out}}
<pre>
The first 100 G numbers are:
1 1 1 2 1 2 2 2 2 3
3 3 2 3 2 4 4 2 3 4
3 4 5 4 3 5 3 4 6 3
5 6 2 5 6 5 5 7 4 5
8 5 4 9 4 5 7 3 6 8
5 6 8 6 7 10 6 6 12 4
5 10 3 7 9 6 5 8 7 8
11 6 5 12 4 8 11 5 8 10
5 6 13 9 6 11 7 7 14 6
8 13 5 8 11 7 9 13 8 9

The value of G(1000000) is 5402
</pre>


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==