My attempts to solve puzzles of Advent of Code
0
fork

Configure Feed

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

feat: prepare for 2023

- include year as input for solver
- couple of macros to create solution and call solution easily
- rearrange files year wise

+497 -96
+299
Cargo.lock
··· 3 3 version = 3 4 4 5 5 [[package]] 6 + name = "android-tzdata" 7 + version = "0.1.1" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" 10 + 11 + [[package]] 12 + name = "android_system_properties" 13 + version = "0.1.5" 14 + source = "registry+https://github.com/rust-lang/crates.io-index" 15 + checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" 16 + dependencies = [ 17 + "libc", 18 + ] 19 + 20 + [[package]] 6 21 name = "aoc" 7 22 version = "0.1.0" 8 23 dependencies = [ 24 + "chrono", 9 25 "indexmap", 10 26 "nom", 27 + "paste", 11 28 ] 12 29 13 30 [[package]] ··· 17 34 checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 18 35 19 36 [[package]] 37 + name = "bumpalo" 38 + version = "3.14.0" 39 + source = "registry+https://github.com/rust-lang/crates.io-index" 40 + checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" 41 + 42 + [[package]] 43 + name = "cc" 44 + version = "1.0.83" 45 + source = "registry+https://github.com/rust-lang/crates.io-index" 46 + checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" 47 + dependencies = [ 48 + "libc", 49 + ] 50 + 51 + [[package]] 52 + name = "cfg-if" 53 + version = "1.0.0" 54 + source = "registry+https://github.com/rust-lang/crates.io-index" 55 + checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 56 + 57 + [[package]] 58 + name = "chrono" 59 + version = "0.4.31" 60 + source = "registry+https://github.com/rust-lang/crates.io-index" 61 + checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" 62 + dependencies = [ 63 + "android-tzdata", 64 + "iana-time-zone", 65 + "js-sys", 66 + "num-traits", 67 + "serde", 68 + "wasm-bindgen", 69 + "windows-targets", 70 + ] 71 + 72 + [[package]] 73 + name = "core-foundation-sys" 74 + version = "0.8.4" 75 + source = "registry+https://github.com/rust-lang/crates.io-index" 76 + checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" 77 + 78 + [[package]] 20 79 name = "hashbrown" 21 80 version = "0.12.3" 22 81 source = "registry+https://github.com/rust-lang/crates.io-index" 23 82 checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" 24 83 25 84 [[package]] 85 + name = "iana-time-zone" 86 + version = "0.1.58" 87 + source = "registry+https://github.com/rust-lang/crates.io-index" 88 + checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" 89 + dependencies = [ 90 + "android_system_properties", 91 + "core-foundation-sys", 92 + "iana-time-zone-haiku", 93 + "js-sys", 94 + "wasm-bindgen", 95 + "windows-core", 96 + ] 97 + 98 + [[package]] 99 + name = "iana-time-zone-haiku" 100 + version = "0.1.2" 101 + source = "registry+https://github.com/rust-lang/crates.io-index" 102 + checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" 103 + dependencies = [ 104 + "cc", 105 + ] 106 + 107 + [[package]] 26 108 name = "indexmap" 27 109 version = "1.9.3" 28 110 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 33 115 ] 34 116 35 117 [[package]] 118 + name = "js-sys" 119 + version = "0.3.65" 120 + source = "registry+https://github.com/rust-lang/crates.io-index" 121 + checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" 122 + dependencies = [ 123 + "wasm-bindgen", 124 + ] 125 + 126 + [[package]] 127 + name = "libc" 128 + version = "0.2.149" 129 + source = "registry+https://github.com/rust-lang/crates.io-index" 130 + checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" 131 + 132 + [[package]] 133 + name = "log" 134 + version = "0.4.20" 135 + source = "registry+https://github.com/rust-lang/crates.io-index" 136 + checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" 137 + 138 + [[package]] 36 139 name = "memchr" 37 140 version = "2.6.4" 38 141 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 53 156 "memchr", 54 157 "minimal-lexical", 55 158 ] 159 + 160 + [[package]] 161 + name = "num-traits" 162 + version = "0.2.17" 163 + source = "registry+https://github.com/rust-lang/crates.io-index" 164 + checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" 165 + dependencies = [ 166 + "autocfg", 167 + ] 168 + 169 + [[package]] 170 + name = "once_cell" 171 + version = "1.18.0" 172 + source = "registry+https://github.com/rust-lang/crates.io-index" 173 + checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" 174 + 175 + [[package]] 176 + name = "paste" 177 + version = "1.0.14" 178 + source = "registry+https://github.com/rust-lang/crates.io-index" 179 + checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" 180 + 181 + [[package]] 182 + name = "proc-macro2" 183 + version = "1.0.69" 184 + source = "registry+https://github.com/rust-lang/crates.io-index" 185 + checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" 186 + dependencies = [ 187 + "unicode-ident", 188 + ] 189 + 190 + [[package]] 191 + name = "quote" 192 + version = "1.0.33" 193 + source = "registry+https://github.com/rust-lang/crates.io-index" 194 + checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" 195 + dependencies = [ 196 + "proc-macro2", 197 + ] 198 + 199 + [[package]] 200 + name = "serde" 201 + version = "1.0.190" 202 + source = "registry+https://github.com/rust-lang/crates.io-index" 203 + checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" 204 + dependencies = [ 205 + "serde_derive", 206 + ] 207 + 208 + [[package]] 209 + name = "serde_derive" 210 + version = "1.0.190" 211 + source = "registry+https://github.com/rust-lang/crates.io-index" 212 + checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" 213 + dependencies = [ 214 + "proc-macro2", 215 + "quote", 216 + "syn", 217 + ] 218 + 219 + [[package]] 220 + name = "syn" 221 + version = "2.0.38" 222 + source = "registry+https://github.com/rust-lang/crates.io-index" 223 + checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" 224 + dependencies = [ 225 + "proc-macro2", 226 + "quote", 227 + "unicode-ident", 228 + ] 229 + 230 + [[package]] 231 + name = "unicode-ident" 232 + version = "1.0.12" 233 + source = "registry+https://github.com/rust-lang/crates.io-index" 234 + checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 235 + 236 + [[package]] 237 + name = "wasm-bindgen" 238 + version = "0.2.88" 239 + source = "registry+https://github.com/rust-lang/crates.io-index" 240 + checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" 241 + dependencies = [ 242 + "cfg-if", 243 + "wasm-bindgen-macro", 244 + ] 245 + 246 + [[package]] 247 + name = "wasm-bindgen-backend" 248 + version = "0.2.88" 249 + source = "registry+https://github.com/rust-lang/crates.io-index" 250 + checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" 251 + dependencies = [ 252 + "bumpalo", 253 + "log", 254 + "once_cell", 255 + "proc-macro2", 256 + "quote", 257 + "syn", 258 + "wasm-bindgen-shared", 259 + ] 260 + 261 + [[package]] 262 + name = "wasm-bindgen-macro" 263 + version = "0.2.88" 264 + source = "registry+https://github.com/rust-lang/crates.io-index" 265 + checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" 266 + dependencies = [ 267 + "quote", 268 + "wasm-bindgen-macro-support", 269 + ] 270 + 271 + [[package]] 272 + name = "wasm-bindgen-macro-support" 273 + version = "0.2.88" 274 + source = "registry+https://github.com/rust-lang/crates.io-index" 275 + checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" 276 + dependencies = [ 277 + "proc-macro2", 278 + "quote", 279 + "syn", 280 + "wasm-bindgen-backend", 281 + "wasm-bindgen-shared", 282 + ] 283 + 284 + [[package]] 285 + name = "wasm-bindgen-shared" 286 + version = "0.2.88" 287 + source = "registry+https://github.com/rust-lang/crates.io-index" 288 + checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" 289 + 290 + [[package]] 291 + name = "windows-core" 292 + version = "0.51.1" 293 + source = "registry+https://github.com/rust-lang/crates.io-index" 294 + checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" 295 + dependencies = [ 296 + "windows-targets", 297 + ] 298 + 299 + [[package]] 300 + name = "windows-targets" 301 + version = "0.48.5" 302 + source = "registry+https://github.com/rust-lang/crates.io-index" 303 + checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" 304 + dependencies = [ 305 + "windows_aarch64_gnullvm", 306 + "windows_aarch64_msvc", 307 + "windows_i686_gnu", 308 + "windows_i686_msvc", 309 + "windows_x86_64_gnu", 310 + "windows_x86_64_gnullvm", 311 + "windows_x86_64_msvc", 312 + ] 313 + 314 + [[package]] 315 + name = "windows_aarch64_gnullvm" 316 + version = "0.48.5" 317 + source = "registry+https://github.com/rust-lang/crates.io-index" 318 + checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" 319 + 320 + [[package]] 321 + name = "windows_aarch64_msvc" 322 + version = "0.48.5" 323 + source = "registry+https://github.com/rust-lang/crates.io-index" 324 + checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" 325 + 326 + [[package]] 327 + name = "windows_i686_gnu" 328 + version = "0.48.5" 329 + source = "registry+https://github.com/rust-lang/crates.io-index" 330 + checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" 331 + 332 + [[package]] 333 + name = "windows_i686_msvc" 334 + version = "0.48.5" 335 + source = "registry+https://github.com/rust-lang/crates.io-index" 336 + checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" 337 + 338 + [[package]] 339 + name = "windows_x86_64_gnu" 340 + version = "0.48.5" 341 + source = "registry+https://github.com/rust-lang/crates.io-index" 342 + checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" 343 + 344 + [[package]] 345 + name = "windows_x86_64_gnullvm" 346 + version = "0.48.5" 347 + source = "registry+https://github.com/rust-lang/crates.io-index" 348 + checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" 349 + 350 + [[package]] 351 + name = "windows_x86_64_msvc" 352 + version = "0.48.5" 353 + source = "registry+https://github.com/rust-lang/crates.io-index" 354 + checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
+2
Cargo.toml
··· 11 11 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 12 12 13 13 [dependencies] 14 + chrono = { version = "0.4.31", features = ["serde"] } 14 15 indexmap = "1.9.2" 15 16 nom = "7" 17 + paste = "1.0.14"
data/day1.txt data/2022/day1.txt
data/day10.txt data/2022/day10.txt
data/day11.txt data/2022/day11.txt
data/day12.txt data/2022/day12.txt
data/day2.txt data/2022/day2.txt
data/day22.txt data/2022/day22.txt
data/day3.txt data/2022/day3.txt
data/day4.txt data/2022/day4.txt
data/day5.txt data/2022/day5.txt
data/day6.txt data/2022/day6.txt
data/day7.txt data/2022/day7.txt
data/day8.txt data/2022/day8.txt
data/day9.txt data/2022/day9.txt
+15 -8
src/lib/input.rs
··· 11 11 } 12 12 13 13 pub struct Day { 14 - _day: u8, 14 + day: u8, 15 + year: u16, 15 16 } 16 17 17 18 pub enum Part { ··· 23 24 24 25 impl Debug for Day { 25 26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 26 - f.write_str(&format!("{}", self._day)) 27 + f.write_str(&format!("{}", self.day)) 27 28 } 28 29 } 29 30 30 - impl TryFrom<u8> for Day { 31 + impl TryFrom<(u8, u16)> for Day { 31 32 type Error = &'static str; 32 - fn try_from(value: u8) -> Result<Self, Self::Error> { 33 - if (1..=25).contains(&value) { 34 - Ok(Day { _day: value }) 33 + fn try_from(value: (u8, u16)) -> Result<Self, Self::Error> { 34 + if (1..=25).contains(&value.0) { 35 + Ok(Day { 36 + day: value.0, 37 + year: value.1, 38 + }) 35 39 } else { 36 - Err("Day value should be between 1 and 25") 40 + Err("Day and Year values are invalid") 37 41 } 38 42 } 39 43 } ··· 68 72 // }; 69 73 70 74 // let data_file_path = PathBuf::new().join("data").join(&d).join(p); 71 - let data_file_path = PathBuf::new().join("data").join(format!("day{}.txt", day._day)); 75 + // let year = year.unwrap_or(chrono::Utc::now().year()); 76 + let data_file_path = PathBuf::new() 77 + .join("data") 78 + .join(format!("{}/day{}.txt", day.year, day.day)); 72 79 let data_file = File::open(&data_file_path) 73 80 .unwrap_or_else(|_| panic!("could not open data file {:?}", data_file_path.as_path())); 74 81 let buf_reader = BufReader::new(data_file);
+41
src/lib/mod.rs
··· 3 3 4 4 pub use input::*; 5 5 pub use solver::*; 6 + 7 + // proc macro to call the right method 8 + #[macro_export] 9 + macro_rules! solve { 10 + ($year:expr; $day:expr; $part:expr) => { 11 + paste::paste! { 12 + [<year_ $year>]::[<Day $day>]::[<solve_part $part>]() 13 + } 14 + }; 15 + } 16 + 17 + #[macro_export] 18 + macro_rules! create_solution { 19 + ( 20 + out_1 => $out1:ty; 21 + out_2 => $out2:ty; 22 + year => $year:expr; 23 + day => $day:expr; 24 + sol_1 => $sol1:expr; 25 + sol_2 => $sol2:expr; 26 + ) => { 27 + paste::paste! { 28 + impl Solver for [<Day $day>] { 29 + type OutputPart1 = $out1; 30 + type OutputPart2 = $out2; 31 + fn year() -> u16 { 32 + $year 33 + } 34 + fn day() -> u8 { 35 + $day 36 + } 37 + fn solution_part1(input: Input) -> Option<Self::OutputPart1> { 38 + $sol1(input) 39 + } 40 + fn solution_part2(input: Input) -> Option<Self::OutputPart2> { 41 + $sol2(input) 42 + } 43 + } 44 + } 45 + }; 46 + }
+2 -1
src/lib/solver.rs
··· 6 6 type OutputPart1: Debug; 7 7 type OutputPart2: Debug; 8 8 fn day() -> u8; 9 + fn year() -> u16; 9 10 fn input() -> Input { 10 - let day = Day::try_from(Self::day()).expect("could not parse day"); 11 + let day = Day::try_from((Self::day(), Self::year())).expect("could not parse day"); 11 12 Input::new(day) 12 13 } 13 14 fn solution_part1(input: Input) -> Option<Self::OutputPart1>;
+3 -5
src/main.rs
··· 1 - use crate::solutions::year_2022::{ 2 - Day10, Day11, Day12, Day2, Day22, Day3, Day4, Day5, Day6, Day7, Day8, Day9, 3 - }; 4 - use aoc_lib::Solver; 1 + use crate::solutions::*; 2 + use aoc_lib::{solve, Solver}; 5 3 pub mod solutions; 6 4 7 5 fn main() { 8 - let sol = Day22::solve_part2(); 6 + let sol = solve!(2022; 1; 2); 9 7 println!("{:?}", sol); 10 8 }
+30 -12
src/solutions/year_2022/day1.rs
··· 1 - use aoc_lib::{Input, Solver}; 1 + use aoc_lib::{create_solution, Input, Solver}; 2 2 3 3 #[derive(Debug)] 4 4 pub(crate) struct Day1 {} ··· 20 20 } 21 21 } 22 22 23 - impl Solver for Day1 { 24 - type OutputPart1 = u32; 25 - type OutputPart2 = u32; 26 - fn day() -> u8 { 27 - 1 28 - } 29 - fn solution_part1(input: Input) -> Option<Self::OutputPart1> { 23 + // impl Solver for Day1 { 24 + // type OutputPart1 = u32; 25 + // type OutputPart2 = u32; 26 + // fn year() -> u16 { 27 + // 2022 28 + // } 29 + // fn day() -> u8 { 30 + // 1 31 + // } 32 + // fn solution_part1(input: Input) -> Option<Self::OutputPart1> { 33 + // let x = Day1::get_sorted(input); 34 + // x.first().copied() 35 + // } 36 + // fn solution_part2(input: Input) -> Option<Self::OutputPart2> { 37 + // let x = Day1::get_sorted(input); 38 + // x.split_at(3).0.iter().copied().reduce(|a, b| a + b) 39 + // } 40 + // } 41 + 42 + create_solution!( 43 + out_1 => u32; 44 + out_2 => u32; 45 + year => 2022; 46 + day => 1; 47 + sol_1 => |input: Input| { 30 48 let x = Day1::get_sorted(input); 31 49 x.first().copied() 32 - } 33 - fn solution_part2(input: Input) -> Option<Self::OutputPart2> { 50 + }; 51 + sol_2 => |input: Input| { 34 52 let x = Day1::get_sorted(input); 35 53 x.split_at(3).0.iter().copied().reduce(|a, b| a + b) 36 - } 37 - } 54 + }; 55 + );
+27 -25
src/solutions/year_2022/day10.rs
··· 20 20 } 21 21 22 22 impl Solver for Day10 { 23 - fn day() -> u8 { 24 - 10 25 - } 26 - fn solution_part1(input: aoc_lib::Input) -> Option<Self::OutputPart1> { 27 - let mut d = Day10::default(); 28 - d.load_instructions(input.lines.iter().map(Instruction::from), |_, _| {}); 23 + fn day() -> u8 { 24 + 10 25 + } 26 + fn year() -> u16 { 27 + 2022 28 + } 29 + fn solution_part1(input: aoc_lib::Input) -> Option<Self::OutputPart1> { 30 + let mut d = Day10::default(); 31 + d.load_instructions(input.lines.iter().map(Instruction::from), |_, _| {}); 29 32 30 - let s = [20, 60, 100, 140, 180, 220] 31 - .map(|i| (i, d.cycles[i - 1])) 32 - .iter() 33 - .map(|(n, (_, during, _))| *n as i32 * during) 34 - .sum::<i32>(); 35 - Some(s) 36 - } 33 + let s = [20, 60, 100, 140, 180, 220] 34 + .map(|i| (i, d.cycles[i - 1])) 35 + .iter() 36 + .map(|(n, (_, during, _))| *n as i32 * during) 37 + .sum::<i32>(); 38 + Some(s) 39 + } 37 40 38 - fn solution_part2(input: aoc_lib::Input) -> Option<Self::OutputPart2> { 39 - let mut crt = Crt::default(); 40 - let mut d = Day10::default(); 41 - d.load_instructions(input.lines.iter().map(Instruction::from), |x, y| { 42 - crt.handle_cyle(x, y); 43 - }); 41 + fn solution_part2(input: aoc_lib::Input) -> Option<Self::OutputPart2> { 42 + let mut crt = Crt::default(); 43 + let mut d = Day10::default(); 44 + d.load_instructions(input.lines.iter().map(Instruction::from), |x, y| { 45 + crt.handle_cyle(x, y); 46 + }); 44 47 45 - println!("{:?}", crt.clone()); 46 - Some(()) 47 - } 48 + println!("{:?}", crt.clone()); 49 + Some(()) 50 + } 48 51 49 - type OutputPart1 = i32; 50 - type OutputPart2 = (); 52 + type OutputPart1 = i32; 53 + type OutputPart2 = (); 51 54 } 52 55 53 56 impl From<PixelType> for usize { ··· 145 148 self 146 149 } 147 150 } 148 - 149 151 150 152 #[derive(Debug)] 151 153 enum Instruction {
+3
src/solutions/year_2022/day11.rs
··· 34 34 fn day() -> u8 { 35 35 11 36 36 } 37 + fn year() -> u16 { 38 + 2022 39 + } 37 40 type OutputPart1 = u128; 38 41 type OutputPart2 = u128; 39 42
+3
src/solutions/year_2022/day12.rs
··· 16 16 fn day() -> u8 { 17 17 12 18 18 } 19 + fn year() -> u16 { 20 + 2022 21 + } 19 22 type OutputPart1 = usize; 20 23 type OutputPart2 = usize; 21 24 fn solution_part1(input: aoc_lib::Input) -> Option<Self::OutputPart1> {
+3
src/solutions/year_2022/day2.rs
··· 167 167 impl Solver for Day2 { 168 168 type OutputPart1 = u32; 169 169 type OutputPart2 = u32; 170 + fn year() -> u16 { 171 + 2022 172 + } 170 173 fn day() -> u8 { 171 174 2 172 175 }
+3
src/solutions/year_2022/day22.rs
··· 68 68 fn day() -> u8 { 69 69 22 70 70 } 71 + fn year() -> u16 { 72 + 2022 73 + } 71 74 72 75 fn solution_part1(input: aoc_lib::Input) -> Option<Self::OutputPart1> { 73 76 let (mut board, commands) = Board::setup(input);
+3
src/solutions/year_2022/day3.rs
··· 30 30 impl Solver for Day3 { 31 31 type OutputPart1 = usize; 32 32 type OutputPart2 = usize; 33 + fn year() -> u16 { 34 + 2022 35 + } 33 36 34 37 fn day() -> u8 { 35 38 3
+3
src/solutions/year_2022/day4.rs
··· 46 46 impl Solver for Day4 { 47 47 type OutputPart1 = usize; 48 48 type OutputPart2 = usize; 49 + fn year() -> u16 { 50 + 2022 51 + } 49 52 50 53 fn day() -> u8 { 51 54 4
+3
src/solutions/year_2022/day5.rs
··· 140 140 impl Solver for Day5 { 141 141 type OutputPart1 = String; 142 142 type OutputPart2 = String; 143 + fn year() -> u16 { 144 + 2022 145 + } 143 146 144 147 fn day() -> u8 { 145 148 5
+3
src/solutions/year_2022/day6.rs
··· 66 66 fn solution_part2(input: aoc_lib::Input) -> Option<Self::OutputPart2> { 67 67 Some(Day6::new(14).common_sol(input).chars_processed) 68 68 } 69 + fn year() -> u16 { 70 + 2022 71 + } 69 72 fn day() -> u8 { 70 73 6 71 74 }
+3
src/solutions/year_2022/day7.rs
··· 15 15 fn day() -> u8 { 16 16 7 17 17 } 18 + fn year() -> u16 { 19 + 2022 20 + } 18 21 19 22 type OutputPart1 = u32; 20 23 type OutputPart2 = u32;
+40 -37
src/solutions/year_2022/day8.rs
··· 1 1 use aoc_lib::{Input, Solver}; 2 2 3 3 impl Solver for Day8 { 4 - fn day() -> u8 { 5 - 8 6 - } 4 + fn day() -> u8 { 5 + 8 6 + } 7 + fn year() -> u16 { 8 + 2022 9 + } 7 10 8 - fn solution_part1(input: Input) -> Option<Self::OutputPart1> { 9 - let count = Day8::new(input) 10 - .reduce_grid( 11 - |xs| { 12 - xs.iter() 13 - .map(|x| x.0) 14 - .reduce(|a, b| a || b) 15 - .unwrap_or(false) 16 - }, 17 - true, 18 - ) 19 - .iter() 20 - .filter(|x| **x) 21 - .count(); 11 + fn solution_part1(input: Input) -> Option<Self::OutputPart1> { 12 + let count = Day8::new(input) 13 + .reduce_grid( 14 + |xs| { 15 + xs.iter() 16 + .map(|x| x.0) 17 + .reduce(|a, b| a || b) 18 + .unwrap_or(false) 19 + }, 20 + true, 21 + ) 22 + .iter() 23 + .filter(|x| **x) 24 + .count(); 22 25 23 - Some(count) 24 - } 26 + Some(count) 27 + } 25 28 26 - fn solution_part2(input: Input) -> Option<Self::OutputPart2> { 27 - let count = Day8::new(input) 28 - .reduce_grid( 29 - |xs| { 30 - xs.iter() 31 - .map(|x| x.1.len()) 32 - .reduce(|a, b| a * b) 33 - .unwrap_or(1) 34 - }, 35 - 1, 36 - ) 37 - .iter() 38 - .copied() 39 - .max(); 29 + fn solution_part2(input: Input) -> Option<Self::OutputPart2> { 30 + let count = Day8::new(input) 31 + .reduce_grid( 32 + |xs| { 33 + xs.iter() 34 + .map(|x| x.1.len()) 35 + .reduce(|a, b| a * b) 36 + .unwrap_or(1) 37 + }, 38 + 1, 39 + ) 40 + .iter() 41 + .copied() 42 + .max(); 40 43 41 - count 42 - } 44 + count 45 + } 43 46 44 - type OutputPart1 = usize; 45 - type OutputPart2 = usize; 47 + type OutputPart1 = usize; 48 + type OutputPart2 = usize; 46 49 } 47 50 48 51 #[derive(Debug)]
+3
src/solutions/year_2022/day9.rs
··· 48 48 fn day() -> u8 { 49 49 9 50 50 } 51 + fn year() -> u16 { 52 + 2022 53 + } 51 54 52 55 type OutputPart1 = usize; 53 56 type OutputPart2 = usize;
+8 -8
src/solutions/year_2022/mod.rs
··· 1 1 mod day1; 2 + mod day10; 3 + mod day11; 4 + mod day12; 2 5 mod day2; 6 + mod day22; 3 7 mod day3; 4 8 mod day4; 5 9 mod day5; ··· 7 11 mod day7; 8 12 mod day8; 9 13 mod day9; 10 - mod day10; 11 - mod day11; 12 - mod day12; 13 - mod day22; 14 14 pub(crate) use day1::*; 15 + pub(crate) use day10::*; 16 + pub(crate) use day11::*; 17 + pub(crate) use day12::*; 15 18 pub(crate) use day2::*; 19 + pub(crate) use day22::*; 16 20 pub(crate) use day3::*; 17 21 pub(crate) use day4::*; 18 22 pub(crate) use day5::*; ··· 20 24 pub(crate) use day7::*; 21 25 pub(crate) use day8::*; 22 26 pub(crate) use day9::*; 23 - pub(crate) use day10::*; 24 - pub(crate) use day11::*; 25 - pub(crate) use day12::*; 26 - pub(crate) use day22::*;