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 part2 = | |
travel (1, 1) | |
|> Seq.take 50 | |
|> Seq.map snd | |
|> Seq.sumBy Seq.length | |
|> (+) 1 // the starting position |
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 = | |
travel (1, 1) | |
|> Seq.filter (fun (_, ps) -> ps |> List.exists ((=) (31, 39))) | |
|> Seq.head | |
|> fst |
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 countSetBitsV1 n = | |
let rec loop n count = | |
if n = 0 then count | |
else loop (n >>> 1) <| count + (n &&& 1) | |
loop n 0 | |
let countSetBitsV2 n = | |
let rec loop n count = | |
if n = 0 then count |
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.IO | |
let inputs = File.ReadAllLines (__SOURCE_DIRECTORY__ + "/Day12Input.txt") | |
let (|Int|_|) x = | |
match Int32.TryParse x with | |
| true, n -> Some n | |
| _ -> None |
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 initFloorsPart2 = | |
[| | |
set [ Generator "promethium"; Microchip "promethium"; | |
Generator "elerium"; Microchip "elerium"; | |
Generator "dilithium"; Microchip "dilithium" ] | |
set [ Generator "cobalt"; Generator "curium"; | |
Generator "ruthenium"; Generator "plutonium" ] | |
set [ Microchip "cobalt"; Microchip "curium"; | |
Microchip "ruthenium"; Microchip "plutonium" ] | |
set [] |
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 initFloorsPart1 = | |
[| | |
set [ Generator "promethium"; Microchip "promethium" ] | |
set [ Generator "cobalt"; Generator "curium"; | |
Generator "ruthenium"; Generator "plutonium" ] | |
set [ Microchip "cobalt"; Microchip "curium"; | |
Microchip "ruthenium"; Microchip "plutonium" ] | |
set [] | |
|] |
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 solve initState = | |
let visitedStates = new System.Collections.Generic.HashSet<string>() | |
let next { Elevator = floorNum; Floors = floors } = | |
// all the different ways items can be loaded into the elevator | |
let itemCombos (floor : Floor) = | |
seq { | |
for item in floor do | |
yield set [ item ] | |
for otherItem in floor.Remove item do |
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 State = | |
{ | |
Elevator : int | |
Floors : Floor[] | |
} | |
override x.ToString() = | |
let byElement = | |
x.Floors | |
|> Seq.mapi (fun n items -> items |> Seq.map (fun i -> n, i)) |