-
Notifications
You must be signed in to change notification settings - Fork 0
/
13-Dec-1.py
48 lines (31 loc) · 869 Bytes
/
13-Dec-1.py
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
41
42
43
44
45
46
47
48
import math
def det(a, b, c, d):
return a * d - b * c
def solve(a1, b1, c1, a2, b2, c2):
denom = det(a1, b1, a2, b2)
numX = det(c1, b1, c2, b2)
numY = det(a1, c1, a2, c2)
if (denom == 0):
return 0, 0
x, y = numX / denom, numY / denom
if (x < 0) or (y < 0):
return 0, 0
if (x > 100) or (y > 100):
return 0, 0
return math.floor(x), math.floor(y)
def main():
f = open("AOC.txt", "r")
lines = f.readlines()
f.close()
nTokens = 0
i = 0
while (i < (len(lines) - 2)):
numbersA = [int(n) for n in lines[i].split()]
numbersB = [int(n) for n in lines[i+1].split()]
numbersRHS = [int(n) for n in lines[i+2].split()]
x, y = solve((numbersA[0]), (numbersB[0]), (numbersRHS[0]), (numbersA[1]), (numbersB[1]), (numbersRHS[1]))
print(x, y)
nTokens += 3 * x + y
i += 4
print(nTokens)
main()