Skip to content

Instantly share code, notes, and snippets.

@bluepichu
Created December 2, 2022 05:09
Show Gist options
  • Save bluepichu/238f9eec87f71857ed5468e6d0d7f9af to your computer and use it in GitHub Desktop.
Save bluepichu/238f9eec87f71857ed5468e6d0d7f9af to your computer and use it in GitHub Desktop.
aoc22-02.mts
import { Advent, f } from "advent";
const { compute, computeCheck } = await Advent({ day: 2 });
compute(2, async (input) => {
const data = input.parse(f.nl(f.tok(f.str())));
let ans = 0;
for (const [them, us] of data) {
let t = them.charCodeAt(0) - "A".charCodeAt(0);
let u = us.charCodeAt(0) - "X".charCodeAt(0);
if (u == 0) {
ans += (t + 2) % 3 + 1;
} else if (u == 1) {
ans += t + 1;
} else if (u == 2) {
ans += (t + 1) % 3 + 1;
}
ans += u * 3;
}
return ans;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment