#232 · Simulation · Beginner · 30 XP · about 6 min
A traffic light turns green at second 0. It stays green for green seconds, then yellow for yellow seconds, then red for red seconds, and then the whole cycle starts again with green, forever.
Write light_at(t, green, yellow, red) that returns the colour showing at second t: 'green', 'yellow' or 'red'. For example, a light that is green for 30 seconds shows green during seconds 0 to 29 and turns yellow at second 30.
light_at(0, 30, 5, 25) # returns 'green' light_at(32, 30, 5, 25) # returns 'yellow' light_at(59, 30, 5, 25) # returns 'red' light_at(60, 30, 5, 25) # returns 'green'
A full cycle of this light lasts 30 + 5 + 25 = 60 seconds, so at second 60 it is green again.
t can be enormous, up to 10**15, so counting second by second is far too slow.green and red are at least 1. yellow may be 0, which means the light goes straight from green to red.First solves only, ranked by stars and then time.