python-by-contract-corpus
latest

Contents:

  • Introduction
  • Correct Programs
    • Common
    • Solutions to Advent of Code 2020
      • Day 1: Report Repair
      • Day 2: Password Philosophy
      • Day 3: Toboggan Trajectory
      • Day 4: Passport Processing
      • Day 5: Binary Boarding
      • Day 6: Custom Customs
      • Day 7: Handy Haversacks
      • Day 8: Handheld Halting
      • Day 9: Encoding Error
      • Day 10: Adapter Array
      • Day 11: Seating System
      • Day 12: Rain Risk
      • Day 13: Shuttle Search
      • Day 14: Docking Data
      • Day 15: Rambunctious Recitation
      • Day 16: Ticket Translation
      • Day 17: Conway Cubes
      • Day 18: Operation Order
      • Day 19: Monster Messages
      • Day 20: Jurassic Jigsaw
      • Day 21: Allergen Assessment
      • Day 22: Crab Combat
      • Day 23: Crab Cups
      • Day 24: Lobby Layout
      • Day 25: Combo Breaker
    • Solutions to ETHZ “Introduction to Programming” 2019
  • Recorded Failures
  • Incorrect Programs
  • Contributing
  • Contributors
  • Changelog
python-by-contract-corpus
  • »
  • Correct Programs »
  • Solutions to Advent of Code 2020 »
  • Day 13: Shuttle Search
  • Edit on GitHub

Day 13: Shuttle Search¶

Functions:

next_departure(bus_id, min_time)

Compute the next departure of bus_id leaving earliest at min_time.

find_departure(start_time, bus_ids)

Find the earliest bus to catch after start_time.

parse_input(lines)

Parse the input into (earliest departure time, bus IDs).

main()

Execute the main routine.

next_departure(bus_id: int, min_time: int) → int[source]¶

Compute the next departure of bus_id leaving earliest at min_time.

Requires
  • bus_id > 0

  • min_time >= 0

Ensures
  • min_time == 0 ⇒ result == 0

    (All buses leave at time zero.)

  • result < min_time + bus_id

  • result >= min_time

find_departure(start_time: int, bus_ids: Set[int]) → Tuple[int, int][source]¶

Find the earliest bus to catch after start_time.

Requires
  • all(i > 0 for i in bus_ids)

  • len(bus_ids) > 0

  • start_time >= 0

Ensures
  • result[0] % result[1] == 0

    (Departure time matches at least one bus.)

  • result[0] >= start_time

parse_input(lines: Lines) → Tuple[int, Set[int]][source]¶

Parse the input into (earliest departure time, bus IDs).

Requires
  • len(lines) == 2
    and re.match(r"\d+", lines[0])
    and re.match(r"(\d+|x)(,(\d+|x))*", lines[1])
    
  • len(lines) == 2

main() → None[source]¶

Execute the main routine.

Next Previous

© Copyright . Revision 6db58f7e.

Built with Sphinx using a theme provided by Read the Docs.