Format and URL fix 2006/sykes1 + add missing pdf
The pdf file is available on the Internet Wayback Machine. It felt like it might be nice to have it stored in the repo instead since the link is technically dead. Some links (besides the pdf one) were dead. One I removed as I'm not sure it has any purpose to have the Internet Wayback Machine archive. Others were fixed (for example a YouTube video was no longer there so I found an alternative). Format fix README.md.
This commit is contained in:
1 parent
2330bee2b2
commit
cc868ba67d
2 files changed
+71
-38
No files matched your search
+71
-38
@@ -1,8 +1,6 @@
|
||||
# Best Assembler
|
||||
|
||||
Stephen Sykes
|
||||
Itäinen koulupolku
|
||||
Kauniainen
|
||||
Finland
|
||||
<https://web.archive.org/web/20160316092728/http://www.stephensykes.com/>
|
||||
|
||||
@@ -28,29 +26,56 @@ Next point your browser to the file: `sykes1.html`.
|
||||
|
||||
Refresh your browser.
|
||||
|
||||
### Also try:
|
||||
|
||||
If you have all day :-) and wish to find out how fast your machine can solve the
|
||||
maximum:
|
||||
|
||||
|
||||
```sh
|
||||
time ./sykes1 19186
|
||||
```
|
||||
|
||||
This was done on a CentOS 7 server with `Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz`
|
||||
with 16 cores (via HyperThreading):
|
||||
|
||||
real 7m48.287s
|
||||
user 7m48.223s
|
||||
sys 0m0.004s
|
||||
|
||||
and done with macOS Ventura with the Max M1 chip:
|
||||
|
||||
real 8m26.466s
|
||||
user 8m23.134s
|
||||
sys 0m2.981s
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
Read the sykes1.html page source.
|
||||
Now then read the C source. Confused? :-)
|
||||
Read the [sykes1.html](sykes1.html) page source.
|
||||
Now then read the C source. Confused? :-) If it's not clear try:
|
||||
|
||||
```sh
|
||||
diff -s sykes1.c sykes1.html
|
||||
```
|
||||
|
||||
For extra credit, understand what happens when you give this entry
|
||||
an negative number argument, and why.
|
||||
|
||||
See the author's remarks for how to make your own shapes as well.
|
||||
|
||||
## Author's remarks:
|
||||
|
||||
This cube shaped program solves the fiendishly difficult "Bedlam Cube"
|
||||
This cube shaped program solves the fiendishly difficult "Bedlam Cube".
|
||||
|
||||
If you did not get one for Christmas, there is an article about these
|
||||
puzzles in wikipedia:
|
||||
If you did not get one for Christmas, there is an [article about these
|
||||
puzzles in wikipedia](http://en.wikipedia.org/wiki/Bedlam_cube).
|
||||
|
||||
> <http://en.wikipedia.org/wiki/Bedlam_cube>
|
||||
Some instructions on how to make your own cube are in the included file
|
||||
[bedlam-cubes.pdf](bedlam-cubes.pdf).
|
||||
|
||||
There is also website dedicated to them - <http://www.bedlampuzzles.com>
|
||||
And some instructions on how to make your own cube here:
|
||||
<http://ch.twi.tudelft.nl/~sidney/puzzles/downloads/bedlam-pieces.pdf>
|
||||
Finally, you can watch it being solved here:
|
||||
|
||||
> <http://www.youtube.com/watch?v=eDpC7oKQJIQ>
|
||||
Finally, you can watch it being solved
|
||||
[here](https://www.youtube.com/watch?v=a8s1AcYMLBc).
|
||||
|
||||
Actually the cube is very hard to do by hand by just trying to fit it
|
||||
together. I have not known anyone to solve it in this way - you would
|
||||
@@ -66,13 +91,13 @@ Compile the program, then test that it works:
|
||||
|
||||
Shortly you should see the first solution pop out on your screen. It
|
||||
shows you how to build the cube piece by piece, rendered in glorious
|
||||
3d ascii.
|
||||
3D ASCII.
|
||||
|
||||
Ascii art is all very well, but you also have a web browser, right?
|
||||
Well, just open the file sykes1.html. This html file is just a copy
|
||||
of prog.c, which helpfully contains an html document that should make
|
||||
the browser display for you a nice animated gif, showing you how to
|
||||
build the cube. Rendered in glorious 3d color.
|
||||
ASCII art is all very well, but you also have a web browser, right? Well, just
|
||||
open the file [sykes1.html](sykes1.html). This html file is just a copy of
|
||||
[sykes1.c](sykes1.c), which helpfully contains an html document that should make
|
||||
the browser display for you a nice animated GIF, showing you how to build the
|
||||
cube. Rendered in glorious 3D color.
|
||||
|
||||
Want to see another solution? Try:
|
||||
|
||||
@@ -83,7 +108,7 @@ Want to see another solution? Try:
|
||||
The program will discard solutions up to the number, and output numbered
|
||||
solution. Refresh your browser window to see the new solution.
|
||||
|
||||
Try some more - there are exactly 19186 solutions to choose from.
|
||||
Try some more - there are exactly `19186` solutions to choose from.
|
||||
|
||||
If you have a fast machine you might try the last solution:
|
||||
|
||||
@@ -107,16 +132,19 @@ int s[ ] = { 186, 94, 1426, 3098
|
||||
|
||||
Each piece is a bitmap, and represents a 3x3x3 cube.
|
||||
|
||||
For instance the first piece is 186 - this is 010111010 in binary.
|
||||
For instance the first piece is `186` - this is `010111010` in binary.
|
||||
Written out like this you can see that it is the cross shaped piece:
|
||||
|
||||
```
|
||||
010
|
||||
111
|
||||
010
|
||||
```
|
||||
|
||||
The other pieces are defined similarly. Most of the rest require more
|
||||
than one layer, such as piece 3 (1426):
|
||||
than one layer, such as piece 3 (`1426`):
|
||||
|
||||
```
|
||||
000
|
||||
000
|
||||
010
|
||||
@@ -124,10 +152,12 @@ than one layer, such as piece 3 (1426):
|
||||
110
|
||||
010
|
||||
010
|
||||
```
|
||||
|
||||
Imagine the two layers on top of each other, and you should see this
|
||||
shape:
|
||||
|
||||
```
|
||||
+---------+
|
||||
/ +----+ /|
|
||||
+-/ /| / |
|
||||
@@ -138,6 +168,9 @@ shape:
|
||||
| | /
|
||||
| |/
|
||||
+----+
|
||||
```
|
||||
|
||||
### Making your own shapes
|
||||
|
||||
The program is in fact a general solver - you can change the shape of
|
||||
the pieces, and provided that a solution is possible, it will be found.
|
||||
@@ -158,7 +191,7 @@ of the pieces.
|
||||
Once those placings are ready, the program recursively checks each
|
||||
combination thereof.
|
||||
|
||||
In order to complete in a reasonable time, care is take to eliminate
|
||||
In order to complete in a reasonable time, care is taken to eliminate
|
||||
any branches that cannot result in a solution. This is done by checking
|
||||
after each placing if all the remaining pieces can be placed somewhere,
|
||||
and that all the free space in the cube can be filled by at least one
|
||||
@@ -166,49 +199,49 @@ viable placing. Also if a piece is found to only have one possible
|
||||
placing, it is placed immediately without invoking a recursive function
|
||||
call.
|
||||
|
||||
Once the solution is found, the ascii and gif representations are
|
||||
Once the solution is found, the ASCII and GIF representations are
|
||||
generated. Care must be taken to render cubes in the right order such
|
||||
that pieces further back are occluded by those in front.
|
||||
|
||||
In the ascii output care must be taken with drawing the edges of each
|
||||
1/64th cube (edges must be removed within each piece). In the gif
|
||||
In the ASCII output care must be taken with drawing the edges of each
|
||||
`1/64th` cube (edges must be removed within each piece). In the GIF
|
||||
this is taken care of by color, which is graded from the back to the
|
||||
front to ensure edge visibility.
|
||||
|
||||
### Notes
|
||||
|
||||
The whole program has just one function - main - which is recursively
|
||||
The whole program has just one function - `main()` - which is recursively
|
||||
called. In fact if you select solution 19186 it will be called exactly
|
||||
159,260,759 times.
|
||||
`159,260,759` times.
|
||||
|
||||
If you pick a number higher than 19186, the program will return a
|
||||
solution but it will be a rotation of one of the first 19186. This is
|
||||
If you pick a number higher than `19186`, the program will return a
|
||||
solution but it will be a rotation of one of the first `19186`. This is
|
||||
because the cross shaped piece fits 48 ways in the 4x4 cube, but only
|
||||
2 of those ways are unique - you can rotate one of those to make any
|
||||
of the other 46. The algorithm used always places the cross piece
|
||||
first, so the first two placings of that piece result in the 19186
|
||||
first, so the first two placings of that piece result in the `19186`
|
||||
unique solutions.
|
||||
|
||||
If you pick a number higher than 460464 (24x19186) the program will
|
||||
If you pick a number higher than `460464` (`24x19186`) the program will
|
||||
return without outputting a solution. If you can wait that long.
|
||||
|
||||
I recommend compiling with the most aggressive optimization options
|
||||
your compiler supports. I find --unroll-loops to be helpful with gcc.
|
||||
your compiler supports. I find `--unroll-loops` to be helpful with gcc.
|
||||
|
||||
The program relies on long long being 64 bits, but has no other special
|
||||
The program relies on `long long int` being 64 bits, but has no other special
|
||||
requirements.
|
||||
|
||||
The program is known to compile and run under gcc and intel cc, as well
|
||||
The program is known to compile and run under gcc and Intel cc, as well
|
||||
as PellesC on Windows.
|
||||
|
||||
### Bugs
|
||||
|
||||
The program is not at all a valid html document, but fortunately
|
||||
browsers have good error recovery and amongst other things will ignore
|
||||
the /* at the beginning, and won't mind the missing html and head tags
|
||||
the `/*` at the beginning, and won't mind the missing html and head tags
|
||||
and the lack of end tags.
|
||||
|
||||
The generated gif is not compressed. This could be argued as an
|
||||
The generated GIF is not compressed. This could be argued as an
|
||||
advantage - at least I don't violate any of those old Unisys patents!
|
||||
|
||||
The pieces aren't really those colors. Unless you make your own.
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user