10001th prime: Difference between revisions

From Rosetta Code
Content added Content deleted
(add FreeBASIC)
(→‎{{header|Raku}}: Add a Raku example)
Line 37: Line 37:
{{out}}<pre>%1 = 104743</pre>
{{out}}<pre>%1 = 104743</pre>


=={{header|Raku}}==
<lang perl6>say (^∞).grep( &is-prime )[10000]</lang>
{{out}}
<pre>104743</pre>
=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<lang ring>

Revision as of 19:30, 16 November 2021

10001th prime is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task


Find and show on this page 10001th prime

Fermat

<lang fermat> Prime(10001); </lang>

Output:
104743

FreeBASIC

<lang freebasic>

  1. include "isprime.bas"

function prime( n as uinteger ) as ulongint

   if n=1 then return 2
   dim as integer p=3, pn=1
   while pn<n
       if isprime(p) then pn + = 1
       p += 2
   wend
   return p-2

end function

print prime(10001) </lang>

Output:
104743

J

<lang j>p:10000 NB. the index starts at 0; p:0 = 2</lang>

Output:
104743

PARI/GP

<lang parigp>prime(10001)</lang>

Output:
%1 = 104743

Raku

<lang perl6>say (^∞).grep( &is-prime )[10000]</lang>

Output:
104743

Ring

<lang ring> load "stdlib.ring" see "working..." + nl num = 0 pr = 0 limit = 10001

while true

     num++
     if isprime(num)
        pr++
     ok
     if pr = limit
        exit
     ok

end

see "" + num + nl see "done..." + nl </lang>

Output:
working...
The 10001th prime is: 104743
done...