26 lines
531 B
JavaScript
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)
|
|
);
|