Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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