Skip to content

Instantly share code, notes, and snippets.

View milang's full-sized avatar

Milan Gardian milang

  • Calgary, Alberta, Canada
  • 05:39 (UTC -06:00)
View GitHub Profile
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 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(':')
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 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))
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 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)
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 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"
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 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
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 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))
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 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,
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Input data
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let parse filename =
File.ReadAllText(filename).Split('\t')
|> Seq.map Int32.Parse
|> List.ofSeq
let data = parse "queries/Advent/Advent2017-day06.txt"
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Input data
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let parse filename =
File.ReadAllLines(filename)
|> Seq.map Int32.Parse
|> Seq.toArray
let data = parse "queries/Advent/Advent2017-day05.txt"
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Input data
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let parse filename =
File.ReadAllLines(filename)
|> Seq.map (fun line -> line.Split(' '))
let data = parse "queries/Advent/Advent2017-day04.txt"