Skip to content

Instantly share code, notes, and snippets.

@jdh30
Created November 21, 2022 11:59
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 jdh30/41ee0bc873059d0d3250492812cadb93 to your computer and use it in GitHub Desktop.
Save jdh30/41ee0bc873059d0d3250492812cadb93 to your computer and use it in GitHub Desktop.
Compute the prime factors of the given number
let primeFactors x =
let rec loop fs c p =
if p < c * c then Array.Unsafe.append fs p else
if mod(p, c) = 0 then
loop (Array.Unsafe.append fs c) c (p / c)
else loop fs (c + 1) p in
loop {} 2 x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment