First, let's nail down the definition of configuration so we know exactly when the devil wins.
It cannot simply be the state of the lanterns, since not changing a lantern on a given step would then repeat the configuration.
So the location of the devil and angel need to be part of it. There are two ways I see of incorporating this.
Include which lantern number the devil and angel are at and the string of lantern states. Which could be notated by a location marked in a string of lantern states (e.g., "01101;001") or a number and the string (6,01101001).
The lantern numbers don't matter, just look forward from the lantern the angel and devil are at (e.g., ";00101101"). And then you don't need the location marker ";" because it is always at the front.
Option 1 has more states, lanterns x 2^lanterns compared to just 2^lanterns. Let's choose option 2 since less states means more of a chance of repeat and gives the devil a better chance. That is the notation I used for my code.
I notice that you use the word "turn" to sometimes mean one whole stroll around all the lanterns. That is something that threw me off a little. I'd call that a revolution or a full rotation.
Alright, time to put the devil in his place.