diff --git a/day17/Cargo.lock b/day17/Cargo.lock new file mode 100644 index 0000000..a17382d --- /dev/null +++ b/day17/Cargo.lock @@ -0,0 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "day17" +version = "0.1.0" +dependencies = [ + "itertools", +] + +[[package]] +name = "either" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" + +[[package]] +name = "itertools" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b4baf93f58d4425749ca49a51c50ebab072c5df6994d08fed93541c331481dc" +dependencies = [ + "either", +] diff --git a/day17/Cargo.toml b/day17/Cargo.toml new file mode 100644 index 0000000..ae23891 --- /dev/null +++ b/day17/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day17" +version = "0.1.0" +edition = "2024" + +[dependencies] +itertools = "0.15.0" + diff --git a/day17/input.txt b/day17/input.txt new file mode 100644 index 0000000..f796965 --- /dev/null +++ b/day17/input.txt @@ -0,0 +1,20 @@ +11 +30 +47 +31 +32 +36 +3 +1 +5 +3 +32 +36 +15 +11 +46 +26 +28 +1 +19 +3 diff --git a/day17/src/main.rs b/day17/src/main.rs new file mode 100644 index 0000000..ac77490 --- /dev/null +++ b/day17/src/main.rs @@ -0,0 +1,22 @@ +use itertools::Itertools; + +fn main() { + let data: Vec = std::fs::read_to_string("input.txt") + .unwrap() + .lines() + .map(|s| s.parse().unwrap()) + .collect(); + + let mut result = 0; + for i in 1..=20 { + let c = data + .iter() + .combinations(i) + .map(|c| c.iter().cloned().sum::()) + .filter(|s| *s == 150) + .count(); + result += c; + println!("{i} -> {c}"); + } + println!("{result}"); +}