-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday5.py
67 lines (44 loc) · 1.07 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
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 5 14:13:49 2020
@author: rundx
"""
import sys
tickets = []
f = open('day5.txt', 'r')
for line in f:
tickets.append(line.rstrip())
def binaryRow(rowID):
minRow = 0
maxRow = 127
for char in rowID:
if char == 'F':
maxRow = (minRow + maxRow)//2
if char == 'B':
minRow = (minRow + maxRow)//2 + 1
return minRow
def binaryCol(rowID):
minRow = 0
maxRow = 7
for char in rowID:
if char == 'L':
maxRow = (minRow + maxRow)//2
if char == 'R':
minRow = (minRow + maxRow)//2 + 1
return minRow
def convertTicket(seatString):
rowID = seatString[:7]
colID = seatString[7:]
row = binaryRow(rowID)
col = binaryCol(colID)
seatID = 8*row + col
return seatID
ticketIDs = []
for ticket in tickets:
ticketIDs.append(convertTicket(ticket))
print(max(ticketIDs))
maxID = max(ticketIDs)
minID = min(ticketIDs)
for i in range(minID,maxID+1):
if i not in ticketIDs:
print(i)