2025 day 1

This commit is contained in:
RingOfStorms (Joshua Bell) 2025-12-08 13:49:42 -06:00
parent 902917426f
commit 9caa01f1a7
6 changed files with 4570 additions and 26 deletions

17
.envrc
View file

@ -1,22 +1,5 @@
#!/bin/bash
# Copy these to a .env.local file to override in local host
# This is what DIESEL cli uses
export DATABASE_URL="test_db.db"
## APP variables
# /etc/stormd/stormd.db
export STORMD_DB_PATH="stormd_db_local.db"
export STORMD_DB_ENC_KEY_FILE="stormd_db_enc.key"
# /etc/nebula/config.yml
export STORMD_NEBULA_CONFIG="nebula_config.yml"
# Auth key for admin API
export STORMD_NEXUS_ADMIN_AUTH_FILE="stormd_auth_key"
export STORMD_DAEMON_HTTP_PORT=37391
# ======
watch_file .env.local
dotenv_if_exists .env.local

44
2025/day_1.nix Normal file
View file

@ -0,0 +1,44 @@
# nix eval -f ./day_1.nix -I 'input=(builtins.readFile ./puzzle_cache/day_1_1)' countZero
{ input ? (builtins.readFile ./puzzle_cache/day_1_0) }:
let
utils = import ./utils.nix;
inherit (utils) toIntBase10 mod;
# Split into non-empty lines
lines = builtins.filter (s: builtins.isString s && s != "") (builtins.split "\n" input);
# Parse a line like "L68" or "R14"
parseLine = line: {
dir = builtins.substring 0 1 line;
dist = toIntBase10 (builtins.substring 1 (builtins.stringLength line - 1) line);
};
rotations = map parseLine lines;
# Fold over the list to simulate the dial
step =
state: rot:
let
position =
if rot.dir == "L" then
mod (state.position - rot.dist) 100
else if rot.dir == "R" then
mod (state.position + rot.dist) 100
else
builtins.trace "Invalid direction: ${rot.dir}" state.position;
countZero = state.countZero + (if position == 0 then 1 else 0);
in
{
inherit position countZero;
};
initialState = {
position = 50;
countZero = 0;
};
finalState = builtins.foldl' step initialState rotations;
in
{
inherit (finalState) position countZero;
}

10
2025/puzzle_cache/day_1_0 Normal file
View file

@ -0,0 +1,10 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82

4503
2025/puzzle_cache/day_1_1 Normal file

File diff suppressed because it is too large Load diff

4
2025/utils.nix Normal file
View file

@ -0,0 +1,4 @@
{
toIntBase10 = str: builtins.fromJSON "${str}";
mod = a: b: a - b * (builtins.floor (a / b));
}

18
flake.lock generated
View file

@ -2,11 +2,11 @@
"nodes": {
"nix-filter": {
"locked": {
"lastModified": 1731533336,
"narHash": "sha256-oRam5PS1vcrr5UPgALW0eo1m/5/pls27Z/pabHNy2Ms=",
"lastModified": 1757882181,
"narHash": "sha256-+cCxYIh2UNalTz364p+QYmWHs0P+6wDhiWR4jDIKQIU=",
"owner": "numtide",
"repo": "nix-filter",
"rev": "f7653272fd234696ae94229839a99b73c9ab7de0",
"rev": "59c44d1909c72441144b93cf0f054be7fe764de5",
"type": "github"
},
"original": {
@ -17,11 +17,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1733581040,
"narHash": "sha256-Qn3nPMSopRQJgmvHzVqPcE3I03zJyl8cSbgnnltfFDY=",
"lastModified": 1764950072,
"narHash": "sha256-BmPWzogsG2GsXZtlT+MTcAWeDK5hkbGRZTeZNW42fwA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "22c3f2cf41a0e70184334a958e6b124fb0ce3e01",
"rev": "f61125a668a320878494449750330ca58b78c557",
"type": "github"
},
"original": {
@ -45,11 +45,11 @@
]
},
"locked": {
"lastModified": 1733625333,
"narHash": "sha256-tIML2axjm4AnlKP29upVJxzBpj4Cy4ak+PKonqQtXmc=",
"lastModified": 1765161692,
"narHash": "sha256-XdY9AFzmgRPYIhP4N+WiCHMNxPoifP5/Ld+orMYBD8c=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "430c8b054e45ea44fd2c9521a378306ada507a6c",
"rev": "7ed7e8c74be95906275805db68201e74e9904f07",
"type": "github"
},
"original": {