# [Python 3], <s>282</s> 276 bytes I managed to get the byte count under 300, I'm quite happy with that :). Edit: *-6 bytes thanks to @ovs:* rewritten ternary if ... else <!-- language-all: lang-python --> def f(h): m,t=[],[[0]*-~len(h)for i in range(4)] for w in h: x='' for q in zip(w,'012'*len(w)):x+=q[1]*(q[0]>'L'or 3)+'3' x+='3'*6;m.append(x*450) for i in range(3600): for n in'0123'[3*(t[2][-1]>4):]:t[int(n)][[c[i]for c in m].count(n)]+=1 print(t[:3],t[3][::-1]) [Try it online!][TIO-krkt8i9w] [Python 3]: https://docs.python.org/3/ [TIO-krkt8i9w]: https://tio.run/##TY7NbsIwEITveQrf/ENACQ4cXIUn8M3H1R4QJE2kYkLkCtpDXz3dJSDlNOtvZmc9/KTuGu00nZtWtKrTLhOXPNWAOUCBZv331UTC7XUUveijGI/xs1GVxkwwuzPraEk8ailJGN4Y/vaDuueyKLfScMdda/dY1Tco0agbdR@klxS2eiUtb5JJg9l/XDbHYWjiWT1MtSv0fGhx3O6Lgv/55JE4H7ESrFEJtgjrEg@VdugS9DGpqBHgBD1y/MQ1F9ycrt@ztarLTAwjBxM4i3kCi@AcleipVSCDDzIXJP4p4fnywUvU2cL3r1hYODQTDm@fn@EdJ303@tcwR2h7@gc "Python 3 – Try It Online" ---------- *Original code explanation (at least I tried)* - `def f(h):` Function definition, takes as input the list with the lighthouses' codes. - `m,t=[],[[0]*-~len(h)for i in range(4)]` Initialize the empty list `m` that will contain the translated codes. Initialize the list of counters: 4 lists (1 for each color and 1 for the total), each with n+1 lighthouses elements. - `for w in h:` Loop on the code of each lighthouse to translate into color codes. - `x=''` Initialize empty string for the translated code. - `for q in zip(w,'012'*len(w)):x+=q[1]*(1if q[0]>'L'else 3)+'3'` Translate the `'SL'` sequences into color codes and the corresponding duration. `zip(w,'012'*len(w))` zips the the `'SL'` code with the corresponding repeated color sequence ('0'=F, '1'=C, '2'=A). For each `'S'`, `'L'`: replace with the color code (repeated for the seconds of short or long duration) and the off separation period ('3'=OFF). - `x+='3'*6;m.append(x*450)` Add the long off period (6s since 1s is already present) and extend the translated sequence for at least 1h. - `for i in range(3600):` Loop for 1h: for each second... - `for n in'0123'[3*(t[2][-1]>4):]:t[int(n)][[c[i]for c in m].count(n)]+=1` For each color and for the off (`in '0123'`)... `'0123'[3*(t[2][-1]>4):]` count only the off periods (indexed last item of the string) if we get 5s of color A on all lighthouses at the same time. `[c[i]for c in m]` status of each lighthouse at second *i*. `count(n)` gives how many lighthouses have that status `n`; the count corresponds to the index in the list of the corresponding status; and increment the counter. - `print(t[:3],t[3][::-1])` Print the counter for the colors and the total ON period: this list must be reversed since in the previous step we counted the OFF periods.