Goldbach's comet: Difference between revisions

m (→‎{{header|Wren}}: Wren-trait -> Wren-iterate)
Line 972:
'''Stretch goal:''' (offsite SVG image) [https://raw.githubusercontent.com/thundergnat/rc/master/img/Goldbachs-Comet-Raku.svg Goldbachs-Comet-Raku.svg]
 
=={{header|Ruby}}==
following the J comments, but only generating primes up-to half a million
<syntaxhighlight lang="ruby">require 'prime'
 
n = 100
puts "The first #{n} Godbach numbers are: "
sums = Prime.each(n*2 + 2).to_a[1..].repeated_combination(2).map(&:sum)
sums << 4
sums.sort.tally.values[...n].each_slice(10){|slice| puts "%4d"*slice.size % slice}
 
n = 1000000
puts "\nThe value of G(#{n}) is #{Prime.each(n/2).count{|pr| (n-pr).prime?} }."
</syntaxhighlight>
{{out}}
<pre>The first 100 Godbach 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|Rust}}==
<syntaxhighlight lang="rust">// [dependencies]
1,149

edits