Related: Turn off all lights in a ring-shaped palace
Your boss has trapped you inside a ring-shaped palace, and all you know about the palace is that there are some number* of identical rooms, each of which contains a light which you can toggle on and off, and two doors which lead to adjacent rooms on either side (possibly back into the same room if there is only one). You don't know which lights are on or off to start with. The rooms happen to have the wall bordering the inside of the ring painted black and the wall bordering the outside of the ring painted white, so you can tell which direction is which.
Your job is to switch all the lights off, and once this is done, report to your boss via phone. The caveat is, if there is still a light on, you will be executed. The boss is also impatient, so you can't just keep walking forever.
Unfortunately, you suffer from short-term memory loss. Specifically, after walking through a door, you can only remember a single integer between 1 and N# inclusive at any time, and must do so. Luckily, you have a few minutes in which you can write down a plan to take around, but you can't continue to edit the plan once you pass through your first door.
* An arbitrary unknown positive integer, this could include 1
# You choose N (which must be a positive integer), see below
What is the minimum N that allows you to escape?^
^ The first answer with the smallest N out of all current answers will be accepted, but this may change if an answer with a smaller N is submitted. Proof is not required that this N is necessarily the smallest possible N.
NB: This is not a lateral-thinking puzzle. Below are some loopholes I have closed (loopholes I will not accept are not limited to these).
- There are thick doors between the rooms, so you cannot see light from between adjacent rooms, and the door closes behind you as soon as you step through it, so you can't stand in a doorway and look between rooms
- Magical fairies clean any rooms you do not occupy, so you can't leave things behind except from the state of the light
- You don't have any location tracking devices to help you, nor memory storing devices except your planning paper (which cannot be torn or folded), including the state of your body (when the door closes behind you, it hits you so that you fall down and instinctively you fall into the same position every time, and more magical fairies heal your body and redress you in exactly the same clothes you had)
- The lightbulbs are too high for you to detect their temperature
- The rooms are too long for you to detect any curvature in them
- The castle is completely impervious to information exchange (e.g. there are no windows) between inside and out except for you notifying your boss that you are finished
- There is no fuse box for you to turn off, and you can't access the wiring from the switch
Congratulations to @Lawrence and @Bass for independently discovering a loophole in the question that I think is a feature and shouldn't be closed. I will award the checkmark to the first lowest N regardless of whether this loophole is used or not, but will be awarding a small bounty (+50) to the first lowest N that doesn't make use of this loophole since some people have already put in quite some effort into their solutions.
Currently, @ajee is the first with both a solution for N=2 with the loophole and a derived solution for N=4 without the loophole.