-
Notifications
You must be signed in to change notification settings - Fork 26
/
labybox.html
executable file
·115 lines (88 loc) · 5.25 KB
/
labybox.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html>
<head>
<title>Puzzle: Laby Box</title>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<p class="subtle"><a href="/">« Boston Python puzzles</a></p>
<h1>Laby Box</h1>
<p><i>by Sebastian Wernicke</i></p>
<p>The "Laby Box" is an interesting mechanical puzzle. Though formally it's
hard to classify — yes, there are
<a href="http://www.cleverwood.com/mechanical_puzzle_classification.htm">
classification schemes</a> for puzzles — it is fairly simple to describe:</p>
<p><img src="labybox/puzzlebox.jpg" alt="Photo of Laby puzzle box"></p>
<p>In this state, it's not possible to open the box. However, the lid has
five moving elements: two wooden sliders that can
move from left to right, and three pairs of pins that can move up or down.
The pins always move in fixed pairs.</p>
<p><img src="labybox/movement.jpg" alt="Photo of Laby puzzle box parts"></p>
<p>Here's a more schematic view from the top:</p>
<p><img src="labybox/schematic.jpg" alt="Schematic from top"></p>
<p>As you can see in the photos, each wooden slider has a maze-like structure
cut into it corresponding to the black areas in the schematic. The pins go
through this maze structure. Therefore, the wooden sliders and pins cannot move
independently of each other: a movement of a wooden slider might be restricted by
a pin or a pin movement might be restricted by a slider. This is illustrated in
the following examples (keep in mind that the pins are connected as pairs,
so if one of the two paired pins can't move in a certain direction, neither
can the other):</p>
<p><img src="labybox/movement_examples.jpg" alt="Allowed moves examples"></p>
<p>You can also watch a video <a href="https://www.youtube.com/watch?v=1PUvlglM7gs">
here</a> to further illustrate how the box works.</p>
<p>Notice that the lower slider has an opening on the left side. Through
a series of moves on the pins and sliders, it is actually possible to remove
the second slider from the box. The box is very cleverly designed such that
removal of the second slider will actually allow you to open it.</p>
<p><img src="labybox/box_opening.jpg" alt="Opening the box"></p>
<p>Now let's say you are presented with the box in the following configuration:</p>
<p><img src="labybox/starting_configuration.jpg" alt="Starting configuration"></p>
<p>You <i>could</i>, of course, solve this puzzle through logic and patience.
But that's not what we're here for. Rather, let's write a Python program to
do it for us!</p>
<p>To help you get started, here are the two sliders encoded into Python lists,
where 1 represents solid wood and 0 represents a cutout:</p>
<pre>
SLIDER_1 = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
]
SLIDER_2 = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1],
[1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
]
</pre>
<p>1. Write a program that outputs a series of moves/instructions that
get you from the starting configuration to the following target configuration
(where the second slider can easily be pulled out of the box):</p>
<p><img src="labybox/target_config.jpg" alt="Target configuration"></p>
<p>2. Let's call one single motion of a wooden slider or pin a "move"
(no matter how far or where you move that pin or slider). For example,
moving the upper slider, then the middle pin, and then the upper slider
again would count as three moves. What's the minimum number of moves
to get from the starting configuration to the target configuration
of Problem 1?</p>
<p>3. Having solved the secret of the puzzle box, you now want to pose a challenge
to your friend. Since you are devious, you want to put the box back together
into a configuration that will take the most moves to solve, that is,
the hardest initial configuration (because it takes
the most moves to come to a solution). Since you love aesthetics, too, both
sliders must be in their original position, that is, not overlap the box anywhere.
What is this hardest possible configuration? Is it unique?</p>
<h2>Solutions</h2>
<ul>
<li>Andrew Ross's solution is <a href="https://github.com/BostonPython/puzzles/blob/gh-pages/solutions/asross/labybox.py">labybox.py</a></li>
<li>Roderick Bovee's solution is <a href="https://github.com/BostonPython/puzzles/blob/gh-pages/solutions/rbovee/labybox.py">labybox.py</a></li>
</ul>
<p>If you have a solution you'd like to share see the
<a href="solutions.html">Solutions page</a> for instructions.</p>