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 "packages/FParsec/lib/net40-client/FParsecCS.dll" | |
#r "packages/FParsec/lib/net40-client/FParsec.dll" | |
open FParsec | |
type Operation = | |
| Spin of int | |
| Exchange of int * int | |
| Partner of char * char | |
type ParserState = unit |
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 "packages/FParsec/lib/net40-client/FParsecCS.dll" | |
#r "packages/FParsec/lib/net40-client/FParsec.dll" | |
open FParsec | |
type Operation = | |
| Spin of int | |
| Exchange of int * int | |
| Partner of char * char | |
type ParserState = unit |
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 Operation = | |
| Spin of int | |
| Exchange of int * int | |
| Partner of char * char |
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 memoryValues = | |
seq { | |
yield 1 | |
let rec loop i (ring : int []) = | |
seq { | |
yield! ring |> Seq.ofArray | |
let nring = generateRing i ring | |
yield! loop (i+1) nring | |
} | |
yield! loop 2 [|1;2;4;5;10;11;23;25|] |
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 generateRing ringId previousRing = | |
let rowLength = ringId * 2 | |
let ringSize = rowLength * 4 | |
let ring = Array.zeroCreate ringSize | |
let data = (rowLength, previousRing, ring) | |
for i in 0 .. (ringSize - 1) do | |
let value = | |
match (data, i) with | |
| FirstItem 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 wrapGet (arr : int []) = function | |
| x when x < 0 -> arr.[arr.Length + x] | |
| x -> arr.[x] | |
let generalIndexOffset rowLength location = 2 * (location / rowLength) + 1 | |
let (|LastItem|_|) ((_, previousRing : int [], currentRing : int []), i) = | |
if i = currentRing.Length - 1 | |
then Some (currentRing.[i - 1] + currentRing.[0] + previousRing.[previousRing.Length - 1]) |
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 part1 location = | |
let rowOffset ringId limit = | |
match (location - limit) % (ringId * 2) with | |
| 0 -> ringId | |
| x when x - ringId < 0 -> (ringId - x) % ringId | |
| x -> x % ringId | |
location |> function | |
| x when x <= 1 -> 0 | |
| x -> |
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 rings = | |
seq { | |
yield (0,1) | |
yield! Seq.unfold | |
(fun (i, previous) -> | |
let ringId = i + 1 | |
let m = (ringId, (ringId * 2 * 4) + previous) | |
Some (m,m)) (0,1) } |
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 "packages/FsCheck/lib/net452/" | |
#r "FsCheck.dll" | |
#I "artifacts/" | |
#r "ThereAndBack.dll" | |
open FsCheck | |
open System | |
let ``Check there and back of DateTime encryption`` (input : DateTime) = |
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 datapoints = [1 .. 400000] | |
let keys = [1; -4; 45000; 2501; 56000] | |
// Enable some evaluation statistics. Execute #time again to disable. | |
#time | |
let singleKeyLookup fn = fn datapoints 67 |> ignore | |
let multiKeyLookup (fn : int seq -> int -> bool) = | |
keys |> List.map (fn datapoints) |