Skip to content

Instantly share code, notes, and snippets.

@einarwh
einarwh / aoc14.fsx
Created December 14, 2023 11:41
Advent of Code 2023 - Day 14: Parabolic Reflector Dish - F# version
// Advent of Code 2023. Day 14: Parabolic Reflector Dish
// dotnet fsi aoc14.fsx
open System
open System.IO
let readLines =
File.ReadAllLines >> Array.filter ((<>) String.Empty)
let rollNorthStep (s1, s2) =
@einarwh
einarwh / aoc13.fsx
Last active December 13, 2023 08:54
Advent of Code 2023 - Day 13: Point of Incidence - F# version
// Advent of Code 2023. Day 13: Point of Incidence
// dotnet fsi aoc13.fsx
open System
open System.IO
let readChunks fileName =
let text = File.ReadAllText fileName
text.TrimEnd().Split("\n\n") |> Array.toList
@einarwh
einarwh / aoc12.fsx
Last active December 12, 2023 16:42
Advent of Code 2023 - Day 12: Hot Springs - F# version
// Advent of Code 2023. Day 12: Hot Springs
// dotnet fsi aoc12.fsx
open System
open System.IO
let parseLine (s : string) =
let parts = s.Split(" ")
let springs = parts[0]
let damaged = parts[1]
@einarwh
einarwh / aoc11.fsx
Last active December 11, 2023 09:10
Advent of Code 2023 - Day 11: Cosmic Expansion - F# version
// Advent of Code 2023. Day 11: Cosmic Expansion
// dotnet fsi aoc11.fsx
open System
open System.IO
let readLines =
File.ReadAllLines >> Array.filter ((<>) String.Empty)
let findEmptyRows rows =
@einarwh
einarwh / aoc10.fsx
Last active December 10, 2023 17:04
Advent of Code 2023 - Day 10: Pipe Maze - F# version
// Advent of Code 2023. Day 10: Pipe Maze
// dotnet fsi aoc10.fsx
open System
open System.IO
module Array2D =
let tryGet (a : 'a[,]) index1 index2 =
let first = index1 >= 0 && index1 < a.GetLength(0)
let second = index2 >= 0 && index2 < a.GetLength(1)
@einarwh
einarwh / Tailor.cs
Created December 9, 2023 14:41
Printing Hello, World! with nested enumerables.
namespace Tailor;
using System.Collections;
using System.Collections.Generic;
public static class EnumerableExt
{
public static IEnumerable<T> Tail<T>(this IEnumerable<T> source)
{
return new TailEnumerable<T>(source);
@einarwh
einarwh / aoc09.fsx
Created December 9, 2023 09:14
Advent of Code 2023 - Day 9: Mirage Maintenance - F# version
// Advent of Code 2023. Day 9: Mirage Maintenance
// dotnet fsi aoc09.fsx
open System
open System.IO
let parseLine (s : string) =
s.Split(" ") |> Array.toList |> List.map int64
let differences =
@einarwh
einarwh / aoc08.fsx
Last active December 9, 2023 09:14
Advent of Code 2023 - Day 8: Haunted Wasteland - F# version
// Advent of Code 2023. Day 8: Haunted Wasteland
// dotnet fsi aoc08.fsx
open System
open System.IO
let parse (s : string) =
let a = s.Substring(0, 3)
let b = s.Substring(7, 3)
let c = s.Substring(12, 3)
@einarwh
einarwh / aoc01.html
Last active December 7, 2023 14:11
Advent of Code 2023 - Day 1: Trebuchet?! - HTML, the programming language version
<html>
<head>
<script src="html.js"></script>
<script>
function rotateRight(arr) {
arr.unshift(arr.pop());
}
function rotateLeft(arr) {
arr.push(arr.shift());
}
@einarwh
einarwh / aoc07.fsx
Last active December 7, 2023 14:42
Advent of Code 2023 - Day 7: Camel Cards - F# version
// Advent of Code 2023. Day 7: Camel Cards
// dotnet fsi aoc07.fsx
open System
open System.IO
let parseLine (line : string) =
match line.Split(" ") with
| [|card;bid|] -> (card, int bid)
| _ -> failwith "Wrong"