Discussion thread for day 2 of the Advent of Code - https://adventofcode.com/2022/day/2
Day 2 done ! ✅
If you need to work on your conditional statements game, here is the training !
I went for the nested IF statements ! Because where would be the fun otherwise ?
Mathematical formula for part 1 :
Mod(CharToInt([Player]) - CharToInt([Opponent]) - 19, 3) * 3 + CharToInt([Player]) - 87
Mathematical formula for part 2 :
(CharToInt([Player]) - 88) * 3 + Mod(ABS(-CharToInt([Player])-CharToInt([Opponent]) + 151), 3) + 1
Day 2 done! This one took way longer than I care to admit... Which is what happens when you don't read the question properly and miss the part about draws, so assign your move based upon your opponent!
I organized the pattern and I found that it is simple. So I remade the workflow as using formula tool.
Formula
ToNumber(
Switch(Right([Input],1),"0",
"X","1",
"Y","2",
"Z","3"
))
+
ToNumber(
IF [Input] IN ("C X","A Y","B Z") THEN "6"
ELSEIF [Input] IN ("A X","B Y","C Z") THEN "3"
ELSE "0"
ENDIF
)
Formula for Part 2
ToNumber(
Switch(Right([Input],1),"0",
"X","0",
"Y","3",
"Z","6"
))
+
ToNumber(
IF [Input] IN ("A X","C Y","B Z") THEN "3"
ELSEIF [Input] IN ("C X","B Y","A Z") THEN "2"
ELSE "1"
ENDIF
)
A bit copy & paste on the formula, otherwise so far so good.
Nothing clever about today's solution
just write every option...
a bit of a tricky one!
Did the giant If Else If
When I solved way past when I should have been sleeping, I created lookup tables for the different values and scores.
Here is my tool golf solution. 3 tools: