From c3f76aa0ca9badbadfa567f438857d5fbd3511bf Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 2 Dec 2022 16:50:41 +0300 Subject: feat(day-2): even more dumb part 2 --- day-2/index.js | 27 ++++++++++++++++++--------- 1 file 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) -- cgit v1.2.3