Skip to content

Instantly share code, notes, and snippets.

@kamocyc
Created February 6, 2021 11:21
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 kamocyc/b6e90e810b0e5a142766f87003d6cb9a to your computer and use it in GitHub Desktop.
Save kamocyc/b6e90e810b0e5a142766f87003d6cb9a to your computer and use it in GitHub Desktop.
// `is_prime` function
=LAMBDA(n, OR(n = 2, AND(n >= 2, SUM((MOD(n,SEQUENCE(SQRT(n),1,2))=0)+0) = 0)))
// `main` function
=LAMBDA(
current_number,
remaining_nth,
IF(is_prime(current_number),
IF(remaining_nth = 1,
current_number,
main(current_number + 1, remaining_nth - 1)
),
main(current_number + 1, remaining_nth)
)
)
// usage (e.g. for 10th prime)
=main(2, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment