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 sieveOfEratosthenes n = | |
let arr = [| for i in 0..n -> 1 |] | |
let sqrt = sqrt(float n) |> int | |
for k = 2 to sqrt + 1 do | |
if arr.[k] = 1 then | |
for j in 2*k..k..n-1 do | |
arr.[j] <- 0 | |
seq { for i in 2..n-1 do if arr.[i] = 1 then yield i } |
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 | |
open System.Collections.Generic | |
let sieve n = | |
seq { | |
let hash = new HashSet<int64>() | |
yield 2L | |
for k in 3L..2L..System.Int64.MaxValue do | |
if not (hash.Contains k) then | |
yield k |
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 factorize n = | |
let rec find i = | |
if i >= n then None | |
elif (n % i = 0) then Some(i, n/i) | |
else find(i+1) | |
find 2 |
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
module Tests | |
open NUnit.Framework | |
open FsxUnit | |
open ProjectEuler | |
type ``Project Euler 1 Tests``() = | |
[<Test>] member test. | |
``Given a empty list sum all members should be equal 0``() = | |
[] |> sumAllMultiplesOf3Or5 |> should be (equal 0) | |
[<Test>] member test. |
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 isMultipleOf3Or5 x = x % 3 = 0 || x % 5 = 0 | |
let sumAllMultiplesOf3Or5Ref list = | |
list |> List.filter isMultipleOf3Or5 | |
|> List.sum |
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 isMultipleOf3Or5 x = x % 3 = 0 || x % 5 = 0 | |
let sumAllMultiplesOf3Or5 list = List.sum (List.filter isMultipleOf3Or5 list) |
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 sumAllMultiplesOf3Or5 list = | |
let mutable total = 0 | |
for i in list do | |
if i % 3 = 0 || i % 5 = 0 then | |
total <- total + i | |
total | |
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 numerosExtenso = ["Um"; "Dois"; "Três"] | |
let numeros = [1;2;3] | |
let tupla = List.zip numeros numerosExtenso | |
for i, j in tupla do | |
printfn "Numero: %d - Numero por extenso: %s" i j |
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 nome = "Rodrigo Vidal" | |
nome <- "Don Syme" |
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 nome = "Rodrigo Vidal" | |
nome = "Don Syme" |