Problem 123379 · easy · Phase 01 Prerequisites & Setup

Traffic Light at Time t

loops · modulo · conditionals

A traffic light repeats forever: green for green seconds, then yellow for yellow seconds, then red for red seconds, starting green at time 0. For each time in times (whole seconds) return the colour that is showing at that instant, as a list of strings "green", "yellow" or "red". The light switches exactly at the boundary, so at t = green it is already yellow.

Examples

Input:  green = 30, yellow = 5, red = 25, times = [0, 29, 30, 35, 59, 60]
Output: ["green", "green", "yellow", "red", "red", "green"]

Input:  green = 2, yellow = 1, red = 1, times = [0, 1, 2, 3, 4, 7]
Output: ["green", "green", "yellow", "red", "green", "red"]

Constraints

  • 1 <= green, yellow, red <= 1000, 0 <= len(times) <= 1000, 0 <= times[i] <= 10**9

Goals

  • Use modulo to map any time onto one repeating cycle
  • Turn a position inside the cycle into a phase with if/elif/else
Starting Python…