Skip to content

Instantly share code, notes, and snippets.

@einarwh
einarwh / aoc01a.html
Created December 7, 2023 01:20
Advent of Code 2023 - Day 1: Trebuchet?! - Part 1 - 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 / aoc06.fsx
Last active December 6, 2023 16:16
Advent of Code 2023 - Day 6: Wait For It - F# version
// Advent of Code 2023. Day 6: Wait For It
// dotnet fsi aoc06.fsx
open System
open System.IO
open System.Text.RegularExpressions
let parse (s : string) : string list =
Regex.Matches(s, "\d+")
|> Seq.map (fun m -> m.Value)
@einarwh
einarwh / aoc05.fsx
Last active December 5, 2023 11:19
Advent of Code 2023 - Day 5: If You Give A Seed A Fertilizer - F# version
// Advent of Code 2023. Day 5: If You Give A Seed A Fertilizer
// dotnet fsi aoc05.fsx
open System.IO
open System.Text.RegularExpressions
let parseNumbers (s : string) : int64 list =
Regex.Matches(s, "\d+")
|> Seq.map (fun m -> int64 m.Value)
|> Seq.toList
@einarwh
einarwh / aoc04.fsx
Last active December 4, 2023 19:43
Advent of Code 2023 - Day 4: Scratchcards - F# version
// Advent of Code 2023. Day 4: Scratchcards
// dotnet fsi aoc04.fsx
open System
open System.IO
open System.Text.RegularExpressions
let parseCard (line : string) : int =
let folder (seen, dups) x =
if List.contains x seen then (seen, x :: dups) else (x :: seen, dups)
@einarwh
einarwh / aoc03.fsx
Last active December 3, 2023 23:53
Advent of Code 2023 - Day 3: Gear Ratios - F# version
// Advent of Code 2023. Day 3: Gear Ratios
// dotnet fsi aoc03.fsx
open System
open System.IO
open System.Text.RegularExpressions
type Box = {
xMin : int
yMin : int
@einarwh
einarwh / aoc02.ps
Last active December 4, 2023 15:27
Advent of Code 2023 - Day 2: Cube Conundrum - PostScript version
% Advent of Code 2023. Day 2: Cube Conundrum
% gs -DNOSAFER aoc02.ps
/read-input
{ % fn
[ % fn [
exch % [ fn
(r) file % [ F
{
dup % [ .. F F
@einarwh
einarwh / aoc02.fsx
Created December 2, 2023 09:06
Advent of Code 2023 - Day 2: Cube Conundrum - F# version
// Advent of Code 2023. Day 1: Cube Conundrum
// dotnet fsi aoc02.fsx
open System
open System.IO
open System.Text.RegularExpressions
let getCount (m : Match) : int =
m.Groups[1].Value |> int
@einarwh
einarwh / aoc01.ps
Last active December 1, 2023 17:39
Advent of Code 2023 - Day 1: Trebuchet?! - PostScript version
% Advent of Code 2023. Day 1: Trebuchet?!
% gs -DNOSAFER aoc01.ps
/read-input
{ % fn
[ % fn [
exch % [ fn
(r) file % [ F
{
dup % [ .. F F
@einarwh
einarwh / aoc01.tcl
Last active December 1, 2023 17:40
Advent of Code 2023 - Day 1: Trebuchet?! - tcl version
# Advent of Code 2023. Day 1: Trebuchet?!
# tclsh aoc01.tcl
set fp [open "input" r]
set fileData [read $fp]
close $fp
proc toNumber {numbers} {
set result 0
if {[llength $numbers] > 0} {
@einarwh
einarwh / ASIMOV.BAS
Last active March 6, 2023 17:15
"Aftermath of the Asimovian Disaster" from "Creating Adventure Games On Your Computer" by Tim Hartnell - for Applesoft BASIC.
10 REM AFTERMATH OF THE ASIMOVIAN DISASTER
20 GOSUB 2600:REM INITIALISE
30 GOSUB 160
35 IF RO=13 THEN QQ=QQ+1:IF QQ=2 THEN 1385
40 GOTO 30
150 REM **************************
160 REM MAJOR HANDLING ROUTINE
170 STRENGTH = STRENGTH - 5
180 IF STRENGTH<10 THEN PRINT "WARNING, CAPTAIN ";N$;", YOUR STRENGTH":PRINT " IS RUNNING LOW":PRINT" YOU NEED AN OXYGEN BOOST"
190 IF STRENGTH < 1 THEN 2300:REM DEATH