Created
December 5, 2020 22:24
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_binary(string: str): | |
string = ( | |
string.replace("B", "1").replace("F", "0").replace("R", "1").replace("L", "0") | |
) | |
return int(string, base=2) | |
def part1(strings): | |
return max([to_binary(string) for string in strings]) | |
def part2(strings): | |
seats = sorted([to_binary(string) for string in strings]) | |
for i, _ in enumerate(seats): | |
if seats[i] - seats[i - 1] == 2: | |
return seats[i] - 1 | |
if __name__ == "__main__": | |
with open("input.txt") as infile: | |
strings = [string.strip() for string in infile.readlines()] | |
print(f"Part 1 {part1(strings)}") | |
print(f"Part 2 {part2(strings)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment