# Harry Potter and the Hall of 100 Doors

Variable

The algorithm will show you the complete pattern of opening and closing of the doors all the way to the last sequence, right inside your browser. I hope that it will save some doors from breaking. This program works fine on Firefox; however, for Explorer and other browsers, as Scotty in Star Trek always says, “I cannot guarantee it!”

The processing is very CPU intensive; therefore please make sure you have closed all the Windows and programs before pressing the button.

## Answer / Solution

The number of open doors between closed doors increases by two every time; hence, the sequence of open doors, between the closed doors is 2, 4, 6, 8, 10, 12, 14...

COOCOOOOCOOOOOOCOOOOOOOOCOOO

OOOOOOOCOOOOOOOOOOOOCOOOOOOO

OOOOOOOCOOOOOOOOOOOOOOOOCOOO

OOOOOOOOOOOOOOOC

• C = Closed Door
• O = Open Door

Hence the door numbers: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 are the closed doors. In addition, as you can see, they are squares:

 1 × 1 = 1 2 × 2 = 4 3 × 3 = 9 4 × 4 = 16 5 × 5 = 25 6 × 6 = 36 7 × 7 = 49 8 × 8 = 64 9 × 9 = 81 10 × 10 = 100

## Binary Solution

This could also have a binary solution where binary one represents a closed door and binary zero represents an open door.

Then opening a closed door and closing an opened door is like the Boolean NOT operation where binary one is changes to binary zero, and vice versa. This is not bad for a person with just a woodwork school report!

You would have to treat the whole sequence as a 100-bit binary number, which would result in large integer values. However, the BigInteger.js library has the necessary functions to process large numbers as I did for the Tupper’s Formula.

This obviously has very useful applications in encrypting and decrypting information...

## Program Code

1: var array_1 = new
2: Array(">","O","O","O","O","O","O","O","O","O",
3: "O","O","O","O","O","O","O","O","O","O","O",
4: "O","O","O","O","O","O","O","O","O","O","O",
5: "O","O","O","O","O","O","O","O","O","O","O",
6: "O","O","O","O","O","O","O","O","O","O","O",
7: "O","O","O","O","O","O","O","O","O","O","O",
8: "O","O","O","O","O","O","O","O","O","O","O",
9: "O","O","O","O","O","O","O","O","O","O","O",
10: "O","O","O","O","O","O","O","O","O","O","O",
11: "O","O","O","<");
12:  for (s=1;s<101;s++){
13:   var hops = 100/s;
14:   var d=0;
15:   for (n=1;n<hops+2;n++){
16:
17:  if(array_1[d]=="O"){
18:       array_1[d]="C";
19:     }
20:        else{
21:              array_1[d]="O";}
22:              d=d+s;
23:            }
24:  newWindow.document.write("<BR>");
25:
26:       for (i=1;i<102;i++){
27:          newWindow.document.write(array_1[i]);
28:       }
29:
30:  }

This is the actual JavaScript code that is running on this page when you press the grey button marked “The Long Process”. It works fine on Firefox, however it may not be compatible with every browser. The output will appear on another pop-up page, generated on the fly, therefore please make sure your browser does not prevent pop up pages.

This code is for students for learning purposes. It is copyright protected and cannot be used by bloggers.

## How I came across this Puzzle

After a hard day’s work, I came home to see my nephews and nieces congregated around several doors. At first, it seemed like a coordinated ritual involving the opening and closing of doors.

“What are you lot doing?” I snapped at them, as I had a terrible headache due to a low sugar level and the last thing I needed was noise.

“We’re solving the Harry Potter Riddle.” Tommy the 6 year old said.

“Well could you do it someplace else please?” I asked.

“No? We’re not allowed to go out.” He replied.

“I don’t mind you reading Harry Potter, but does it have to involve breaking my doors as well?” I added.

“We’re trying to solve the puzzle”, Jasmine the 12 year old replied.

“You do know that if those hinges break, it is going to come out of your Pizza money.” Amazingly, the magic in that sentence had the effect of creating instant silence.

So there I was relaxing with a hot cup of Earl Grey and a chocolate biscuit, when suddenly a mob came running towards me.

“Uncle Pete! Uncle Pete! Can you solve this for us on the computer? It will only take you a few minutes. Please? ”

Well, since they were so polite I figured it might be worth a shot, if only to save my doors from breaking.

## The Puzzle

Professor Oscar Levin founder of mathwiki made the puzzle. More information about the question, please consult his site.