From 331755f1cf89026c090515ed5daafd35fd9c9bc1 Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Mon, 1 Dec 2025 13:59:01 -0800 Subject: [PATCH] convert to aoc-runner and day1 solutions --- .gitignore | 4 +- 6/.gitignore | 1 - 6/Cargo.lock | 25 -- 6/Cargo.toml | 7 - 6/src/main.rs | 100 ------ Cargo.lock | 712 ++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 25 ++ boilerplate/src/main.rs | 66 ---- src/day1.rs | 60 ++++ src/day6.rs | 74 +++++ src/lib.rs | 6 + src/main.rs | 3 + 12 files changed, 883 insertions(+), 200 deletions(-) delete mode 100644 6/.gitignore delete mode 100644 6/Cargo.lock delete mode 100644 6/Cargo.toml delete mode 100644 6/src/main.rs create mode 100644 Cargo.lock create mode 100644 Cargo.toml delete mode 100644 boilerplate/src/main.rs create mode 100644 src/day1.rs create mode 100644 src/day6.rs create mode 100644 src/lib.rs create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore index 09ae99b..2ad0769 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ **/target input flamegraph.svg -perf.data +perf.data* guesses +.aoc_tiles/* +!.aoc_tiles/tiles/ diff --git a/6/.gitignore b/6/.gitignore deleted file mode 100644 index ea8c4bf..0000000 --- a/6/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target diff --git a/6/Cargo.lock b/6/Cargo.lock deleted file mode 100644 index e1fcce4..0000000 --- a/6/Cargo.lock +++ /dev/null @@ -1,25 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "day6" -version = "0.1.0" -dependencies = [ - "itertools", -] - -[[package]] -name = "either" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" - -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] diff --git a/6/Cargo.toml b/6/Cargo.toml deleted file mode 100644 index 31311b9..0000000 --- a/6/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "day6" -version = "0.1.0" -edition = "2021" - -[dependencies] -itertools = "0.13.0" diff --git a/6/src/main.rs b/6/src/main.rs deleted file mode 100644 index 8904373..0000000 --- a/6/src/main.rs +++ /dev/null @@ -1,100 +0,0 @@ -use itertools::Itertools; -use std::fs::File; -use std::io::{BufRead, BufReader, Lines}; -use std::time::{Duration, Instant}; - -// BOILERPLATE -type InputIter = Lines>; - -pub fn get_input() -> InputIter { - let f = File::open("input").unwrap(); - let br = BufReader::new(f); - br.lines() -} - -fn duration_format(duration: Duration) -> String { - match duration.as_secs_f64() { - x if x > 1.0 => format!("{:.3}s", x), - x if x > 0.010 => format!("{:.3}ms", x * 1e3), - x => format!("{:.3}us", x * 1e6), - } -} - -fn main() { - let input = get_input(); - let start = Instant::now(); - let ans1 = problem1(input); - let duration1 = start.elapsed(); - println!( - "Problem 1 solution: {} [{}]", - ans1, - duration_format(duration1) - ); - - let input = get_input(); - let start = Instant::now(); - let ans2 = problem2(input); - let duration2 = start.elapsed(); - println!( - "Problem 2 solution: {} [{}]", - ans2, - duration_format(duration2) - ); - println!("Total duration: {}", duration_format(duration1 + duration2)); -} - -// PROBLEM 1 solution - -fn problem1(mut input: Lines) -> u64 { - let s = input.next().unwrap().unwrap(); - s.as_bytes().windows(4).enumerate().find_map(|(i, window)| { - if window[1..4].iter().all(|c| *c != window[0]) && window[2..4].iter().all(|c| *c != window[1]) && window[2] != window[3] { - println!("Unique window: {:?} at {}", window.iter().map(|c| *c as char).collect_vec(), i); - Some(i + 4) - } else { - None - } - }).unwrap() as u64 -} - -// PROBLEM 2 solution -fn problem2(mut input: Lines) -> u64 { - let s = input.next().unwrap().unwrap(); - let size = 14; - s.as_bytes().windows(size).enumerate().find_map(|(i, window)| { - for i in 1..size { - let shifted = &window[i..]; - if shifted.iter().enumerate().any(|(j,c)| *c == window[j]) { - return None - } - } - return Some(i + 14) - }).unwrap() as u64 -} - -#[cfg(test)] -mod tests { - use crate::*; - use std::io::Cursor; - - const EXAMPLE1: &str = &"bvwbjplbgvbhsrlpgdmjqwftvncz"; - const EXAMPLE2: &str = &"nppdvjthqldpwncqszvftbrmjlhg"; - const EXAMPLE3: &str = &"nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg"; - const EXAMPLE4: &str = &"zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw"; - - #[test] - fn problem1_example() { - assert_eq!(problem1(Cursor::new(EXAMPLE1).lines()), 5); - assert_eq!(problem1(Cursor::new(EXAMPLE2).lines()), 6); - assert_eq!(problem1(Cursor::new(EXAMPLE3).lines()), 10); - assert_eq!(problem1(Cursor::new(EXAMPLE4).lines()), 11); - } - - #[test] - fn problem2_example() { - assert_eq!(problem2(Cursor::new(EXAMPLE1).lines()), 23); - assert_eq!(problem2(Cursor::new(EXAMPLE2).lines()), 23); - assert_eq!(problem2(Cursor::new(EXAMPLE3).lines()), 29); - assert_eq!(problem2(Cursor::new(EXAMPLE4).lines()), 26); - } -} diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..03982db --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,712 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "aoc-runner" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d21ef9204ad206a5a3e918e9920da04e1118ad91ce4f23570be964b9d6b9dfcb" + +[[package]] +name = "aoc-runner-derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba8b944269d3fee645d281b1335e1797044db497bb02d0098cc3fdb8900069cc" +dependencies = [ + "aoc-runner-internal", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "aoc-runner-internal" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "274b0ba7f3669a45ec0aaacf94eb032a749de880ab776091576cca94037c9982" +dependencies = [ + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "aoc2022" +version = "0.1.0" +dependencies = [ + "aoc-runner", + "aoc-runner-derive", + "atoi", + "bitflags", + "cached", + "colored", + "indicatif", + "itertools", + "lazy_static", + "nom", + "rayon", + "regex", + "rustc-hash", + "thread_local", +] + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" + +[[package]] +name = "bumpalo" +version = "3.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" + +[[package]] +name = "cached" +version = "0.54.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9718806c4a2fe9e8a56fd736f97b340dd10ed1be8ed733ed50449f351dc33cae" +dependencies = [ + "ahash", + "cached_proc_macro", + "cached_proc_macro_types", + "hashbrown", + "once_cell", + "thiserror", + "web-time", +] + +[[package]] +name = "cached_proc_macro" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f42a145ed2d10dce2191e1dcf30cfccfea9026660e143662ba5eec4017d5daa" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "cached_proc_macro_types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade8366b8bd5ba243f0a58f036cc0ca8a2f069cff1a2351ef1cac6b083e16fc0" + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "colored" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" +dependencies = [ + "lazy_static", + "windows-sys", +] + +[[package]] +name = "console" +version = "0.15.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "unicode-width", + "windows-sys", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "darling" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.111", +] + +[[package]] +name = "darling_macro" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indicatif" +version = "0.17.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235" +dependencies = [ + "console", + "number_prefix", + "portable-atomic", + "rayon", + "unicode-width", + "web-time", +] + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "js-sys" +version = "0.3.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.177" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "portable-atomic" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" + +[[package]] +name = "proc-macro2" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rayon" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "regex" +version = "1.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "serde_json" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", + "serde_core", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-bindgen" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.111", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2436a85 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "aoc2022" +edition = "2024" +version = "0.1.0" + +[dependencies] +aoc-runner = "0.3.0" +aoc-runner-derive = "0.3.0" +atoi = "2.0.0" +bitflags = "2.6.0" +cached = "0.54.0" +colored = "2.1.0" +indicatif = { version = "0.17.9", features = ["rayon"] } +itertools = "0.13.0" +lazy_static = "1.5.0" +nom = "7.1.3" +rayon = "1.10.0" +regex = "1.11.1" +rustc-hash = "2.1.0" +thread_local = "1.1.8" + +[profile.release] +lto = true +opt-level = 3 +overflow-checks = false diff --git a/boilerplate/src/main.rs b/boilerplate/src/main.rs deleted file mode 100644 index 657202a..0000000 --- a/boilerplate/src/main.rs +++ /dev/null @@ -1,66 +0,0 @@ -use std::fs::File; -use std::io::{BufRead, BufReader, Lines}; -use std::time::{Duration, Instant}; - -// BOILERPLATE -type InputIter = Lines>; - -pub fn get_input() -> InputIter { - let f = File::open("input").unwrap(); - let br = BufReader::new(f); - br.lines() -} - -fn duration_format(duration: Duration) -> String { - match duration.as_secs_f64() { - x if x > 1.0 => format!("{:.3}s", x), - x if x > 0.010 => format!("{:.3}ms", x * 1e3), - x => format!("{:.3}us", x * 1e6), - } -} - -fn main() { - let input = get_input(); - let start = Instant::now(); - let ans1 = problem1(input); - let duration1 = start.elapsed(); - println!("Problem 1 solution: {} [{}]", ans1, duration_format(duration1)); - - let input = get_input(); - let start = Instant::now(); - let ans2 = problem2(input); - let duration2 = start.elapsed(); - println!("Problem 2 solution: {} [{}]", ans2, duration_format(duration2)); - println!("Total duration: {}", duration_format(duration1 + duration2)); -} - -// PROBLEM 1 solution - -fn problem1(input: Lines) -> u64 { - 0 -} - -// PROBLEM 2 solution -fn problem2(input: Lines) -> u64 { - 0 -} - -#[cfg(test)] -mod tests { - use crate::*; - use std::io::Cursor; - - const EXAMPLE: &str = &""; - - #[test] - fn problem1_example() { - let c = Cursor::new(EXAMPLE); - assert_eq!(problem1(c.lines()), 0); - } - - #[test] - fn problem2_example() { - let c = Cursor::new(EXAMPLE); - assert_eq!(problem2(c.lines()), 0); - } -} diff --git a/src/day1.rs b/src/day1.rs new file mode 100644 index 0000000..1e7dafe --- /dev/null +++ b/src/day1.rs @@ -0,0 +1,60 @@ +use aoc_runner_derive::{aoc, aoc_generator}; +use itertools::Itertools; +use std::io::BufRead; + +#[aoc_generator(day1)] +// Sum the calories of each elf's food items +fn parse(input: &[u8]) -> Vec { + let mut result = Vec::new(); + let mut cur_elf = 0u64; + for line in input.lines() { + if let Ok(calories) = line.unwrap().parse::() { + cur_elf += calories + } else { + result.push(cur_elf); + cur_elf = 0 + } + } + result.push(cur_elf); + result +} + +#[aoc(day1, part1)] +fn part1(input: &Vec) -> u64 { + *input.iter().max().unwrap() +} + +#[aoc(day1, part2)] +fn part2(input: &Vec) -> u64 { + input.iter().sorted().rev().take(3).sum::() +} + +#[cfg(test)] +mod tests { + use super::*; + + const EXAMPLE: &[u8] = b"1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000"; + + #[test] + fn part1_example() { + assert_eq!(part1(&parse(EXAMPLE)), 24000); + } + + #[test] + fn part2_example() { + assert_eq!(part2(&parse(EXAMPLE)), 45000); + } +} diff --git a/src/day6.rs b/src/day6.rs new file mode 100644 index 0000000..37fa642 --- /dev/null +++ b/src/day6.rs @@ -0,0 +1,74 @@ +use aoc_runner_derive::aoc; +use itertools::Itertools; +use std::io::BufRead; + +// PROBLEM 1 solution +#[aoc(day6, part1)] +fn part1(input: &[u8]) -> u64 { + let s = input.lines().next().unwrap().unwrap(); + s.as_bytes() + .windows(4) + .enumerate() + .find_map(|(i, window)| { + if window[1..4].iter().all(|c| *c != window[0]) + && window[2..4].iter().all(|c| *c != window[1]) + && window[2] != window[3] + { + println!( + "Unique window: {:?} at {}", + window.iter().map(|c| *c as char).collect_vec(), + i + ); + Some(i + 4) + } else { + None + } + }) + .unwrap() as u64 +} + +// PROBLEM 2 solution +#[aoc(day6, part2)] +fn part2(input: &[u8]) -> u64 { + let s = input.lines().next().unwrap().unwrap(); + let size = 14; + s.as_bytes() + .windows(size) + .enumerate() + .find_map(|(i, window)| { + for i in 1..size { + let shifted = &window[i..]; + if shifted.iter().enumerate().any(|(j, c)| *c == window[j]) { + return None; + } + } + return Some(i + 14); + }) + .unwrap() as u64 +} + +#[cfg(test)] +mod tests { + use crate::day6::*; + + const EXAMPLE1: &[u8] = b"bvwbjplbgvbhsrlpgdmjqwftvncz"; + const EXAMPLE2: &[u8] = b"nppdvjthqldpwncqszvftbrmjlhg"; + const EXAMPLE3: &[u8] = b"nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg"; + const EXAMPLE4: &[u8] = b"zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw"; + + #[test] + fn problem1_example() { + assert_eq!(part1(EXAMPLE1), 5); + assert_eq!(part1(EXAMPLE2), 6); + assert_eq!(part1(EXAMPLE3), 10); + assert_eq!(part1(EXAMPLE4), 11); + } + + #[test] + fn problem2_example() { + assert_eq!(part2(EXAMPLE1), 23); + assert_eq!(part2(EXAMPLE2), 23); + assert_eq!(part2(EXAMPLE3), 29); + assert_eq!(part2(EXAMPLE4), 26); + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..8dee38d --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,6 @@ +mod day1; +use aoc_runner_derive::aoc_lib; + +pub mod day6; + +aoc_lib! { year = 2022 } diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..56b7caf --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +use aoc_runner_derive::aoc_main; + +aoc_main! { lib = aoc2022 }