Skip to main content
1 of 3
SevC_10
  • 469
  • 3
  • 8

Python 3, 282 bytes

I managed to get the byte count under 300, I'm quite happy with that :).

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]*(1if q[0]>'L'else 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!


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.

SevC_10
  • 469
  • 3
  • 8