Wolstenholme numbers: Difference between revisions
Content deleted Content added
add RPL |
→{{header|Ruby}}: Add Ruby |
||
Line 927:
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'prime'
res = (1..20).each.inject([0]){|memo, n| memo << memo.last + (1r/(n*n))}
wolstenholmes = res.map(&:numerator)[1..]
wolstenholmes_primes = wolstenholmes.select(&:prime?)
[wolstenholmes, wolstenholmes_primes].each do |whs|
whs.each.with_index(1){|n, i| puts "%-3d: %d" % [i, n] }
puts
end
</syntaxhighlight>
{{out}}
<pre>1 : 1
2 : 5
3 : 49
4 : 205
5 : 5269
6 : 5369
7 : 266681
8 : 1077749
9 : 9778141
10 : 1968329
11 : 239437889
12 : 240505109
13 : 40799043101
14 : 40931552621
15 : 205234915681
16 : 822968714749
17 : 238357395880861
18 : 238820721143261
19 : 86364397717734821
20 : 17299975731542641
1 : 5
2 : 266681
3 : 40799043101
4 : 86364397717734821
</pre>
=={{header|Wren}}==
{{libheader|Wren-gmp}}
|