Here's my version of this game ... I've tried to simplify the code where I could (primarily by removing the precomputed tables). See https://scratch.mit.edu/discuss/topic/224661/
turn on the 'lights status' and 'lights' reporters if you want to follow the binary arithmetic used.