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
#I @"C:\Projects\Lib" | |
#r "Hopac.dll" | |
#r "Hopac.Core.dll" | |
open System | |
open Hopac | |
open Hopac.Job.Infixes | |
open Hopac.Alt.Infixes | |
open Hopac.Extensions |
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 await (timeout: int) task = | |
async { | |
let evt = Event<_>() | |
let! _ = | |
async { | |
do! Async.Sleep timeout | |
evt.Trigger None | |
} |> Async.StartChild | |
let! _ = |
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.Net | |
open System.Diagnostics | |
let netsh arguments = | |
ProcessStartInfo("netsh", arguments, WindowStyle = ProcessWindowStyle.Hidden) | |
|> Process.Start | |
let rec loop source dest = | |
async { | |
use _ = netsh "interface portproxy reset" |
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
type Meta = interface end | |
type U<'ty>() = | |
class | |
interface Meta | |
end | |
type K<'ty, 'x>(elem: 'x) = | |
interface Meta | |
member x.Elem = elem |
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 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 [] |
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 n = 1000;; | |
[1..n-1] | |
|> Seq.filter (fun v -> v % 3 = 0 || v % 5 = 0) | |
|> Seq.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
#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 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 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 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 |