-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday5.py
85 lines (66 loc) · 2.12 KB
/
day5.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
import math
ticketFile=open(('/home/anjab/PycharmProjects/AdventofCode/venv/passports.txt'), 'r')
file=ticketFile.readlines()
rangeLowRow=0
rangeHighRow=127
rangeLowCol=0
rangeHighCol=7
row=0
col=0
listOfTickets=[]
#loop through tickets
for ticket in file:
#loop through chars of ticket
countRow=0
countCol=0
for element in ticket:
if(rangeHighRow==rangeLowRow):
row=rangeHighRow
if(element=="F" and countRow==0):
rangeLowRow=0
rangeHighRow=63
countRow= countRow + 1
continue
if (element == "B" and countRow==0):
rangeLowRow = 64
rangeHighRow = 127
countRow = countRow + 1
continue
if(element=="F" and countRow>0):
rangeLowRow=rangeLowRow
rangeHighRow= rangeHighRow - int(math.ceil((rangeHighRow - rangeLowRow) / 2))
if(element=="B" and countRow>0):
rangeHighRow=rangeHighRow
rangeLowRow= rangeLowRow + int(math.ceil((rangeHighRow - rangeLowRow) / 2))
if (element == "L" and countCol == 0):
rangeLowCol = 0
rangeHighCol = 3
countCol = countCol + 1
continue
if(rangeHighCol==rangeLowCol):
col=rangeHighCol
id=row*8+col
listOfTickets.append(id)
rangeHighCol=7
rangeLowCol=0
rangeHighRow=127
rangeLowCol=0
break
if (element == "R" and countCol == 0):
rangeLowCol = 4
rangeHighCol = 7
countCol = countCol + 1
continue
if (element == "L" and countCol > 0):
rangeLowCol = rangeLowCol
rangeHighCol = rangeHighCol - int(math.ceil((rangeHighCol - rangeLowCol) / 2))
if (element == "R" and countCol > 0):
rangeHighCol = rangeHighCol
rangeLowCol = rangeLowCol + int(math.ceil((rangeHighCol - rangeLowCol) / 2))
listOfTickets.sort()
number=7
for element in listOfTickets:
if(element!=number):
print("myID "+""+str(element-1))
break
number=number+1