## A Story Problem with One Result and Two Solutions

20 03 2013

by Melody Johnson Quilts

An employee stacks five boxes in alphabetical order to produce the following sequence of labeled boxes:

A
AA
B
BB
C

The employee decides to mix things up and removes the bottom three boxes, placing them on top of the other two. If s/he repeats this action three times more which box would be in the middle of the stack?

Solving this story problem supposedly says something about one’s abilities to think logically. Frankly, story problems are unappealing to me. The only way I know to make solving such problems entertaining is to find a programmatic solution. I say let the computer handle such a mundane problem; I would rather save my mind for more interesting challenges. But, as soon as I converted the problem into a programming exercise, the story problem instantly became an intriguing curiosity. I even found two different ways to solve it using PHP, and so I offer them both, as follows:

```<?php
/**
* One Way
**/
function restack(\$array)
{
\$slice1 = array_slice(\$array,0,2);
\$slice2 = array_slice(\$array,2);
return array_merge(\$slice2,\$slice1);
}

\$array = array('A',
'AA',
'B',
'BB',
'C');

for (\$i=0; \$i <= 3; \$i++) {
\$array = restack(\$array);
}
echo \$array[2];  // the middle box

/**
* And, Another
**/
\$array = array('A',
'AA',
'B',
'BB',
'C');

function restack2(\$array)
{
\$spliced = array_splice(\$array,2,3);
return array_merge(\$spliced,\$array);
}
function getResult(\$array)
{
for(\$i=0; \$i<=3; \$i++){
\$array = restack2(\$array);
}
return \$array[2];
}
echo getResult(\$array); // the middle box
```

To date I’ve presented this question to family and friends who intuitively pick ‘B’ as the correct answer. My guess is that they feel so inclined because of the original ordering of the boxes. But, the computer disagrees with that choice. While you might think twice about arguing with a computer, nonetheless, computers are just hunks of hardware running software, both of which require human activity to produce them. Thus, computers are not infallible.

So, who has the correct answer, wo/man or machine? Obviously, this question concerns more than the actual answer. It’s about perceiving a certain kind of constant relationship among the numbers of the items. The specified quantity of the items determines that the middle box will always have two others above it. Each time three boxes change their position the third one always becomes the new middle one, even before we may realize what the two beneath it are. Therefore the the script’s selection of ‘A’ in each solution makes perfect sense in this particular case.