All SolutionsAll Solutions

ā²ļø

Broken Clocks

Week 24, 2026

Python - Itertools and Simple Loops | BMC | Python Solutions

""" THIS QUESTION WAS QUITE THE HELL TO READ... \/ []>_<] | |-- / \ drew this silly guy to relax lol """ from itertools import combinations class clock: def __init__(self, incrementValue: int = 0): self._hh = 0 self._mm = 0 self._ss = 0 self._overAllSeconds = 0 self._incrementValueSeconds = incrementValue def increment_clock(self) -> None: self._overAllSeconds += self._incrementValueSeconds self._hh, remainder = divmod(self._overAllSeconds, 3600) self._mm, self._ss = divmod(remainder, 60) def getOverAllSeconds(self) -> int: return self._overAllSeconds def __str__(self): return f"{self._hh}:{self._mm:02}:{self._ss:02} | + {self._incrementValueSeconds} | ttl: {self._overAllSeconds} s" def checkSync(clocks: list[clock]) -> bool: return all(c.getOverAllSeconds() % 60 == 0 for c in clocks) def updateClocks(clocks: list[clock]) -> None: for c in clocks: c.increment_clock() def findSyncTime(incorrect_speeds: tuple[int, ...]) -> int: CLOCKS = [clock(incrementValue=60)] + [clock(incrementValue=s) for s in incorrect_speeds] while True: updateClocks(CLOCKS) if checkSync(CLOCKS): return CLOCKS[0].getOverAllSeconds() # main SPEEDS = list(range(1, 61)) # 1 to 59 (60 is the correct clock) # 2-clock combos (1 correct + 2 incorrect) results_2 = {} for combo in combinations(SPEEDS, 2): t = findSyncTime(combo) results_2.setdefault(t, []).append(combo) max_2 = max(results_2) best_2 = results_2[max_2] # 3-clock combos (1 correct + 3 incorrect) results_3 = {} for combo in combinations(SPEEDS, 3): t = findSyncTime(combo) results_3.setdefault(t, []).append(combo) max_3 = max(results_3) best_3 = results_3[max_3] # SAVE TO FILE with open("ans.txt", "w") as f: for combo in best_2: f.write(f"{' '.join(map(str, combo))}\n") f.write(f"{len(best_2)} unique 2-clock combinations took {max_2}s to sync to a whole minute\n") for combo in best_3: f.write(f"{' '.join(map(str, combo))}\n") f.write(f"{len(best_3)} unique 3-clock combinations took {max_3}s to sync to a whole minute\n")

Clock ticks simulation | greenya | Odin Solutions

package main import "core:fmt" main :: proc () { find_longest_unique_N_clock_combinations(N=2, debug=false) find_longest_unique_N_clock_combinations(N=3, debug=false) } find_longest_unique_N_clock_combinations :: proc ($N: int, $debug: bool) { #assert(N > 1) clocks : [N] int combinations: [dynamic] [N] int max_cycles : int defer delete(combinations) for i in 0..<N do clocks[i] = i + 1 clocks_valid := true for clocks_valid { cycles := sync_clocks(clocks[:], debug) switch { case cycles > max_cycles: max_cycles = cycles clear(&combinations) fallthrough case cycles == max_cycles: append(&combinations, clocks) } clocks_valid = false #reverse for &c, i in clocks do if c < 60-N+1+i { c += 1 for j:=i+1; j<N; j+=1 do clocks[j] = clocks[j-1] + 1 clocks_valid = true break } } for &m in combinations { fmt.print(m[0]) for c in m[1:] do fmt.print(' ', c, sep="") fmt.println() } fmt.printfln( "%d unique %d-clock combinations took %ds to sync to a whole minute", len(combinations), N, max_cycles * 60, ) } sync_clocks :: proc (steps: [] int, $debug: bool) -> (cycles: int) { when debug do logf :: fmt.printf else do logf :: proc (..any) {} Clock :: struct { value : int, step : int, } clocks: [dynamic; 10] Clock assert(len(steps) <= cap(clocks)) logf("----") for s in steps { append(&clocks, Clock { 0, s }) logf("\tšŸ•—%d", s) } logf("\n") for cycles = 1; /**/; cycles += 1 { clocks_in_sync := true logf("-%02d-", cycles) for &c in clocks { c.value += c.step c_in_sync := c.value%60 == 0 clocks_in_sync &&= c_in_sync logf("\t%r%d", c_in_sync ? 'āœ…' : 'āŒ', c.value) } logf("\n") if clocks_in_sync do break } logf("\n") return }