Door 36 gets a surprising amount of traffic. Somebody opens it on the first pass down the corridor, closes it on the second and opens it again on the third. By the end of the hundredth pass, door 36 is open. Door 35, which started out shut and has been subject to exactly the same rules, is shut again.

100 doors is one of the programs you can now read in MIMERCode on Rosetta Code. Each task gets a page of its own, with solutions in different languages. If you know Delphi, start with the Pascal solution and compare it with MIMERCode. Both let you use the number on the door as its array index. The difference is what happens to door zero. Browse the MIMERCode collection
The rules for the doors fit in a sentence. All hundred start closed, and on pass n you change the state of every nth door. The first Pascal solution declares Array[1..100] of Boolean, so its first slot belongs to door 1. The MIMERCode solution sets up 101 Boolean values for 100 doors, with a comment explaining the spare one. Index zero stays unused so that door 36 can be IsOpen[36]. On the seventh pass the loop starts at door 7 and advances seven places at a time. There’s no need to ask whether door 23 is due for a visit. The loop never gets there. See the Pascal solution
At the end, filter picks out the numbers of the doors still open. A second line uses map to square each number from one to ten. Both lines print the same ten numbers, 1 4 9 16 25 36 49 64 81 100.
Consider the two doors we started with. Door 35 gets four visits, one for each of its divisors. You can pair them off as 1 and 35, then 5 and 7. Each pair accounts for two changes of state. The same bookkeeping works for door 36 until you reach 6 × 6. Pass six only happens once. That leaves door 36 with nine visits, and gives you a way to work out what happens to any door without walking the corridor. Read 100 doors in MIMERCode
Guess the output
For a closer look at the language, try Closures/Value capture. Cover the output with your hand. The program runs a loop with I going from zero to nine. Each time round, it adds a small function to a list. Every one of those functions has the same instruction, return I * I. After the loop finishes, the program calls the function at index three. What does it print?

Nine. A MIMERCode lambda copies the variables it captures when it is created, so the function made when I was three still has its three. You can read the loop correctly in half a dozen languages and still have good reason to hesitate over that line in a new one. It depends on a choice the language designer made.
The second half of the example is worth reading alongside the first. A function called MakeCounter() creates a local N, initially zero, and returns a function that adds one to its captured copy each time you call it. The program makes two counters, calls the first three times and then calls the second. The output is 1 2 3 1. You can see both properties in those four numbers. A counter keeps its changes between calls, and making a second counter gives it a count of its own. Read Closures/Value capture in MIMERCode
Drawing the Mandelbrot set in 78 columns
The MIMERCode entry draws the Mandelbrot set on a grid 78 characters wide and 24 lines high. For each position on the grid, the program asks how many iterations it will take before the calculation escapes. The Escape function counts up to fifty. If it reaches fifty, the program prints an @ for that position.

The bands around the edge come from Shades[N mod 9]. A point that escapes after two iterations gets the same character as one that escapes after eleven, then twenty. Follow one of those bands across the picture and you’re looking at a few bits of arithmetic rendered in punctuation. You can change the look of the whole thing by editing a single string. See the MIMERCode Mandelbrot set and its output
There’s plenty in the collection for a wet afternoon, including CSV files, Roman numerals and the business of taking 99 bottles of beer down from a wall. In that last one, a little function called Bottles handles the wording for zero, one and many. Anybody who has ever shipped a dialog box saying “1 files remaining” will appreciate it. Read 99 bottles of beer in MIMERCode
Pick a task you once wrote in another language, preferably one you remember well enough to have an opinion about. Read the MimerCode version with that old program in mind and see where you’d have made a different choice. And if you start with the doors, try predicting the fate of door 72 before you look at the output. Find your first MIMERCode task
![]()








