Last active
March 29, 2016 04:04
-
-
Save DavidBrower/e0f303b5c8c0329c0c3e to your computer and use it in GitHub Desktop.
Smallest Common Multiple
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
open System | |
let isDivisibleBy seq n = | |
seq | |
|> Seq.forall (fun x -> n % x = 0) | |
Seq.unfold (fun x -> Some(x, x + 20)) 20 | |
|> Seq.find (isDivisibleBy [|1 .. 20|]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finally, by lazily generating a sequence of numbers that are multiples of 20 we can greatly improve performance: