The Magic Café
Username:
Password:
[ Lost Password ]
  [ Forgot Username ]
The Magic Cafe Forum Index » » Puzzle me this... » » King (er, President) of the Programmer's Club! (0 Likes) Printer Friendly Version

Scott Cram
View Profile
Inner circle
2678 Posts

Profile of Scott Cram
Once a year, the Programmer's Club chooses it's president. They don't merely vote on the president, however. Instead, they choose their president by means of a very specific programming challenge. Here's the challenge, so you can determine whether you're up to presidential standards.

The problem involves three sets of three instructions each:

Instruction Set 1-
B:
0:
1:

Instruction Set 2-
B:
0:
1:

Instruction Set 3-
B:
0:
1:

and a board on which play is recorded:

. . . _ _ _ _ _ _ _ _ _ _ _ _ _ . . .
(The board goes on infinitely in both directions)

Instructions are of the form STOP (ends execution of the program), or contain three elements:

A) An indication of what to record on the playing board. The only possibilities are 1, 0 or B (blank).

B) An indication of which direction to move. One step left or one step right are the only possibilities.

C) An indication of which instruction set (1, 2 or 3) contains the next instruction to be followed.

The instruction 1-R-3, for example, means to record a 1 on the playing field, move one step to the right (R), and then go to board 3 for the next instruction.

The combination of your place on the playing tablet and which instruction board you are on determines the instructions to be followed. You'll note that each of the three instruction boards has a spot marked "B", "0" and "1". If your current location on the playing board is blank, then you follow the instruction after the "B". If the current spot has a 0 in it, then you follow the instruction after the "0". If the current spot has a 1 in it, then you follow the instruction after the "1".

You always start with instruction set 1, and a clear board.

To give a complete example, we'll follow the following set of instructions, and a blank board, so we can see the results:

Instruction Set 1-
B: 1-R-2
0: B-R-3
1: 0-L-2

Instruction Set 2-
B: 1-R-3
0: 1-L-1
1: B-L-3

Instruction Set 3-
B: 1-L-1
0: STOP
1: 1-R-1

Here's our blank playing board, and we'll start in the center. We'll use an bolded line, 0 or 1 to keep track of where we are at any given time:

. . . _ _ _ _ _ _ _ _ _ _ _ _ _ . . .

Our first spot is blank, and we're in instruction set 1. Instruction set 1-B says, "1-R-2". So, we place a 1 in that spot, move one square to the right, and we're going to then follow instruction set 2. Here's the board at this point:

. . . _ _ _ _ _ _ 1 _ _ _ _ _ _ . . .

We're on a blank now with instruction set 2. Instruction set 2-B says, "1-R-3". We're placing a 1 in that spot, moving a square to the right, and following instruction set 3. Here's the new board:

. . . _ _ _ _ _ _ 1 1 _ _ _ _ _ . . .

We're on a blank now with instruction set 3. Instruction set 3-B says, "1-L-1". We'll place a 1 on that spot, move one square left, and then follow instruction set 1:

. . . _ _ _ _ _ _ 1 1 1 _ _ _ _ . . .

Now that you're beginning to get the idea, we're going to move a little quicker. Instruction set 1-1 says, "0-L-2", so here's the effect:

. . . _ _ _ _ _ _ 1 0 1 _ _ _ _ . . .

Instruction set 2-1 says, "B-L-3", so here's the effect of that instruction:

. . . _ _ _ _ _ _ _ 0 1 _ _ _ _ . . .

Instruction set 3-B, "1-L-1", gives us:

. . . _ _ _ _ _ 1 _ 0 1 _ _ _ _ . . .

Instruction set 1-B, "1-R-2", gives us:

. . . _ _ _ _ 1 1 _ 0 1 _ _ _ _ . . .

Instruction set 2-1, "B-L-3", gives us:

. . . _ _ _ _ 1 _ _ 0 1 _ _ _ _ . . .

Instruction set 3-1, "1-R-1", gives us:

. . . _ _ _ _ 1 _ _ 0 1 _ _ _ _ . . .

Instruction set 1-B, "1-R-2", gives us:

. . . _ _ _ _ 1 1 _ 0 1 _ _ _ _ . . .

Instruction set 2-B, "1-R-3", gives us:

. . . _ _ _ _ 1 1 1 0 1 _ _ _ _ . . .

Instruction set 3-0, "STOP", tells us that we've reached the end of the program.

The success of any effort is measured by the longest string of consecutive 1s (ones) on the playing board after the program has ended. In the above example, this program would score 3, because the longest string of 1s (ones) is three 1s (ones) long.

The position of president of the Programmer's Club is now up for grabs, and you have your shot. You must write a program that generates the longer finite series of ones than anyone else (and, obviously, higher than the example score of 3). How high a score can you get?

Remember, you always start with instruction set 1 and a blank slate. Also, the series must be finite, and no counting of strings takes place until the program ends.
The Magic Cafe Forum Index » » Puzzle me this... » » King (er, President) of the Programmer's Club! (0 Likes)
[ Top of Page ]
All content & postings Copyright © 2001-2024 Steve Brooks. All Rights Reserved.
This page was created in 0.03 seconds requiring 5 database queries.
The views and comments expressed on The Magic Café
are not necessarily those of The Magic Café, Steve Brooks, or Steve Brooks Magic.
> Privacy Statement <

ROTFL Billions and billions served! ROTFL