2025 day 1
This commit is contained in:
parent
902917426f
commit
9caa01f1a7
6 changed files with 4570 additions and 26 deletions
17
.envrc
17
.envrc
|
|
@ -1,22 +1,5 @@
|
||||||
#!/bin/bash
|
#!/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
|
watch_file .env.local
|
||||||
dotenv_if_exists .env.local
|
dotenv_if_exists .env.local
|
||||||
|
|
||||||
|
|
|
||||||
44
2025/day_1.nix
Normal file
44
2025/day_1.nix
Normal 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
10
2025/puzzle_cache/day_1_0
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
4503
2025/puzzle_cache/day_1_1
Normal file
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
4
2025/utils.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
toIntBase10 = str: builtins.fromJSON "${str}";
|
||||||
|
mod = a: b: a - b * (builtins.floor (a / b));
|
||||||
|
}
|
||||||
18
flake.lock
generated
18
flake.lock
generated
|
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nix-filter": {
|
"nix-filter": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1731533336,
|
"lastModified": 1757882181,
|
||||||
"narHash": "sha256-oRam5PS1vcrr5UPgALW0eo1m/5/pls27Z/pabHNy2Ms=",
|
"narHash": "sha256-+cCxYIh2UNalTz364p+QYmWHs0P+6wDhiWR4jDIKQIU=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "nix-filter",
|
"repo": "nix-filter",
|
||||||
"rev": "f7653272fd234696ae94229839a99b73c9ab7de0",
|
"rev": "59c44d1909c72441144b93cf0f054be7fe764de5",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -17,11 +17,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1733581040,
|
"lastModified": 1764950072,
|
||||||
"narHash": "sha256-Qn3nPMSopRQJgmvHzVqPcE3I03zJyl8cSbgnnltfFDY=",
|
"narHash": "sha256-BmPWzogsG2GsXZtlT+MTcAWeDK5hkbGRZTeZNW42fwA=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "22c3f2cf41a0e70184334a958e6b124fb0ce3e01",
|
"rev": "f61125a668a320878494449750330ca58b78c557",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -45,11 +45,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1733625333,
|
"lastModified": 1765161692,
|
||||||
"narHash": "sha256-tIML2axjm4AnlKP29upVJxzBpj4Cy4ak+PKonqQtXmc=",
|
"narHash": "sha256-XdY9AFzmgRPYIhP4N+WiCHMNxPoifP5/Ld+orMYBD8c=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"rev": "430c8b054e45ea44fd2c9521a378306ada507a6c",
|
"rev": "7ed7e8c74be95906275805db68201e74e9904f07",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue