aboutsummaryrefslogtreecommitdiff
path: root/2022/02/solve.py
blob: 00d4a5f5774e095ae41b210bf533e3d780536d38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
data = [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():
    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")]
        rot = mat[factor:] + mat[:factor]
        res += rot[ord(line[1]) - ord("X")]

    return res

# X Y Z = lose draw win
# 1 2 3 = Rock Paper Scissors
# A B C = Rock Paper Scissors

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

print(f"Part 1: {part1()}")
print(f"Part 2: {part2()}")