Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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