Wolstenholme numbers: Difference between revisions
Content added Content deleted
m (→{{header|Python}}: add stretch task) |
|||
Line 316: | Line 316: | ||
935 984 1202 1518 1539 |
935 984 1202 1518 1539 |
||
1770 1811 2556 2762 2769</syntaxhighlight> |
1770 1811 2556 2762 2769</syntaxhighlight> |
||
=={{header|Julia}}== |
|||
{{trans|Python}} |
|||
<syntaxhighlight lang="julia">using Primes |
|||
""" Get N numbers in the series of Wolstenholme numbers """ |
|||
wolstenholme(N) = map(numerator, accumulate(+, (1 // (i*i) for i in big"1":N))) |
|||
""" Abbreviate a large string by showing beginning / end and number of chars """ |
|||
function abbreviate(s, term = "digits", thresh = 50, idx = thresh ÷ 2 - 3) |
|||
w = length(s) |
|||
return w < thresh ? s : s[begin:begin+idx] * ".." * s[end-idx:end] * " ($w $term)" |
|||
end |
|||
""" Run the tasks at rosettacode.org/wiki/Wolstenholme_numbers """ |
|||
function process_wolstenholmes(nmax = 10000, filterto = 2000) |
|||
wols = wolstenholme(nmax) |
|||
println("Wolstenholme numbers 1:20, 500, 1000, 2500, 5000, 10000:") |
|||
for i in [1:20; [500, 1000, 2500, 5000, 10000]] |
|||
println(rpad(i, 5), ": ", abbreviate(string(wols[i]))) |
|||
end |
|||
println("\nFifteen Wolstenholme primes:") |
|||
for (i, n) in enumerate(filter(isprime, @view wols[begin:filterto])) |
|||
println(rpad(i, 2), ": ", abbreviate(string(n))) |
|||
end |
|||
end |
|||
process_wolstenholmes() |
|||
</syntaxhighlight>{{out}} |
|||
<pre> |
|||
Wolstenholme numbers 1:20, 500, 1000, 2500, 5000, 10000: |
|||
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 |
|||
500 : 40989667509417020364501..12248084984597965892703 (434 digits) |
|||
1000 : 83545938483149689478187..58699094240207812766449 (866 digits) |
|||
2500 : 64537911900230612090849..91212785535902976933153 (2164 digits) |
|||
5000 : 34472086597488537716198..20022525144829082590451 (4340 digits) |
|||
10000: 54714423173933343999582..37149175649667700005717 (8693 digits) |
|||
Fifteen Wolstenholme primes: |
|||
1 : 5 |
|||
2 : 266681 |
|||
3 : 40799043101 |
|||
4 : 86364397717734821 |
|||
5 : 36190908596780862323291..68379995976006474252029 (104 digits) |
|||
6 : 33427988094524601237303..12048446489305085140033 (156 digits) |
|||
7 : 22812704758392002353774..54384405125167217413149 (218 digits) |
|||
8 : 28347687473208792918550..41045794572911130248059 (318 digits) |
|||
9 : 78440559440644426017290..55630422337523878698419 (520 digits) |
|||
10: 22706893975121925531372..03702173859396183964989 (649 digits) |
|||
11: 27310394808585898968805..03886311385662644388271 (935 digits) |
|||
12: 13001072736642048751114..78008635832246554146071 (984 digits) |
|||
13: 15086863305391456002934..94405367804007944918693 (1202 digits) |
|||
14: 23541935187269979100228..81502324742766220468879 (1518 digits) |
|||
15: 40306783143871607599250..98658901192511859288941 (1539 digits) |
|||
</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |