⛄ Day 5

Advent of Code is a coding challenge that releases a puzzle every day starting December 1st up until the 25th - like an Advent Calendar but no stale chocolate...

Part 1

Find the highest seat ID from a given set of codes
Solution:
                                
                                    
    # For example, consider just the last 3 characters of FBFBBFFRLR:
    # 
    # Start by considering the whole range, columns 0 through 7.
    # R means to take the upper half, keeping columns 4 through 7.
    # L means to take the lower half, keeping columns 4 through 5.
    # The final R keeps the upper of the two, column 5.
    # So, decoding FBFBBFFRLR reveals that it is the seat at row 44, column 5.
    # 
    # Every seat also has a unique seat ID: multiply the row by 8, then add the column. In this example, the seat has ID 44 * 8 + 5 = 357.
    
    import csv
    
    
    def read_input(file_name):
        with open(file_name, 'r') as data:
            return list(map(lambda x: x[0], csv.reader(data)))
    
            
    def get_seat_id(line):
        row, col = line[:7], line[7:]
        row = row.replace('F', '0')
        row = row.replace('B', '1')
        col = col.replace('L', '0')
        col = col.replace('R', '1')
    
        return int(row, 2) * 8 + int(col, 2)
    
    
    input = read_input('__05.txt')
    seat_ids = map(lambda i: get_seat_id(i), input)
    sorted_seats = sorted(seat_ids)
    
    print(sorted_seats[-1])
        
                                
                            

Part 2

Find your seat, it will be the only missing id from the set of codes
Solution:
                                
                                    
    def find_my_seat(sorted_input):
        prev = None
        for i in sorted_input:
            if prev is not None and i - prev > 1:
                return i - 1
            else:
                prev = i
            
    print(find_my_seat(sorted_seats))