Advertisement
Guest User

Untitled

a guest
Dec 13th, 2020
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. def day13_2():
  2.     with open("input.txt", "r") as file:
  3.         data = file.readlines()
  4.  
  5.     buses = [int(i) if i != "x" else 0 for i in data[1].split(",")]
  6.  
  7.     modulus = 1
  8.     for b in buses:
  9.         if b != 0:
  10.             modulus *= b
  11.  
  12.     timestamp = 0
  13.     for b in buses:
  14.         if b != 0:
  15.             timestamp += -buses.index(b) * (modulus // b) * pow(modulus // b, -1, b)
  16.  
  17.     return timestamp % modulus
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement