Advent of Code solutions
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Start Year 2025, done day 1

Ben C 9eaca333 4922020e

+341 -37
+10
Cargo.lock
··· 9 9 "advent_core", 10 10 "macros", 11 11 "y_2024", 12 + "y_2025", 12 13 ] 13 14 14 15 [[package]] ··· 330 331 "regex", 331 332 "utils", 332 333 ] 334 + 335 + [[package]] 336 + name = "y_2025" 337 + version = "0.1.0" 338 + dependencies = [ 339 + "advent_core", 340 + "macros", 341 + "utils", 342 + ]
+1
Cargo.toml
··· 15 15 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 16 16 17 17 [dependencies] 18 + y_2025 = { path = "years/2025" } 18 19 y_2024 = { path = "years/2024" } 19 20 advent_core = { path = "advent_core" } 20 21 macros = { path = "macros" }
+1 -1
advent_core/src/bootstrap.rs
··· 39 39 [package] 40 40 name = \"y_{year}\" 41 41 version = \"0.1.0\" 42 - edition = \"2021\" 42 + edition = \"2024\" 43 43 44 44 [dependencies] 45 45 advent_core = { path = \"../../advent_core\" }
+1 -1
advent_core/src/lib.rs
··· 7 7 8 8 pub use bootstrap::make_year; 9 9 pub use day::Day; 10 - pub use parser::{get_dp_and_input, get_ydp_and_input, Selection, DP, YDP}; 10 + pub use parser::{DP, Selection, YDP, get_dp_and_input, get_ydp_and_input}; 11 11 pub use year::Year;
+1 -1
advent_core/src/parser.rs
··· 1 1 use std::env::args; 2 2 use std::fs; 3 - use std::io::{stdin, Read}; 3 + use std::io::{Read, stdin}; 4 4 5 5 #[derive(Clone, Debug)] 6 6 pub enum Selection {
+1 -1
advent_core/src/year.rs
··· 1 - use crate::parser::{Selection, DP}; 1 + use crate::parser::{DP, Selection}; 2 2 3 3 use super::MAX_DAY; 4 4
+8 -8
justfile
··· 6 6 day := `nu -c 'date now | format date "%_d" | str trim'` 7 7 8 8 # Run a specific part of today's problem 9 - p P in="": 10 - cargo run --release -- solve {{year}}:{{day}}:{{P}} {{in}} 9 + p P in="" ARGS="": 10 + cargo run {{ARGS}} -- solve {{year}}:{{day}}:{{P}} {{in}} 11 11 12 12 # Run a specific day and part of this year 13 - dp DP in="": 14 - cargo run --release -- solve {{year}}:{{DP}} {{in}} 13 + dp DP in="" ARGS="": 14 + cargo run {{ARGS}} -- solve {{year}}:{{DP}} {{in}} 15 15 16 16 # Run a specific year's day's part 17 - dyp DYP in="": 18 - cargo run --release -- solve {{DYP}} {{in}} 17 + dyp DYP in="" ARGS="": 18 + cargo run {{ARGS}} -- solve {{DYP}} {{in}} 19 19 20 20 # Create a new year crate 21 21 prep: ··· 29 29 test-all: 30 30 cargo test -p y_{{year}} --release 31 31 32 - # Open VSCodium to today's file 32 + # Open Editor to today's file 33 33 start: 34 - codium . --goto years/{{year}}/src/day_{{day}}.rs 34 + nvim years/{{year}}/src/day_{{day}}.rs
+24 -24
macros/src/lib.rs
··· 1 1 extern crate proc_macro; 2 2 3 - use advent_core::MAX_DAY; 4 - 5 3 use proc_macro::TokenStream; 6 4 7 - fn make_day_mods() -> String { 8 - (1..=MAX_DAY) 5 + fn make_day_mods(days: usize) -> String { 6 + (1..=days) 9 7 .map(|day| format!("pub mod day_{day};", day = day)) 10 8 .collect::<Vec<_>>() 11 9 .join("\n") 12 10 } 13 11 14 - fn make_use_days() -> String { 15 - (1..=MAX_DAY) 12 + fn make_use_days(days: usize) -> String { 13 + (1..=days) 16 14 .map(|day| format!("use day_{day}::Day{day};", day = day)) 17 15 .collect::<Vec<_>>() 18 16 .join("\n") 19 17 } 20 18 21 - fn make_day_match(inner: &str) -> String { 22 - (1..=MAX_DAY) 19 + fn make_day_match(inner: &str, days: usize) -> String { 20 + (1..=days) 23 21 .map(|day| format!("{day} => {},", inner.replace("{day}", &day.to_string()))) 24 22 .collect::<Vec<_>>() 25 23 .join("\n") 26 24 } 27 25 28 - fn make_day_tests() -> String { 29 - (1..=MAX_DAY) 26 + fn make_day_tests(days: usize) -> String { 27 + (1..=days) 30 28 .map(|day| { 31 29 format!( 32 30 " ··· 45 43 .join("\n") 46 44 } 47 45 48 - fn get_solve_day() -> String { 49 - let inner = make_day_match("Day{day}::run_part(part, input)"); 50 - let inner2 = make_day_match("{Day{day}::bench_part(part, input);}"); 46 + fn get_solve_day(days: usize) -> String { 47 + let inner = make_day_match("Day{day}::run_part(part, input)", days); 48 + let inner2 = make_day_match("{Day{day}::bench_part(part, input);}", days); 51 49 format!( 52 50 " 53 51 fn solve_day(day: usize, part: usize, input: Option<&str>) -> Option<String> {{ ··· 65 63 ) 66 64 } 67 65 68 - fn get_solve_day_both_parts() -> String { 69 - let inner = make_day_match("Day{day}::run_all_parts(extra_indent)"); 66 + fn get_solve_day_both_parts(days: usize) -> String { 67 + let inner = make_day_match("Day{day}::run_all_parts(extra_indent)", days); 70 68 format!( 71 69 " 72 70 fn solve_day_both_parts(day: usize, extra_indent: &str) {{ ··· 79 77 ) 80 78 } 81 79 82 - fn make_year_struct(year: &str) -> String { 80 + fn make_year_struct(year: &str, days: usize) -> String { 83 81 format!( 84 82 " 85 83 pub struct Year{year}; ··· 91 89 92 90 {solve_day_both_parts} 93 91 }}", 94 - solve_day = get_solve_day(), 95 - solve_day_both_parts = get_solve_day_both_parts() 92 + solve_day = get_solve_day(days), 93 + solve_day_both_parts = get_solve_day_both_parts(days) 96 94 ) 97 95 } 98 96 99 - fn make_tests() -> String { 97 + fn make_tests(days: usize) -> String { 100 98 format!( 101 99 " 102 100 #[cfg(test)] ··· 106 104 107 105 {day_tests} 108 106 }}", 109 - day_tests = make_day_tests() 107 + day_tests = make_day_tests(days) 110 108 ) 111 109 } 112 110 ··· 114 112 pub fn year(item: TokenStream) -> TokenStream { 115 113 let year = item.to_string(); 116 114 117 - let mods = make_day_mods(); 118 - let uses = make_use_days(); 115 + let days = if year == "2024" { 25 } else { 12 }; 119 116 120 - let year_struct = make_year_struct(&year); 117 + let mods = make_day_mods(days); 118 + let uses = make_use_days(days); 121 119 122 - let tests = make_tests(); 120 + let year_struct = make_year_struct(&year, days); 121 + 122 + let tests = make_tests(days); 123 123 124 124 format!( 125 125 "
+1 -1
src/main.rs
··· 1 1 use advent_core::{get_ydp_and_input, make_year, Selection, Year, DP, YDP}; 2 2 use macros::global_runner; 3 3 4 - global_runner!(2024); 4 + global_runner!(2024, 2025); 5 5 6 6 fn run_ydp(ydp: YDP, input: Option<String>) { 7 7 let dp = ydp.to_dp();
+10
years/2025/Cargo.toml
··· 1 + 2 + [package] 3 + name = "y_2025" 4 + version = "0.1.0" 5 + edition = "2024" 6 + 7 + [dependencies] 8 + advent_core = { path = "../../advent_core" } 9 + macros = { path = "../../macros" } 10 + utils = { path = "../../utils" }
+70
years/2025/src/day_1.rs
··· 1 + use advent_core::{Day, day_stuff, ex_for_day}; 2 + 3 + pub struct Day1; 4 + 5 + #[derive(Debug, Clone, PartialEq, Eq)] 6 + pub enum Dir { 7 + Left, 8 + Right, 9 + } 10 + 11 + #[derive(Clone, Debug)] 12 + pub struct Rot { 13 + dir: Dir, 14 + amnt: isize, 15 + } 16 + 17 + impl Day for Day1 { 18 + fn part_1(input: Self::Input) -> Option<String> { 19 + let mut curr = 50; 20 + let mut at_0 = 0; 21 + for rot in input { 22 + let amnt = if rot.dir == Dir::Left { 23 + -rot.amnt 24 + } else { 25 + rot.amnt 26 + }; 27 + curr = (curr + amnt).rem_euclid(100); 28 + if curr == 0 { 29 + at_0 += 1; 30 + } 31 + } 32 + 33 + Some(at_0.to_string()) 34 + } 35 + 36 + fn part_2(input: Self::Input) -> Option<String> { 37 + let mut curr = 50; 38 + let mut at_0 = 0; 39 + for rot in input { 40 + let amnt = if rot.dir == Dir::Left { 41 + -rot.amnt 42 + } else { 43 + rot.amnt 44 + }; 45 + at_0 += if rot.dir == Dir::Right { 46 + (curr + rot.amnt) / 100 47 + } else { 48 + (if curr == 0 { 0 } else { 100 - curr } + rot.amnt) / 100 49 + }; 50 + curr = (curr + amnt).rem_euclid(100); 51 + } 52 + 53 + Some(at_0.to_string()) 54 + } 55 + 56 + day_stuff!(1, "3", "6", Vec<Rot>); 57 + 58 + fn parse_input(input: &str) -> Self::Input { 59 + input 60 + .lines() 61 + .map(|l| { 62 + let (dir, amnt) = l.split_at(1); 63 + Rot { 64 + dir: if dir == "L" { Dir::Left } else { Dir::Right }, 65 + amnt: amnt.parse().unwrap(), 66 + } 67 + }) 68 + .collect() 69 + } 70 + }
+17
years/2025/src/day_10.rs
··· 1 + 2 + use advent_core::{Day, day_stuff, ex_for_day}; 3 + 4 + pub struct Day10; 5 + 6 + impl Day for Day10 { 7 + 8 + day_stuff!(10, "", ""); 9 + 10 + fn part_1(_input: Self::Input) -> Option<String> { 11 + None 12 + } 13 + 14 + fn part_2(_input: Self::Input) -> Option<String> { 15 + None 16 + } 17 + }
+17
years/2025/src/day_11.rs
··· 1 + 2 + use advent_core::{Day, day_stuff, ex_for_day}; 3 + 4 + pub struct Day11; 5 + 6 + impl Day for Day11 { 7 + 8 + day_stuff!(11, "", ""); 9 + 10 + fn part_1(_input: Self::Input) -> Option<String> { 11 + None 12 + } 13 + 14 + fn part_2(_input: Self::Input) -> Option<String> { 15 + None 16 + } 17 + }
+17
years/2025/src/day_12.rs
··· 1 + 2 + use advent_core::{Day, day_stuff, ex_for_day}; 3 + 4 + pub struct Day12; 5 + 6 + impl Day for Day12 { 7 + 8 + day_stuff!(12, "", ""); 9 + 10 + fn part_1(_input: Self::Input) -> Option<String> { 11 + None 12 + } 13 + 14 + fn part_2(_input: Self::Input) -> Option<String> { 15 + None 16 + } 17 + }
+17
years/2025/src/day_2.rs
··· 1 + 2 + use advent_core::{Day, day_stuff, ex_for_day}; 3 + 4 + pub struct Day2; 5 + 6 + impl Day for Day2 { 7 + 8 + day_stuff!(2, "", ""); 9 + 10 + fn part_1(_input: Self::Input) -> Option<String> { 11 + None 12 + } 13 + 14 + fn part_2(_input: Self::Input) -> Option<String> { 15 + None 16 + } 17 + }
+17
years/2025/src/day_3.rs
··· 1 + 2 + use advent_core::{Day, day_stuff, ex_for_day}; 3 + 4 + pub struct Day3; 5 + 6 + impl Day for Day3 { 7 + 8 + day_stuff!(3, "", ""); 9 + 10 + fn part_1(_input: Self::Input) -> Option<String> { 11 + None 12 + } 13 + 14 + fn part_2(_input: Self::Input) -> Option<String> { 15 + None 16 + } 17 + }
+17
years/2025/src/day_4.rs
··· 1 + 2 + use advent_core::{Day, day_stuff, ex_for_day}; 3 + 4 + pub struct Day4; 5 + 6 + impl Day for Day4 { 7 + 8 + day_stuff!(4, "", ""); 9 + 10 + fn part_1(_input: Self::Input) -> Option<String> { 11 + None 12 + } 13 + 14 + fn part_2(_input: Self::Input) -> Option<String> { 15 + None 16 + } 17 + }
+17
years/2025/src/day_5.rs
··· 1 + 2 + use advent_core::{Day, day_stuff, ex_for_day}; 3 + 4 + pub struct Day5; 5 + 6 + impl Day for Day5 { 7 + 8 + day_stuff!(5, "", ""); 9 + 10 + fn part_1(_input: Self::Input) -> Option<String> { 11 + None 12 + } 13 + 14 + fn part_2(_input: Self::Input) -> Option<String> { 15 + None 16 + } 17 + }
+17
years/2025/src/day_6.rs
··· 1 + 2 + use advent_core::{Day, day_stuff, ex_for_day}; 3 + 4 + pub struct Day6; 5 + 6 + impl Day for Day6 { 7 + 8 + day_stuff!(6, "", ""); 9 + 10 + fn part_1(_input: Self::Input) -> Option<String> { 11 + None 12 + } 13 + 14 + fn part_2(_input: Self::Input) -> Option<String> { 15 + None 16 + } 17 + }
+17
years/2025/src/day_7.rs
··· 1 + 2 + use advent_core::{Day, day_stuff, ex_for_day}; 3 + 4 + pub struct Day7; 5 + 6 + impl Day for Day7 { 7 + 8 + day_stuff!(7, "", ""); 9 + 10 + fn part_1(_input: Self::Input) -> Option<String> { 11 + None 12 + } 13 + 14 + fn part_2(_input: Self::Input) -> Option<String> { 15 + None 16 + } 17 + }
+17
years/2025/src/day_8.rs
··· 1 + 2 + use advent_core::{Day, day_stuff, ex_for_day}; 3 + 4 + pub struct Day8; 5 + 6 + impl Day for Day8 { 7 + 8 + day_stuff!(8, "", ""); 9 + 10 + fn part_1(_input: Self::Input) -> Option<String> { 11 + None 12 + } 13 + 14 + fn part_2(_input: Self::Input) -> Option<String> { 15 + None 16 + } 17 + }
+17
years/2025/src/day_9.rs
··· 1 + 2 + use advent_core::{Day, day_stuff, ex_for_day}; 3 + 4 + pub struct Day9; 5 + 6 + impl Day for Day9 { 7 + 8 + day_stuff!(9, "", ""); 9 + 10 + fn part_1(_input: Self::Input) -> Option<String> { 11 + None 12 + } 13 + 14 + fn part_2(_input: Self::Input) -> Option<String> { 15 + None 16 + } 17 + }
+10
years/2025/src/examples/day_1/1.txt
··· 1 + L68 2 + L30 3 + R48 4 + L5 5 + R60 6 + L55 7 + L1 8 + L99 9 + R14 10 + L82
+10
years/2025/src/examples/day_1/2.txt
··· 1 + L68 2 + L30 3 + R48 4 + L5 5 + R60 6 + L55 7 + L1 8 + L99 9 + R14 10 + L82
years/2025/src/examples/day_10/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_10/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_11/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_11/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_12/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_12/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_13/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_13/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_14/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_14/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_15/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_15/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_16/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_16/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_17/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_17/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_18/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_18/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_19/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_19/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_2/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_2/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_20/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_20/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_21/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_21/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_22/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_22/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_23/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_23/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_24/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_24/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_25/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_25/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_3/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_3/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_4/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_4/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_5/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_5/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_6/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_6/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_7/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_7/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_8/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_8/2.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_9/1.txt

This is a binary file and will not be displayed.

years/2025/src/examples/day_9/2.txt

This is a binary file and will not be displayed.

+3
years/2025/src/lib.rs
··· 1 + use macros::year; 2 + 3 + year!(2025);
+3
years/2025/src/main.rs
··· 1 + use macros::year_runner; 2 + 3 + year_runner!(2025);