diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-12-02 16:50:41 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-12-02 16:51:52 +0300 |
commit | c3f76aa0ca9badbadfa567f438857d5fbd3511bf (patch) | |
tree | 145380368ca767f257352ffc41574063987ad547 | |
parent | ea2449a171230bf5bb79d4cc010aa72e720daf31 (diff) | |
download | aoc-2022-c3f76aa0ca9badbadfa567f438857d5fbd3511bf.tar.gz |
feat(day-2): even more dumb part 2
-rw-r--r-- | day-2/index.js | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/day-2/index.js b/day-2/index.js index 3671a9b..245acb7 100644 --- a/day-2/index.js +++ b/day-2/index.js @@ -12,14 +12,21 @@ const defeatMap = { // What defeats what [PAPER]: ROCK, } -const shapeMap = { +// This is dumb +const suckMap = { // What loses to what + [ROCK]: PAPER, + [SCISSORS]: ROCK, + [PAPER]: SCISSORS, +} + +const inputMap = { A: ROCK, B: PAPER, C: SCISSORS, - X: ROCK, - Y: PAPER, - Z: SCISSORS, + X: LOSS, + Y: DRAW, + Z: WIN, } const shapeScores = { @@ -35,12 +42,14 @@ const outcomeScores = { }; const result = lines.reduce((acc, line) => { - const [opponentShape, shape] = line.split(' ').map(code => shapeMap[code]); - if (!shape || !opponentShape) return acc; + const [opponentShape, outcome] = line.split(' ').map(code => inputMap[code]); + if (!outcome || !opponentShape) return acc; + + let shape; - let outcome = LOSS; - if (shape === opponentShape) outcome = DRAW; - else if (defeatMap[shape] === opponentShape) outcome = WIN; + if (outcome === DRAW) shape = opponentShape; + else if (outcome === LOSS) shape = defeatMap[opponentShape]; + else if (outcome === WIN) shape = suckMap[opponentShape]; return acc + shapeScores[shape] + outcomeScores[outcome]; }, 0) |