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 generate a b = seq { | |
| yield (a, b) | |
| let rec down (a, b) diff secondPass = seq { | |
| let next = a - diff, b + diff - 1 | |
| yield next | |
| yield! up next diff (not secondPass) | |
| } | |
| and up (a,b) diff secondPass = seq { | |
| yield! Seq.init diff (fun i -> a + 1 + i, b - 1 - i) | |
| yield! down (a + diff, b - diff) (if secondPass then diff + 1 else diff) secondPass |
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 getLPF num = | |
| let rec getLPF l rest = | |
| seq { yield 2L; yield! seq {3L..2L..(rest |> float |> sqrt |> int64)}} | |
| |> Seq.tryFind (fun d -> rest % d = 0L) | |
| |> function | |
| | None -> max l rest | |
| | Some d -> getLPF (max l d) (rest / d) | |
| getLPF 1L num;; | |
| getLPF 600851475143L |
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
| Seq.unfold (fun (c, n) -> Some(c, (n, c + n))) (1, 2) | |
| |> Seq.takeWhile (fun v -> v <= 4000000) | |
| |> Seq.filter (fun v -> v % 2 = 0) | |
| |> Seq.sum |
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 n = 1000;; | |
| [1..n-1] | |
| |> Seq.filter (fun v -> v % 3 = 0 || v % 5 = 0) | |
| |> Seq.sum |
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
| open System | |
| type Agent<'a> = MailboxProcessor<'a> | |
| type Msg = Step of int | End | |
| let getRingHead n = | |
| let lastNode = | |
| Agent.Start(fun inbox -> | |
| let rec loop (time : DateTime) = async { | |
| let! m = inbox.Receive() |
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
| #r @"System.Reactive.dll" | |
| open System | |
| open System.Reactive.Subjects | |
| open System.Reactive.Linq | |
| let run n m = | |
| let now = DateTime.Now | |
| let nodes = List.init n (fun _ -> new Subject<_>()) |
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 toVarint v = | |
| let rec loop n s = | |
| match n >>> 7, n &&& 127 with | |
| | (0, c) -> byte c :: s | |
| | (r, c) -> loop r (byte (128 ||| c) :: s) | |
| loop v [] |
NewerOlder