Advent of Code Solutions Thread: Day Two

Only shitty solutions allowed

38
Jump in the discussion.

No email address required.

const Q = {
    X: {
        A: "Z",
        B: "X",
        C: "Y"
    },
    Y: {
        A: "X",
        B: "Y",
        C: "Z"
    },
    Z: {
        A: "Y",
        B: "Z",
        C: "X"
    }
}

function score(them, me) {
    me = Q[me][them]
    let score = { X: 1, Y: 2, Z: 3 }[me];
    if (them == "A" \&\& me == "X" \|\| them == "B" && me == "Y" \|\| them == "C" \&\& me == "Z") {
        score += 3
    } else if (them == "A" \&\& me == "Y" \|\| them == "B" && me == "Z" \|\| them == "C" \&\& me == "X") {
        score += 6;
    }
    return score
}
let sum = 0;
for (const line of input.lines()) {
    const them = line.word()
    const me = line.word()
    sum += score(them, me);
}
console.log(sum)
Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.