Perl Weekly Challenge 146: 10001st Prime Number

by Abigail


Write a script to generate the 10001st prime number.


The 10001st prime number is 104743. (This is task 7 of project Euler).

Fixed output challenges are boring. They're just glorified Hello, World programs.



The easiest Perl solution is just a one liner:

say 104743

For the sake of not being entirely trivial, we make use of Math::Prime::Util::PrimeArray. It provides a tied array, where the Nth element is the Nth prime number.

Which results in

use Math::Prime::Util::PrimeArray;
tie my @p, 'Math::Prime::Util::PrimeArray';
say $p [10000];

Find the full program on GitHub.


program ch1
    implicit none
    write (*, *) "104743"

What's there to say? We just have to print 104743 — which we do.

Other languages

We also have trivial solutions in

AWK, Bash, Basic, bc, Befunge-93, C, Cobol, Csh, Erlang, Forth, Go, Java, Lua, m4, MMIX, Node.js, OCaml, Pascal, PHP, PostScript, Python, R, Rexx, Ruby, Scheme, Sed, SQL, and Tcl.

Please leave any comments as a GitHub issue.