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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// Input data | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
type Layer = { index: int; depth: int; position: int; movement: int } | |
let parse filename = | |
File.ReadAllLines(filename) | |
|> Seq.map (fun line -> | |
let parts = line.Split(':') |
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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// Input data | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
let parse filename = | |
File.ReadAllLines(filename) | |
|> Seq.map (fun line -> | |
let segments = line.Split([| "<->" |], StringSplitOptions.None) | |
let targets = segments.[1].Split(',') |> Seq.map Int32.Parse | |
(Int32.Parse segments.[0], targets)) |
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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// Input data | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
let parse filename = | |
File.ReadAllText(filename).Split(',') | |
|> Seq.map | |
(fun direction -> // use axial coordinates from https://www.redblobgames.com/grids/hexagons/ | |
match direction with | |
| "n" -> ( 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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// Input data | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
let parseAsInts filename = File.ReadAllText(filename).Split(',') |> Seq.map Int32.Parse | |
let parseAsChars filename = File.ReadAllText(filename) |> Seq.map (int) | |
let dataInts = parseAsInts "queries/Advent/Advent2017-day10.txt" | |
let dataChars = parseAsChars "queries/Advent/Advent2017-day10.txt" |
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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// Input data | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
let parse filename = | |
File.ReadAllText(filename) | |
|> Seq.scan | |
(fun state c -> | |
match (c, state) with | |
| (_, (nesting, inGarbage, totalGarbage, true, _)) -> (nesting, inGarbage, totalGarbage, false, ' ') // ignoring next |
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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// Input data | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
let parse filename = | |
File.ReadAllLines(filename) | |
|> Seq.map (fun line -> line.Split(' ') |> List.ofArray) | |
|> Seq.map (fun parts -> | |
match parts with | |
| [name; "inc"; value; "if"; target; condition; targetValue] -> (name, ((+) (Int32.Parse value)), target, (condition, Int32.Parse targetValue)) |
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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// Input data | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
let parse filename = | |
File.ReadAllLines(filename) | |
|> Seq.map (fun line -> Regex.Match(line, "([a-z]+) \((\d+)\)(?: -> ([a-z, ]+))?")) | |
|> Seq.map ( | |
fun regexMatch -> | |
( regexMatch.Groups.[1].Value, |
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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// Input data | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
let parse filename = | |
File.ReadAllText(filename).Split('\t') | |
|> Seq.map Int32.Parse | |
|> List.ofSeq | |
let data = parse "queries/Advent/Advent2017-day06.txt" |
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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// Input data | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
let parse filename = | |
File.ReadAllLines(filename) | |
|> Seq.map Int32.Parse | |
|> Seq.toArray | |
let data = parse "queries/Advent/Advent2017-day05.txt" |
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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// Input data | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
let parse filename = | |
File.ReadAllLines(filename) | |
|> Seq.map (fun line -> line.Split(' ')) | |
let data = parse "queries/Advent/Advent2017-day04.txt" |