diff options
author | alyx <alyx@aleteoryx.me> | 2023-11-19 14:55:43 -0500 |
---|---|---|
committer | alyx <alyx@aleteoryx.me> | 2023-11-19 14:55:43 -0500 |
commit | 2d12f6ec2294e36ae090fdd1e10025452ec1a480 (patch) | |
tree | 9467466f8fb7daba9d76a6a956931eba51b5d865 /2015/rs/src/two.rs | |
download | adventofcode-2d12f6ec2294e36ae090fdd1e10025452ec1a480.tar.gz adventofcode-2d12f6ec2294e36ae090fdd1e10025452ec1a480.tar.bz2 adventofcode-2d12f6ec2294e36ae090fdd1e10025452ec1a480.zip |
Initial commit, done up to 2015.7
Diffstat (limited to '2015/rs/src/two.rs')
-rw-r--r-- | 2015/rs/src/two.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/2015/rs/src/two.rs b/2015/rs/src/two.rs new file mode 100644 index 0000000..572c556 --- /dev/null +++ b/2015/rs/src/two.rs @@ -0,0 +1,31 @@ +static INPUT: &'static str = include_str!("two.txt"); + +fn main() { + let valueified = INPUT + .split('\n') + .filter(|s| !s.is_empty()) + .map(|line| { + let mut nums = line + .split('x') + .map(str::parse::<u32>) + .map(Result::unwrap); + (nums.next().unwrap(), nums.next().unwrap(), nums.next().unwrap()) + }); + + let final_area: u32 = valueified.clone() + .map(|(w, l, h)| { + let sides = [w*h, l*w, h*l]; + sides.into_iter().min().unwrap() + sides.into_iter().sum::<u32>() * 2 + }) + .sum(); + println!("Final area: {final_area}"); + + let ribbon_length: u32 = valueified + .map(|(w, l, h)| { + let mut nums = [w, l, h]; + nums.sort(); + (nums[0] + nums[1]) * 2 + (w * l * h) + }) + .sum(); + println!("Ribbon length: {ribbon_length}"); +} |