Last active
September 18, 2019 21:57
-
-
Save Ch3shireDev/ef485551ad423363e8dc76b140e3dfbd to your computer and use it in GitHub Desktop.
My first F# program - Primes
This file contains hidden or 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 prime n = | |
| if n = 2 then true | |
| else | |
| let arr = [for i in 2..n-1 -> n%i=0] | |
| List.contains true arr |> not | |
| //let choiser elem = if elem > 0 then Some(elem) else None | |
| //let f x = List.choose choiser x | |
| let primes = List.choose (fun i -> if (prime i) then Some(i) else None) [2..500] | |
| printfn "%A" primes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment