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
| type Direction = Left | Right | |
| type Instruction = | |
| | SwapPos of int * int | |
| | SwapLetter of char * char | |
| | Rotate of Direction * int | |
| | RotateBasedOn of char | |
| | Reverse of int * int | |
| | Move of int * int |
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 findAllowedIPs input = | |
| let rec loop lo hi input = seq { | |
| match input with | |
| | [] -> () | |
| | (lo', hi')::tl -> | |
| if lo' > hi + 1L then | |
| yield! { hi+1L .. lo'-1L} | |
| yield! loop lo (max hi hi') tl | |
| } |
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.IO | |
| open Checked | |
| let input = | |
| File.ReadAllLines(__SOURCE_DIRECTORY__ + "/Day20Input.txt") | |
| |> Seq.map (fun line -> | |
| let [| lo; hi |] = line.Split('-') | |
| int64 lo, int64 hi) | |
| |> Seq.sortBy fst | |
| |> Seq.toList |
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 part2 = | |
| let n = log3 input | |
| let m = pown 3.0 n | |
| let l = input - m | |
| if l = 0.0 then m |> int | |
| elif l <= m then l |> int | |
| else m + (l - m) * 2.0 |> int |
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 input = 3018458.0 | |
| let logn n m = log10 m / log10 n |> floor |> int | |
| let log2 = logn 2.0 | |
| let log3 = logn 3.0 | |
| let part1 = | |
| let l = input - pown 2.0 (log2 input) |> int | |
| 2 * l + 1 |
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
| type Elf = { N: int; mutable Gifts: int } | |
| let rec loop (elves: ResizeArray< Elf>)= | |
| let this = elves.[0] | |
| let opposite = elves.[elves.Count / 2] | |
| this.Gifts <- this.Gifts + opposite.Gifts | |
| opposite.Gifts <- 0 | |
| elves.RemoveAt(elves.Count/2) |
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 input = "^.^^^..^^...^.^..^^^^^.....^...^^^..^^^^.^^.^^^^^^^^.^^.^^^^...^^...^^^^.^.^..^^..^..^.^^.^.^......." | |
| let part1 = solve input 40 | |
| let part2 = solve input 400000 |
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 | |
| let previousTiles (row : string) = | |
| seq { | |
| yield [| '.'; row.[0]; row.[1] |] | |
| yield! row |> Seq.windowed 3 | |
| yield [| row.[row.Length-2]; row.[row.Length-1]; '.' |] | |
| } | |
| let genRows input = |
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 findPaths input = | |
| [| ((0, 0), input) |] | |
| |> Seq.unfold (fun paths -> | |
| paths | |
| |> Array.filter (fun (pos, _) -> pos <> (3, 3)) | |
| |> Array.collect (fun (pos, path) -> | |
| let hashVals = hash path |> Seq.take 4 | |
| hashVals | |
| |> Seq.zip [| up; down; left; right |] | |
| |> Seq.choose (fun (f, hashVal) -> |
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 inline between low hi x = x >= 0 && x < hi | |
| let step direction (dx, dy) (x, y) path = | |
| if x + dx |> between 0 width && y + dy |> between 0 height | |
| then Some((x+dx, y+dy), path + direction) | |
| else None | |
| let up = step "U" (0, -1) | |
| let down = step "D" (0, 1) | |
| let left = step "L" (-1, 0) |