-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdventOfCode11.2.py
106 lines (86 loc) · 2.54 KB
/
AdventOfCode11.2.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from datetime import datetime
with open('./seats.txt') as file:
my_input = file
data=file.readlines()
file.close()
def split(word):
return [char for char in word]
import copy
data = [split(line.replace("\r", "").replace('\n', '')) for line in data]
copy_data = copy.deepcopy(data)
movmts= {0:['#'],1:copy_data}
print(len(movmts))
x=1
times = datetime.now()
while [item for sublist in movmts[x-1] for item in sublist].count('#') != [item for sublist in movmts[x] for item in sublist].count('#'):
print("X: lgkgkjhgkjhgkjhgkjhgkjhgkhjgkjhgkjhgkjhgkjhgjhghj", x)
new_seat_map = copy.deepcopy(movmts[x])
for i in range(len(data)):
for j in range(len(data[i])):
one = [i+1, j]
two = [i-1, j]
three =[i, j+1]
four = [i, j-1]
five = [i+1, j+1]
six = [i+1, j-1]
seven = [i-1, j+1]
eight = [i-1, j-1]
z=0
v=0
print("hi")
while movmts[x][i+z][j] == '.' and z+i < len(data)-1:
one == [i+z, j]
z+=1
z=0
v=0
while movmts[x][i+z][j]=='.' and z+i < len(data)-1:
two == [i-z, j]
z+=1
z=0
v=0
while movmts[x][i][j+z]=='.' and z+j < len(data[0])-1:
print(i, j)
three == [i, j+z]
z+=1
z=0
v=0
while movmts[x][i][j-z]=='.' and z+j < len(data[0])-1:
four == [i, j-z]
z+=1
z=0
v=0
while movmts[x][i+v][j+z]=='.' and z+j < len(data[0])-1 and v+i< len(data)-1:
five == [i+v, j+z]
z+=1
v+=1
z=0
v=0
while movmts[x][i+v][j-z]=='.' and z+j < len(data[0])-1 and v+i< len(data)-1:
six == [i+v, j-z]
z+=1
v+=1
z=0
v=0
while movmts[x][i-v][j+z]=='.' and z+j < len(data[0])-1 and v+i< len(data)-1:
seven == [i-v, j+z]
z+=1
v+=1
z=0
v=0
while movmts[x][i-v][j-z]=='.' and z+j < len(data[0])-1 and v+i< len(data)-1:
eight == [i-v, j-z]
z+=1
v+=1
print(one)
adjacent_seats = [one, two, three, four, five, six, seven]
print(adjacent_seats )
adjacent_seats = [seat for seat in adjacent_seats if (seat[0]<len(data) and seat[1]< len(data[0]) and seat[0]>=0 and seat[1]>=0)]
adjacent_seats = [movmts[x][k][l] for k,l in adjacent_seats]
if adjacent_seats.count('#')==0 and movmts[x][i][j]=='L':
new_seat_map[i][j] = '#'
elif movmts[x][i][j] == '#' and adjacent_seats.count('#')>=5:
new_seat_map[i][j] = 'L'
x+=1
movmts[x] = new_seat_map
print("answer is: {}".format([item for sublist in movmts[x] for item in sublist].count('#')))
print(datetime.now() - times)