5.py 495 B

12345678910111213141516171819202122232425
  1. lines = []
  2. with open("5.input") as f:
  3. for line in f.readlines():
  4. lines.append(line)
  5. ids = []
  6. for line in lines:
  7. head, tail = line[0:7], line[7:10]
  8. row = int(head.replace('F', '0').replace('B', '1'), 2)
  9. col = int(tail.replace('L', '0').replace('R', '1'), 2)
  10. ids.append(row * 8 + col)
  11. print("Answer 1: {}".format(max(ids)))
  12. ids.sort()
  13. last_id = ids[0] - 1
  14. for id in ids:
  15. if id != last_id + 1:
  16. print("Answer 2: {}".format((id - 1)))
  17. last_id = id