-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp04a.py
70 lines (58 loc) · 1.13 KB
/
p04a.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# https://adventofcode.com/2021/day/4 part 1
# Created by: Menaka S. 4 Dec 2021
import sys
nums = []
first = 0
none = 0
ctr = -1
matrix = []
def calculatescore(ctr):
total = 0
for i in range(0,5):
for j in range(0,5):
total += int(matrix[ctr][i][j])
return total
def hascomplete(ctr):
#rows
for i in range(0,5):
marked = 1
for j in range(0,5):
if matrix[ctr][i][j] != '0':
marked = 0
if marked == 1:
return 1
#columns
for i in range(0,5):
marked = 1
for j in range(0,5):
if matrix[ctr][j][i] != '0':
marked = 0
if marked == 1:
return 1
for line in sys.stdin:
line = line.strip()
if first == 0:
nums = line.split(',')
first = 1
else:
if line == '':
none=0
ctr +=1
else:
if none == 0:
matrix.append([])
none = 1
matrix[ctr].append(line.split())
draw = 0;
while draw < len(nums):
for i in range(0,len(matrix)):
for j in range(0,5):
for k in range(0,5):
if matrix[i][j][k] == nums[draw]:
matrix[i][j][k] = '0'
for k in range(0,len(matrix)):
if hascomplete(k):
score = calculatescore(k)
print( score * int(nums[draw]))
exit()
draw += 1