diff options
Diffstat (limited to '2022/02/solve.py')
-rw-r--r-- | 2022/02/solve.py | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/2022/02/solve.py b/2022/02/solve.py index 00d4a5f..ded08c8 100644 --- a/2022/02/solve.py +++ b/2022/02/solve.py @@ -1,40 +1,20 @@ -data = [dat.split(" ") for dat in open("input").read().split("\n") if dat != ''] +data = [[ord(x) - (ord("X") if i == 1 else ord("A")) for i,x in enumerate(dat.split(" "))] for dat in open("input").read().split("\n") if dat != ''] -# X Y Z = Rock Paper Scissors -# A B C = Rock Paper Scissors - -def part1(): +def solve(choice, mat, factors): res = 0 - choice=[1,2,3] - mat = [3,6,0] - factors = [1, 0, 2] - mat = [0,3,6] for line in data: - res += choice[ord(line[1]) - ord("X")] - factor = factors[ord(line[0]) - ord("A")] + factor = factors[line[0]] rot = mat[factor:] + mat[:factor] - res += rot[ord(line[1]) - ord("X")] + res += choice[line[1]] + rot[line[1]] return res -# X Y Z = lose draw win -# 1 2 3 = Rock Paper Scissors -# A B C = Rock Paper Scissors +def part1(): + return solve([1,2,3], [0,3,6], [1,0,2]) def part2(): - res = 0 - - choice = [0,3,6] - mat = [3,1,2] - - for line in data: - res += choice[ord(line[1]) - ord("X")] - factor = ord(line[0]) - ord("A") - rot = mat[factor:] + mat[:factor] - res += rot[ord(line[1]) - ord("X")] - - return res + return solve([0,3,6], [3,1,2], [0,1,2]) print(f"Part 1: {part1()}") print(f"Part 2: {part2()}") |