adventofcode/2022/02/part2.js

26 lines
531 B
JavaScript
Raw Normal View History

2022-12-02 15:59:27 +00:00
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)
);