Last active
October 25, 2017 21:29
-
-
Save cmbrown1598/1e3585f676188531607f53cc0d15f3a0 to your computer and use it in GitHub Desktop.
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 getFactors (value : bigint) = | |
let isFactor i pf = | |
i % pf = 0I | |
let rec potentialFactors start i = seq { | |
match start with | |
| Some v when v > 2I -> for a in v..2I..i do yield a | |
| Some _ | None -> | |
yield 2I | |
yield! potentialFactors (Some 3I) i | |
} | |
let rec loop acc lf i = | |
let findFunc = isFactor i | |
let seq = potentialFactors lf i | |
match Seq.tryFind findFunc seq with | |
| Some (f) -> loop (f::acc) (Some (f)) (i / f) | |
| None -> acc | |
if (value < 0I) then loop [-1I] None (value * -1I) | |
elif (value > 0I) then loop [] None value | |
else [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment