Created
December 2, 2022 05:09
-
-
Save bluepichu/238f9eec87f71857ed5468e6d0d7f9af to your computer and use it in GitHub Desktop.
aoc22-02.mts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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