Updates to 2006/sykes1

Add alt code based on author's remarks.

Add try.sh along the lines of most the others.

Some of the README.md has been formatted. More has to be done another
time.

Add the video file of the cube being solved in case that video is also
lost (like the previous one was).

The pdf file I had added was incomplete. For some reason it was only one
page, not the full document. This has been fixed.

When I can do the README.md file that should complete the entry though
it's possible other issues will be found at that point.
This commit is contained in:
Cody Boone Ferguson committed 2023-11-23 07:21:58 -08:00
1 parent 8dffa154bc
commit d3c9386673
7 files changed
+202 -22

No files matched your search

+4
View File
@@ -2,3 +2,7 @@ sykes1
sykes1.html
sykes1.orig
prog.orig
sykes1.out
sykes1.alt.out
sykes1.alt
sykes1.alt.html
+9 -2
View File
@@ -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}
+26 -20
View File
@@ -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 <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
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
Binary file not shown.
Binary file not shown.
+94
View File
@@ -0,0 +1,94 @@
/* <body bgcolor = 0 >
<img src= cube.gif><!-- */
#define _ ] [ /* ; ; ; ; */
#include <string.h> /* ; ; */
#include <stdio.h> /* ; ; ; */
#define K(o,O) L o=0; o<O ; o++)
#define H unsigned long long
#define /* ; ; ; ; ; ; } */ W ]=
#define /* ; ; ; ; ; ; */ L for(
#define /* ; ; ; ; ; ; */ J if (
#include <stdlib.h> /*; ; ; ; */
#define Z (j*3+j/9*3+2)%10+j/9*9
int s[ ] = { 187, 94, 402, 3098
,1047 , 122 , 1082 , 3083 , 1039
, 569 , 527 , 1054 , 531 } ;
#define P( o , O ,l) K(C,o)\
fputc ( ( O )[ C ] -l, G);
#define Y strncpy( /* */
int j,k,l,v,c,C,O[64],n[
64],*o,q[13 _ 13],u,d,f,g[
W{ 8,7,6,6,6,6 } ; H p [13 _
#define M memset(E[c]+j*298+v\
*a+88-u*5+586*( u*5+152-i/16*a+C
13 _ 432],r,w,t,b,S[13]; FILE*G;
char E[13 _ 168840],*A="||||||",
*D=" { ; wb; aa; aaaa}a \
0z00Zzz} { z0z} ",Q[64 _ 60
],*F ="+ +",T [43]; int main(
int I,char**V){ int i,h,B,a,m; H
#define R(z){ x=h=0; K(j,27)h|=\
(c>> j&1 )<<z ; ; ; } c=h; ; ; ;
x; J I>1)B=C=atoi(V[1]); J !d)K(
v,13){ h=s[v]; J B<0){ k=h>>18
^h&511; h^= k<<18|k; C=-C; }
K(k,7){ J k==4)R(Z)R(j+(j-
" /@"[j/9]+38)/3*6-6)K(l
,4){ R(Z)K(a,9) x|=((H)c
>>a*3&7)<<a*4 +a/3*4; K(a,
96){ m=a-37; r=m<0?x>>-m:x<<
m; J!(x!=(m<0?r<<-m:r>>m)||r&r
/2&0x888888888888888ULL||r&r>>4&
0xF000F000F000ULL)){ p[0 _ v _ q
[v _ 0]++W r; K(j,q[v _ 0]-1)J p
[0 _ v _ j]==r)q[v _ 0]--; } } }
} } h=d; x=w; m=q[f _ h]; a=f; u
|=1<<a; B=u; K(i,m){ w|=S[a W p[
d _ a _ i]; r: d++; v=*s; t=w; L
j=1; j<13; j++){ J u>>j&1^1){ b=
c=k=0; l=q[j _ h]; L; k<l; k++){
r=p[h _ j _ k]; J!(w&r))b|=p[d _
j _ c++W r; } J!c) goto n; J c
==1){ w|=S[j W b; u|=1<<j; J
d==12){ J--C<1){ K(c,64)O[
c W-1; x=0; K(c,13){ r=~
0; K(j,13)J S[j]<r&&S[j]
>x)r=S[j]; K(i,64){ n[i W-
1; memset(Q[i],32,59); } K(i
,64){ J r>>i&1)O[i W n[i W c ;
K(j,2){ o=j?O:n; k=o[i]; u=i&d ;
v=i&3; a=48; J k+1){ C=k==c; Y T
,"+----+/ /|+----+ || | +\
| |/+----+",43); J!C&&v&&o[i-
1]==k)T[6 W T[21 W T[29 W 32 ; J
u&&o[i-4]==k){ Y T,C?"//////":F,
6); J v==3||o[i-3]<0)T[d W T [20
W C?47:32; } J i&a&&o[i-16]==k){
J u==d||o[i-d]<0)Y T+36,C?A:F,6)
; J!C)J v==3|| o[i-15]<0) T[35 W
32; } J C){ Y T+7,"////",4); T
[19 W T[27 W 47; Y T+22,A,4)
; Y T+30,A,4); } K(C,6)Y Q
[9-i/16*3+u/2+C]+v*5-u/2
+j*30+g[C],T+"06=EMT"[C]
-a,20-g[C]-g[5-C]); K(C,a)
{ M)+28,m=k+33,h=20); M+h)-h
,k+49+u/4*16,a); } K(C,h){ M)-
C,k+17,a); M)+a-C,m,C); M+a)+28,
m,h-C); } } } } K(i,21)puts(Q[i]
); x=r; } G=fopen("cube.gif", D+
11); P(13,"qspbc\213t,J+ **",42)
K(i,8)P(a,D,h+" H Zbjm "[i]+C)P(
19,"F$0sjyxhfujWSU(&%%%",37)K(i,
13){ P(19,"K#.3 ***V****t,J+*1",
42)K(j,1340){ P(2," !",161)P(126
,E[i]+j*126,0)}P(3+i/d,"!\241 ["
,32 ) } exit(0); } goto n; }else
goto r; } J c<v) { f=j; v=c; }
q[j _ d W c; t|=b; } } J!~t)
main(0,0); n:u=B; w=x; d=h
; } u^=1<<a ; } /*--> */
+69
View File
@@ -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