Skip to content

Instantly share code, notes, and snippets.

@einarwh
einarwh / aoc14.fsx
Last active December 15, 2024 13:46
Advent of Code 2024. Day 14: Restroom Redoubt. F# version.
// Advent of Code 2024. Day 14: Restroom Redoubt.
// dotnet fsi aoc14.fsx
open System
open System.IO
open System.Diagnostics
type Pos = (int * int)
type Robot = { p : Pos; v : Pos }
@einarwh
einarwh / aoc13.fsx
Last active December 13, 2024 10:11
Advent of Code 2024. Day 13: Claw Contraption. F# version.
// Advent of Code 2024. Day 13: Claw Contraption.
// dotnet fsi aoc13.fsx
open System
open System.IO
type Machine =
{ ax : int64
bx : int64
ay : int64
@einarwh
einarwh / aoc12.fsx
Last active December 12, 2024 14:31
Advent of Code 2024. Day 12: Garden Groups. F# version.
// Advent of Code 2024. Day 12: Garden Groups.
// dotnet fsi aoc12.fsx
open System
open System.IO
module Garden =
let inBounds (a : 'a[,]) (x, y) =
let first = y >= 0 && y < a.GetLength(0)
let second = x >= 0 && x < a.GetLength(1)
@einarwh
einarwh / aoc11.fsx
Created December 11, 2024 16:17
Advent of Code 2024. Day 11: Plutonian Pebbles. F# version.
// Advent of Code 2024. Day 11: Plutonian Pebbles.
// dotnet fsi aoc11.fsx
open System
open System.IO
let applyRules stone =
if stone = 0L then [1L]
else
let s = stone.ToString()
@einarwh
einarwh / aoc10.fsx
Last active December 10, 2024 23:06
Advent of Code 2024. Day 10: Hoof It. F# version.
// Advent of Code 2024. Day 10: Hoof It.
// dotnet fsi aoc10.fsx
open System
open System.IO
module Array2D =
let inBounds (a : 'a[,]) (x, y) =
let first = y >= 0 && y < a.GetLength(0)
let second = x >= 0 && x < a.GetLength(1)
@einarwh
einarwh / aoc09.fsx
Created December 10, 2024 22:56
Advent of Code 2024. Day 09: Disk Fragmenter. F# version.
// Advent of Code 2024. Day 09: Disk Fragmenter.
// dotnet fsi aoc09.fsx
open System
open System.IO
open System.Collections.Generic
type DiskEntry =
| File of (int * int)
| Free of int
@einarwh
einarwh / aoc08.fsx
Last active December 8, 2024 09:01
Advent of Code 2024. Day 08: Resonant Collinearity. F# version.
// Advent of Code 2024. Day 08: Resonant Collinearity.
// dotnet fsi aoc08.fsx
open System
open System.IO
module Array2D =
let inBounds (a : 'a[,]) (x, y) =
let first = y >= 0 && y < a.GetLength(0)
let second = x >= 0 && x < a.GetLength(1)
@einarwh
einarwh / aoc07.fsx
Created December 7, 2024 07:57
Advent of Code 2024. Day 07: Bridge Repair. F# version.
// Advent of Code 2024. Day 07: Bridge Repair.
// dotnet fsi aoc07.fsx
open System
open System.IO
let split (splitter : string) (input : string) = input.Split(splitter)
let parseLine s =
let parts = s |> split ": "
@einarwh
einarwh / Array2D.fsx
Created December 6, 2024 08:02
Array2D module.
module Array2D =
let tryGet (a : 'a[,]) (x, y) =
let first = y >= 0 && y < a.GetLength(0)
let second = x >= 0 && x < a.GetLength(1)
if first && second then Some (Array2D.get a y x) else None
let positions (a : 'a[,]) =
let rowCount = a.GetLength(0)
let colCount = a.GetLength(1)
[for x in [0..colCount-1] do for y in [0..rowCount-1] -> (x, y)]
let fromList (lst : 'a list list) =
@einarwh
einarwh / aoc06.fsx
Last active December 6, 2024 08:01
Advent of Code 2024. Day 06: Guard Gallivant. F# version.
// Advent of Code 2024. Day 06: Guard Gallivant.
// dotnet fsi aoc06.fsx
open System
open System.IO
module Array2D =
let tryGet (a : 'a[,]) (x, y) =
let first = y >= 0 && y < a.GetLength(0)
let second = x >= 0 && x < a.GetLength(1)