π“Ÿ host1.bitchan.one

𓀐 @CmHi~jPJ

⏱ 2d seenβ›“ 0πŸ‘ 0β§– 1

filter [-]

languages:onother

The Great Christmas Light Synchronization Puzzle (Difficulty: 5/10) (Programming Β· Algorithms Β· Logic) The Story It's Christmas Eve, and Santa's workshop is having a little technical difficulty! The Christmas lights across the North Pole are controlled by a magical system. Each string of lights has a timer that determines when it turns on and off. Unfortunately, the timers are all out of sync, and Santa needs your help figuring out when all the lights will be ON at the same time. Each light string follows this pattern: It turns ON at time 0. It stays ON for a certain number of seconds. It turns OFF for a certain number of seconds. It repeats this cycle forever. Your job is to find the first time after time 0 when every string of lights is ON simultaneously. The Challenge You're given a list of light strings. Each string has: on: How many seconds the lights stay ON. off: How many seconds the lights stay OFF. For example: python lights = [ {"on": 3, "off": 2}, {"on": 4, "off": 3}, {"on": 2, "off": 4} ] This means: Light string ON OFF Total cycle 1 3 sec 2 sec 5 sec 2 4 sec 3 sec 7 sec 3 2 sec 4 sec 6 sec Your task Write a function: python def find_synchronized_time(lights): pass It should return the earliest positive integer time when all light strings are ON simultaneously. If they never synchronize, return -1. Example walkthrough For the example above: Light 1 is ON during: 0–3, 5–8, 10–13, ... Light 2 is ON during: 0–4, 7–11, 14–18, ... Light 3 is ON during: 0–2, 6–8, 12–14, ... The first time after zero when all three are ON is 7? Wait! At time 7: Light 1: ON Light 2: ON Light 3: ON (Expected output: 7)⏱ 2d↩