Skip to content

Instantly share code, notes, and snippets.

@HeinrichHartmann
Created January 29, 2023 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HeinrichHartmann/c917de72eceefb35b51126002f1a8101 to your computer and use it in GitHub Desktop.
Save HeinrichHartmann/c917de72eceefb35b51126002f1a8101 to your computer and use it in GitHub Desktop.
with builtins;
let
div = x: y: if y / x * x == y then true else false;
divany = L: x:
if (length L) == 0 then
false
else if (div (head L) x) then
true
else
(divany (tail L) x);
cPrimes = L: candidate: max:
if candidate > max then
L
else if candidate == 2 then
(cPrimes [ 2 ] (candidate + 1) max)
else if (divany L candidate) then
(cPrimes L (candidate + 1) max)
else
(cPrimes (L ++ [ candidate ]) (candidate + 1) max);
primes = x: (cPrimes [ ] 2 x);
in primes 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment