Created
November 21, 2022 11:59
-
-
Save jdh30/41ee0bc873059d0d3250492812cadb93 to your computer and use it in GitHub Desktop.
Compute the prime factors of the given number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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