-
Notifications
You must be signed in to change notification settings - Fork 0
/
11-1.py
66 lines (61 loc) · 1.84 KB
/
11-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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
f = open("Day11Seat.txt", "r")
d = f.read().split("\n")
length = len(d[0])
tempL = list(d)
total = 0
while True:
for x in range(len(d)):
for y in range(length):
if d[x][y] == ".":
temp = list(tempL[x])
temp[y] = d[x][y]
tempL[x] = ''.join(temp)
continue
taken = 0
if x:
if d[x-1][y] == "#":
taken = taken + 1
if y + 1 < length:
if d[x - 1][y + 1] == "#":
taken = taken + 1
if y:
if d[x][y-1] == "#":
taken = taken + 1
if x + 1 < len(d):
if d[x+1][y - 1] == "#":
taken = taken + 1
if x * y:
if d[x-1][y-1] == "#":
taken = taken + 1
if x + 1 < len(d):
if d[x+1][y] == "#":
taken = taken + 1
if y + 1 < length:
if d[x + 1][y+1] == "#":
taken = taken + 1
if y + 1 < length:
if d[x][y+1] == "#":
taken = taken + 1
if taken == 0:
temp = list(tempL[x])
temp[y] = "#"
tempL[x] = ''.join(temp)
elif taken >= 4:
temp = list(tempL[x])
temp[y] = "L"
tempL[x] = ''.join(temp)
else:
temp = list(tempL[x])
temp[y] = d[x][y]
tempL[x] = ''.join(temp)
if d == tempL:
break
d = list(tempL)
print('\n'.join(tempL))
print()
d = list(tempL)
for x in range(len(d)):
for y in range(length):
if d[x][y] == "#":
total = total + 1
print(f"Total: {total}")