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
VP 29.1: Without Parentheses (15 pts)
Write a function that can evaluate expressions without parentheses.Evaluate these three expressions and muliply the results together to form the flag.
23 + 1 * 8 + 7 + 12 * 3 44 + 21 * 66 + 3 + 55 * 2 1 + 5 + 77 * 33 * 7 + 2 * 2
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?
VP 29.2: With Parentheses (10 pts extra)
Write a function that can evaluate expressions with parentheses.Evaluate these three expressions and muliply the results together to form the flag.
23 + 1 * (8 + 7 + 12) * 3 44 + 21 * (66 + 3) + (55 * 2) (1 + (5 + 77 * 33 * (7 + 2))) * 2
VP 29.3: Large Dataset (10 pts extra)
Evaluate these expressions:VP29Calculate the total of all the results. That's the flag.
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.
VP 29.4: Precedence (10 pts extra)
Use the same large dataset as in the previous flag.Evaluate the expressions using the new precedence rule.
Calculate the total of all the results. That's the flag.
Posted 9-20-24
Video added 10-9-24