adventofcode/2022/02/part2.js
2022-12-02 10:59:27 -05:00

26 lines
531 B
JavaScript

import * as R from "remeda";
import { movePositions, mapScores, playMap, parseInput } from "./part1.js";
function calculateMove(opponent, verdict) {
const incr = {
Y: 0,
X: 2,
Z: 1,
};
const index =
(movePositions.findIndex((x) => x === opponent) + incr[verdict]) %
movePositions.length;
return movePositions[index];
}
export const solutionPart2 = R.createPipe(
parseInput,
R.map(([a, b]) => [a, calculateMove(a, b)]),
R.map(mapScores),
R.map(R.sumBy(R.identity)),
R.sumBy(R.identity)
);