Skip to content

Instantly share code, notes, and snippets.

@cmbrown1598
Last active October 25, 2017 21:29
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 cmbrown1598/1e3585f676188531607f53cc0d15f3a0 to your computer and use it in GitHub Desktop.
Save cmbrown1598/1e3585f676188531607f53cc0d15f3a0 to your computer and use it in GitHub Desktop.
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