diff --git a/2006/sykes1/.gitignore b/2006/sykes1/.gitignore index 9d0257451..e4c88413f 100644 --- a/2006/sykes1/.gitignore +++ b/2006/sykes1/.gitignore @@ -1,4 +1,9 @@ +cube.gif sykes1 sykes1.html sykes1.orig prog.orig +sykes1.out +sykes1.alt.out +sykes1.alt +sykes1.alt.html diff --git a/2006/sykes1/Makefile b/2006/sykes1/Makefile index 18c926f31..558a2e3ee 100644 --- a/2006/sykes1/Makefile +++ b/2006/sykes1/Makefile @@ -112,8 +112,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} ${PROG}.html # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ${PROG}.alt.html # This entry wants to use -funroll-loops @@ -145,6 +145,13 @@ ${PROG}.html: ${PROG}.c alt: data ${ALT_TARGET} @${TRUE} +${PROG}.alt: ${PROG}.alt.c + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + +${PROG}.alt.html: ${PROG}.alt.c + ${RM} -f ${PROG}.alt.html + cp ${PROG}.alt.c ${PROG}.alt.html + # data files # data: ${DATA} diff --git a/2006/sykes1/README.md b/2006/sykes1/README.md index e0ff55e2c..a692c603b 100644 --- a/2006/sykes1/README.md +++ b/2006/sykes1/README.md @@ -32,21 +32,21 @@ maximum: 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): +This was done on a Rocky Linux 9.2 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 +real 6m35.524s +user 6m35.159s +sys 0m0.002s ``` -and done with macOS Ventura with the Max M1 chip: +and done with macOS Sonoma with the Max M1 chip: ``` -real 8m26.466s -user 8m23.134s -sys 0m2.981s +real 7m10.786s +user 7m8.322s +sys 0m0.110s ``` @@ -75,13 +75,17 @@ puzzles in wikipedia](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). -Finally, you can watch it being solved -[here](https://www.youtube.com/watch?v=a8s1AcYMLBc). +Finally, you can watch it being solved: + +![Bedlam Cube being solved](solving-bedlam-cube.mp4) + +...taken from . 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 need to be very lucky indeed to stumble across a solution. + ### Instructions Compile the program, then test that it works: @@ -119,6 +123,7 @@ If you have a fast machine you might try the last solution: On my machine this takes about half an hour to run. + ### Implementation The implementation is an optimized recursive algorithm that tries to fit @@ -137,22 +142,22 @@ 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 +010 +111 +010 ``` The other pieces are defined similarly. Most of the rest require more than one layer, such as piece 3 (`1426`): ``` - 000 - 000 - 010 +000 +000 +010 - 110 - 010 - 010 +110 +010 +010 ``` Imagine the two layers on top of each other, and you should see this @@ -171,6 +176,7 @@ shape: +----+ ``` + ### Making your own shapes The program is in fact a general solver - you can change the shape of diff --git a/2006/sykes1/bedlam-cubes.pdf b/2006/sykes1/bedlam-cubes.pdf index 4c0166100..bf78bb1e2 100644 Binary files a/2006/sykes1/bedlam-cubes.pdf and b/2006/sykes1/bedlam-cubes.pdf differ diff --git a/2006/sykes1/solving-bedlam-cube.mp4 b/2006/sykes1/solving-bedlam-cube.mp4 new file mode 100644 index 000000000..46afc5df4 Binary files /dev/null and b/2006/sykes1/solving-bedlam-cube.mp4 differ diff --git a/2006/sykes1/sykes1.alt.c b/2006/sykes1/sykes1.alt.c new file mode 100644 index 000000000..0a86db405 --- /dev/null +++ b/2006/sykes1/sykes1.alt.c @@ -0,0 +1,94 @@ + /* + */ diff --git a/2006/sykes1/try.sh b/2006/sykes1/try.sh new file mode 100755 index 000000000..899cfe4e7 --- /dev/null +++ b/2006/sykes1/try.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2006/sykes1 +# + +# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it +# this way allows us to have the user specify a different compiler in an easy +# way. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +make CC="$CC" everything >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +try() +{ + if [[ "$#" -ne 1 ]]; then + SYKES1="sykes1" + else + SYKES1="$1" + fi + + echo "$ diff -s $SYKES1.c $SYKES1.html" 1>&2 + diff -s "$SYKES1".c "$SYKES1".html + echo 1>&2 + + echo "$ ./$SYKES1 | less" 1>&2 + read -r -n 1 -p "Press any key to continue (use 'q' to quit pager, space to scroll a page down): " + ./"$SYKES1" | less + echo 1>&2 + + echo "$ ./$SYKES1 5 | less" 1>&2 + read -r -n 1 -p "Press any key to continue (use 'q' to quit pager, space to scroll a page down): " + ./"$SYKES1" 5 | less + echo 1>&2 + + echo "$ ./$SYKES1 -1 | less" 1>&2 + read -r -n 1 -p "Press any key to continue ('q' to quit pager, space to scroll a page down): " + ./"$SYKES1" -1 | less + echo 1>&2 + echo "What happened and why did it happen?" 1>&2 + echo 1>&2 +} + +read -r -n 1 -p "Press any key to see the entry: " +try sykes1 +echo 1>&2 + +read -r -n 1 -p "Press any key to see the alt version: " +try sykes1.alt +echo 1>&2 + +# clean up output files first +rm -f sykes1.out sykes1.alt.out +read -r -n 1 -p "Press any key to look at output differences of the two: " +echo 1>&2 + +echo "$ ./sykes1 > sykes1.out" 1>&2 +./sykes1 > sykes1.out +echo "$ ./sykes1.alt > sykes1.alt.out" 1>&2 +./sykes1.alt > sykes1.alt.out + +echo "$ diff sykes1.out sykes1.alt.out | less" 1>&2 +read -r -n 1 -p "Press any key to continue (use 'q' to quit pager, space to scroll down a page): " +diff sykes1.out sykes1.alt.out | less +rm -f sykes1.out sykes1.alt.out