Skip to content

Instantly share code, notes, and snippets.

@einarwh
einarwh / HelloWorld.java
Last active January 2, 2024 22:03
Object-oriented Hello World.
import java.io.*;
public interface Printer {
public void print(PrintStream stream);
}
public class ChainPrinter implements Printer {
private final char _c;
private final Printer _next;
public ChainPrinter(char c, Printer next) {
@einarwh
einarwh / HelloWorld.java
Last active January 2, 2024 17:41
Object-oriented Hello World.
import java.io.*;
public abstract class Printer {
protected final PrintStream _stream;
public Printer(PrintStream stream) {
_stream = stream;
}
@einarwh
einarwh / dotify.fsx
Created December 20, 2023 15:56
Advent of Code 2023 - Day 20: Pulse Propagation - Convert input into dot format
// Advent of Code 2023. Day 20: Pulse Propagation.
// Convert input file into dot format for rendering with graphviz.
// dotnet fsi dotify.fsx <inputfile> <outputfile?>
open System
open System.IO
type Node =
| Broadcaster
| FlipFlop
@einarwh
einarwh / aoc19.fsx
Last active December 19, 2023 20:39
Advent of Code 2023 - Day 19: Aplenty - F# version
// Advent of Code 2023. Day 19: Aplenty
// dotnet fsi aoc19.fsx
open System
open System.IO
open System.Text.RegularExpressions
type Part = {
x : int
m : int
@einarwh
einarwh / aoc18.fsx
Created December 19, 2023 18:43
Advent of Code 2023 - Day 18: Lavaduct Lagoon - F# version
// Advent of Code 2023. Day 18: Lavaduct Lagoon
// dotnet fsi aoc18.fsx
open System
open System.IO
type Direction = U | D | L | R
type Pos = { x : int64; y : int64 }
@einarwh
einarwh / aoc17.fsx
Last active December 17, 2023 13:14
Advent of Code 2023 - Day 17: Clumsy Crucible - F# version
// Advent of Code 2023. Day 17: Clumsy Crucible
// dotnet fsi aoc17.fsx
open System
open System.IO
open System.Collections.Generic
module Array2D =
let getRowCount (ary : 'a[,]) = ary.GetLength(0)
let getColumnCount (ary : 'a[,]) = ary.GetLength(1)
@einarwh
einarwh / aoc16.fsx
Last active December 16, 2023 11:17
Advent of Code 2023 - Day 16: The Floor Will Be Lava - F# version
// Advent of Code 2023. Day 16: The Floor Will Be Lava
// dotnet fsi aoc16.fsx
open System
open System.IO
type Dir = N | W | S | E
module Array2D =
let getRowCount (ary : 'a[,]) = ary.GetLength(0)
@einarwh
einarwh / aoc15comp.fsx
Created December 15, 2023 09:34
Advent of Code 2023 - Day 15: Lens Library - F# version with function composition
// Advent of Code 2023. Day 15: Lens Library
// dotnet fsi aoc15.fsx
open System.IO
let readText fileName =
let text = File.ReadAllText fileName
text.TrimEnd()
let getHash s =
@einarwh
einarwh / aoc15.fsx
Last active December 15, 2023 08:23
Advent of Code 2023 - Day 15: Lens Library - F# version
// Advent of Code 2023. Day 15: Lens Library
// dotnet fsi aoc15.fsx
open System.IO
type Op =
| Insert of (string * int)
| Remove of string
let readText fileName =
// Advent of Code 2023. Day 14: Parabolic Reflector Dish
// dotnet fsi aoc14.fsx
open System
open System.IO
module Array2D =
let getRowCount (ary : 'a[,]) = ary.GetLength(0)