From 6f58a357be42a76dc9aebfd9639b6327de4e5bab Mon Sep 17 00:00:00 2001 From: Burnus Date: Thu, 13 Apr 2023 05:50:46 +0200 Subject: [PATCH] Added Solution for 2020 day 18 --- 2020/day18_operation_order/Cargo.toml | 8 + 2020/day18_operation_order/challenge.txt | 79 ++++ 2020/day18_operation_order/src/lib.rs | 210 ++++++++++ .../tests/challenge_input | 377 ++++++++++++++++++ 2020/day18_operation_order/tests/sample_input | 5 + 5 files changed, 679 insertions(+) create mode 100644 2020/day18_operation_order/Cargo.toml create mode 100644 2020/day18_operation_order/challenge.txt create mode 100644 2020/day18_operation_order/src/lib.rs create mode 100644 2020/day18_operation_order/tests/challenge_input create mode 100644 2020/day18_operation_order/tests/sample_input diff --git a/2020/day18_operation_order/Cargo.toml b/2020/day18_operation_order/Cargo.toml new file mode 100644 index 0000000..49aa9f5 --- /dev/null +++ b/2020/day18_operation_order/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day18_operation_order" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2020/day18_operation_order/challenge.txt b/2020/day18_operation_order/challenge.txt new file mode 100644 index 0000000..cfed789 --- /dev/null +++ b/2020/day18_operation_order/challenge.txt @@ -0,0 +1,79 @@ +As you look out the window and notice a heavily-forested continent slowly appear over the horizon, you are interrupted by the child sitting next to you. They're curious if you could help them with their math homework. + +Unfortunately, it seems like this "math" [follows different rules](https://www.youtube.com/watch?v=3QtRK7Y2pPU&t=15) than you remember. + +The homework (your puzzle input) consists of a series of expressions that consist of addition (`+`), multiplication (`*`), and parentheses (`(...)`). Just like normal math, parentheses indicate that the expression inside must be evaluated before it can be used by the surrounding expression. Addition still finds the sum of the numbers on both sides of the operator, and multiplication still finds the product. + +However, the rules of *operator precedence* have changed. Rather than evaluating multiplication before addition, the operators have the *same precedence*, and are evaluated left-to-right regardless of the order in which they appear. + +For example, the steps to evaluate the expression `1 + 2 * 3 + 4 * 5 + 6` are as follows: + +``` +1 + 2 * 3 + 4 * 5 + 6 + 3 * 3 + 4 * 5 + 6 + 9 + 4 * 5 + 6 + 13 * 5 + 6 + 65 + 6 + 71 + +``` + +Parentheses can override this order; for example, here is what happens if parentheses are added to form `1 + (2 * 3) + (4 * (5 + 6))`: + +``` +1 + (2 * 3) + (4 * (5 + 6)) +1 + 6 + (4 * (5 + 6)) + 7 + (4 * (5 + 6)) + 7 + (4 * 11 ) + 7 + 44 + 51 + +``` + +Here are a few more examples: + +* `2 * 3 + (4 * 5)` becomes *`26`*. +* `5 + (8 * 3 + 9 + 3 * 4 * 3)` becomes *`437`*. +* `5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))` becomes *`12240`*. +* `((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2` becomes *`13632`*. + +Before you can help with the homework, you need to understand it yourself. *Evaluate the expression on each line of the homework; what is the sum of the resulting values?* + +Your puzzle answer was `24650385570008`. + +\--- Part Two --- +---------- + +You manage to answer the child's questions and they finish part 1 of their homework, but get stuck when they reach the next section: *advanced* math. + +Now, addition and multiplication have *different* precedence levels, but they're not the ones you're familiar with. Instead, addition is evaluated *before* multiplication. + +For example, the steps to evaluate the expression `1 + 2 * 3 + 4 * 5 + 6` are now as follows: + +``` +1 + 2 * 3 + 4 * 5 + 6 + 3 * 3 + 4 * 5 + 6 + 3 * 7 * 5 + 6 + 3 * 7 * 11 + 21 * 11 + 231 + +``` + +Here are the other examples from above: + +* `1 + (2 * 3) + (4 * (5 + 6))` still becomes *`51`*. +* `2 * 3 + (4 * 5)` becomes *`46`*. +* `5 + (8 * 3 + 9 + 3 * 4 * 3)` becomes *`1445`*. +* `5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))` becomes *`669060`*. +* `((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2` becomes *`23340`*. + +*What do you get if you add up the results of evaluating the homework problems using these new rules?* + +Your puzzle answer was `158183007916215`. + +Both parts of this puzzle are complete! They provide two gold stars: \*\* + +At this point, you should [return to your Advent calendar](/2020) and try another puzzle. + +If you still want to see it, you can [get your puzzle input](18/input). \ No newline at end of file diff --git a/2020/day18_operation_order/src/lib.rs b/2020/day18_operation_order/src/lib.rs new file mode 100644 index 0000000..cd63433 --- /dev/null +++ b/2020/day18_operation_order/src/lib.rs @@ -0,0 +1,210 @@ +use core::fmt::Display; +use std::num::ParseIntError; + +#[derive(Debug, PartialEq, Eq)] +pub enum ParseError { + ParseIntError(std::num::ParseIntError), + LineMalformed(String), +} + +impl From for ParseError { + fn from(value: ParseIntError) -> Self { + Self::ParseIntError(value) + } +} + +impl Display for ParseError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::ParseIntError(e) => write!(f, "Unable to parse into integer: {e}"), + Self::LineMalformed(v) => write!(f, "Line is malformed: {v}"), + } + } +} + +enum Operator { + Add, + Mul, +} + +enum SubExpression { + Expr(Box), + Num(usize), +} + +impl SubExpression { + fn eval(&self) -> usize { + match self { + Self::Expr(e) => e.eval(), + Self::Num(n) => *n, + } + } +} + +struct Expression { + op: Operator, + lhs: SubExpression, + rhs: SubExpression, +} + +impl TryFrom<&str> for Expression { + type Error = ParseError; + + fn try_from(value: &str) -> Result { + let components: Vec<_> = value.split_whitespace().collect(); + let last = components.len()-1; + if last < 2 { + Err(Self::Error::LineMalformed(value.to_string())) + } else { + if components[last].ends_with(')') { + let mut recursion_level = components[last].matches(')').count(); + let mut rhs_components = 0; + while recursion_level > 0 { + rhs_components += 1; + recursion_level += components[last-rhs_components].matches(')').count(); + recursion_level -= components[last-rhs_components].matches('(').count(); + } + if rhs_components == last { + Expression::try_from(&value[1..value.len()-1]) + } else { + let rhs_str = &components[last-rhs_components..].join(" ")[..]; + let rhs = SubExpression::Expr(Box::new(Expression::try_from(&rhs_str[1..rhs_str.len()-1])?)); + let op = match components[last-rhs_components-1] { + "+" => Operator::Add, + "*" => Operator::Mul, + _ => return Err(Self::Error::LineMalformed(value.to_string())), + }; + let lhs = match last-rhs_components { + 2 => SubExpression::Num(components[0].parse()?), + _ => SubExpression::Expr(Box::new(Expression::try_from(&components[..last-rhs_components-1].join(" ")[..])?)), + }; + Ok(Self { op, lhs, rhs }) + } + } else { + let rhs = SubExpression::Num(components[last].parse()?); + let op = match components[last-1] { + "+" => Operator::Add, + "*" => Operator::Mul, + _ => return Err(Self::Error::LineMalformed(value.to_string())), + }; + let lhs = match last { + 2 => SubExpression::Num(components[0].parse()?), + _ => SubExpression::Expr(Box::new(Expression::try_from(&components[..last-1].join(" ")[..])?)), + }; + Ok(Self { op, lhs, rhs }) + } + } + } +} + +impl Expression { + fn eval(&self) -> usize { + match self.op { + Operator::Mul => self.lhs.eval() * self.rhs.eval(), + Operator::Add => self.lhs.eval() + self.rhs.eval(), + } + } + + fn try_from_advanced(value: &str) -> Result { + let components: Vec<_> = value.split_whitespace().collect(); + let last = components.len()-1; + if last < 2 { + Err(ParseError::LineMalformed(value.to_string())) + } else { + if components[last].ends_with(')') { + let mut recursion_level = components[last].matches(')').count(); + let mut rhs_components = 0; + while recursion_level > 0 { + rhs_components += 1; + recursion_level += components[last-rhs_components].matches(')').count(); + recursion_level -= components[last-rhs_components].matches('(').count(); + } + if rhs_components == last { + Expression::try_from_advanced(&value[1..value.len()-1]) + } else { + let mut recursion_level = 0; + for idx in (0..last-rhs_components).rev() { + recursion_level += components[idx].matches(')').count(); + recursion_level -= components[idx].matches('(').count(); + if recursion_level == 0 && components[idx] == "*" { + let op = Operator::Mul; + let lhs = if idx == 1 { + SubExpression::Num(components[0].parse()?) + } else { + SubExpression::Expr(Box::new(Expression::try_from_advanced(&components[..idx].join(" ")[..])?)) + }; + let rhs = SubExpression::Expr(Box::new(Expression::try_from_advanced(&components[idx+1..].join(" ")[..])?)); + return Ok(Self { op, lhs, rhs }); + } + } + let op = Operator::Add; + let rhs = SubExpression::Expr(Box::new(Expression::try_from_advanced(&components[last-rhs_components..].join(" ")[..])?)); + let lhs = match last-rhs_components { + 2 => SubExpression::Num(components[0].parse()?), + _ => SubExpression::Expr(Box::new(Expression::try_from_advanced(&components[..last-rhs_components-1].join(" ")[..])?)), + }; + + Ok(Self { op, lhs, rhs }) + } + } else { + let mut recursion_level = 0; + for idx in (0..=last).rev() { + recursion_level += components[idx].matches(')').count(); + recursion_level -= components[idx].matches('(').count(); + if recursion_level == 0 && components[idx] == "*" { + let op = Operator::Mul; + let lhs = if idx == 1 { + SubExpression::Num(components[0].parse()?) + } else { + SubExpression::Expr(Box::new(Expression::try_from_advanced(&components[..idx].join(" ")[..])?)) + }; + let rhs = if idx == last-1 { + SubExpression::Num(components[components.len()-1].parse()?) + } else { + SubExpression::Expr(Box::new(Expression::try_from_advanced(&components[idx+1..].join(" ")[..])?)) + }; + return Ok(Self { op, lhs, rhs }); + } + } + let op = Operator::Add; + let rhs = SubExpression::Num(components[last].parse()?); + let lhs = match last { + 2 => SubExpression::Num(components[0].parse()?), + _ => SubExpression::Expr(Box::new(Expression::try_from_advanced(&components[..last-1].join(" ")[..])?)), + }; + + Ok(Self { op, lhs, rhs }) + } + } + } +} + +pub fn run(input: &str) -> Result<(usize, usize), ParseError> { + let formulas_1: Vec<_> = input.lines().map(Expression::try_from).collect::, _>>()?; + let formulas_2: Vec<_> = input.lines().map(Expression::try_from_advanced).collect::, _>>()?; + let first = formulas_1.iter().map(|f| f.eval()).sum(); + let second = formulas_2.iter().map(|f| f.eval()).sum(); + Ok((first, second)) +} + +#[cfg(test)] +mod tests { + use super::*; + use std::fs::read_to_string; + + fn read_file(name: &str) -> String { + read_to_string(name).expect(&format!("Unable to read file: {name}")[..]).trim().to_string() + } + + #[test] + fn test_sample() { + let sample_input = read_file("tests/sample_input"); + assert_eq!(run(&sample_input), Ok((26386, 693942))); + } + + #[test] + fn test_challenge() { + let challenge_input = read_file("tests/challenge_input"); + assert_eq!(run(&challenge_input), Ok((24650385570008, 158183007916215))); + } +} diff --git a/2020/day18_operation_order/tests/challenge_input b/2020/day18_operation_order/tests/challenge_input new file mode 100644 index 0000000..4fd2cf6 --- /dev/null +++ b/2020/day18_operation_order/tests/challenge_input @@ -0,0 +1,377 @@ +9 + 4 + (3 + (6 * 5 + 9 * 2 * 4) * 9) +((7 + 6) + 2 * 6 + 4 * 2 + 9) * 6 + 5 +7 * 3 * 9 * 6 + (4 + 2 + 4 * 9) + 7 +9 + (9 * 3 * 3 * (9 + 5 + 4) + 4) +(8 * 5 + (7 + 5 + 3 + 6) * 9 + 7 * (9 * 8 + 7 * 2)) * 8 +3 + (6 * 2 * (9 + 2 + 5) * (9 * 2 * 6 + 8 * 5) * (2 + 2 + 3 + 7 * 9)) + 4 * 4 + (6 * 4 * (9 + 4) + 8 * 3 * (5 + 3)) * 5 +2 * 8 * (8 * 2 * 4) + (9 * 3 * 6) * 9 +2 + (8 * 4 * 9 * 3 + 8 * 2) + 4 * 9 * 6 +((6 * 4 + 9 + 5 * 7 + 3) * 4 + 8 * (3 + 6 + 9 * 9) + 9 * 6) + (7 * 7) + 6 * 2 * 2 +2 + 5 * 3 +2 + 6 * (8 + 6 * 5 + (3 * 9) + 3) +3 + 2 * 4 + 9 * 4 + 9 +(7 + 5 + (4 + 7)) * (4 + 4 * 9) + 4 * 7 + 9 * 4 +8 + 5 * (3 + 3 + 8 + (4 + 3 * 4 + 3 * 4)) + (8 * 6 * 3) * 4 + 2 +(2 + 9 + 9 * (8 * 3 + 2 * 5 + 6 * 2)) * 4 +8 * 6 +9 * 4 * (5 + 4 + 2 + (4 * 7 + 9) * 4 * 6) * 5 * 2 +3 + (5 + (4 + 9 + 6) * 8 * 8 * (3 + 5 + 8 + 2)) * 7 + 5 * ((2 + 4 + 8 + 3) * 6 + 7 + 9) +((8 + 3 * 5 + 7) + 9) * 2 + 2 * 8 * 4 * 5 +3 + 2 + 8 * (4 * (5 + 2 * 8 * 3 * 4) + (6 + 8 * 6) + 2 + 5 * 2) +4 + ((2 + 4 * 9) * 4 + (6 + 6 + 3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+ 7 + 4 + 9)) +8 * 6 * (9 + (9 * 8 + 2 * 3) + 2 * 6 * 3) + 7 +(7 * 6 * 2 + 6 + 4) + 9 * 4 +((4 * 8) * 8 * 7 + 2) * 8 +2 + 3 * ((8 + 2 * 3 * 9 + 8 + 8) + 9 + 4 + (5 * 2) + 9 * 3) +(5 + 3 + 3) * ((5 + 4) + 5) + 8 * 8 * ((8 * 6 + 9 + 5) * 5 + 4 + 5 * 6) * 8 +(8 * (8 + 9 + 6) + 2 * 2) + 5 * 4 + 4 + 3 +(9 * 6 + 2 * 6) * (6 * 6 + 2) * (7 * (3 + 6 * 8 * 6 * 5) * 8) +(2 + 8 + 8 + (6 * 3 * 2 * 3) + 4 * (8 * 5 * 8 * 4 + 6 + 2)) * 2 + 4 + 6 + 9 +9 * 9 * 9 + (6 + 9 * 3 + 6 * 5 * 5) * 3 +3 * 2 * (8 * (4 + 5 + 8 * 5 + 5)) * 5 * 9 diff --git a/2020/day18_operation_order/tests/sample_input b/2020/day18_operation_order/tests/sample_input new file mode 100644 index 0000000..721ec45 --- /dev/null +++ b/2020/day18_operation_order/tests/sample_input @@ -0,0 +1,5 @@ +1 + (2 * 3) + (4 * (5 + 6)) +2 * 3 + (4 * 5) +5 + (8 * 3 + 9 + 3 * 4 * 3) +5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4)) +((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2