Online since 2002. Over 3300 puzzles, 2600 worldwide members, and 270,000 messages.

TwistyPuzzles.com Forum

It is currently Wed Jul 23, 2014 5:17 am

All times are UTC - 5 hours



Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Looking for Short Cube Solving programs
PostPosted: Thu Oct 15, 2009 4:22 pm 
Offline
User avatar

Joined: Thu Jan 06, 2005 8:53 pm
Location: Los Angeles
I remember some years ago, there was a contest to write the shortest Rubik's Cube solver you could. The contestants/winners source was posted online somewhere. I was thinking about this the other day, and I want to look through the code.
I'm going to keep looking, but I haven't been able to find them. If anybody knows where they are, could you help me out?

[edit]

Wouldn't you know the next search I did found the page I was looking for?
http://tomas.rokicki.com/cubecontest/


Top
 Profile  
 
 Post subject: Re: Looking for Short Cube Solving programs
PostPosted: Thu Oct 15, 2009 5:14 pm 
Offline
User avatar

Joined: Tue Aug 11, 2009 2:44 pm
Huh, I guess "some years ago" is not as long ago as I thought.

I entered a similar contest in, looks like, 1994. It was sponsored by some computer magazine; I can't remember which one.

My program didn't win, but as I recall it was the shortest. I hadn't quite realized it, I think, but the programs were judged purely on speed. The winner's program was a little faster than mine, but over 10 times as long; it was full of tables. (Note that my program is not at all short by the standards of this newer contest!)

Anyway if anyone wants to see another random C program for solving the cube, here's mine.


Top
 Profile  
 
 Post subject: Re: Looking for Short Cube Solving programs
PostPosted: Thu Oct 15, 2009 5:57 pm 
Offline
User avatar

Joined: Thu Jan 06, 2005 8:53 pm
Location: Los Angeles
Hey, I'm only 25 ... 5 years is 20% of my life 8-)


Top
 Profile  
 
 Post subject: Re: Looking for Short Cube Solving programs
PostPosted: Fri Oct 16, 2009 1:23 am 
Offline
User avatar

Joined: Thu Jan 06, 2005 8:53 pm
Location: Los Angeles
Sorry to double post, but this doesn't need it's own topic.

I was reading through the code for the winner, and I came across this line:
Code:
cubelet[<<stuff>>].twi = (cubelet[<<stuff>>].twi + 2 - i%2) % 3, cubelet[<<stuff>>].twi ^= cur_phase < 2;

(the <<stuff>> section is just a bitwise operator finding which cubie in the array to operate on... I took it out 'cause that made it less readable)

I've just never seen this syntax before in my life, and I have no idea what it's doing.
Can anybody help shed some light on this for me?


Top
 Profile  
 
 Post subject: Re: Looking for Short Cube Solving programs
PostPosted: Fri Oct 16, 2009 2:29 am 
Offline

Joined: Fri Jul 17, 2009 5:32 pm
Location: Tokyo
In your C or C++ textbook of choice, look up "comma operator" and "compound assignment".

(If I gave you any further details, it would be like showing you how to solve the cube and you'd never have a chance to learn for yourself.)

_________________
May the force not be with you.


Top
 Profile  
 
 Post subject: Re: Looking for Short Cube Solving programs
PostPosted: Fri Oct 16, 2009 10:18 am 
Offline
User avatar

Joined: Sat Jul 11, 2009 1:09 pm
Location: My House
I don't have a clue what any of you are saying. :lol:

Alex

_________________
If I had £1,000,000 more, I'd be a Millionaire

YouTube Account: Cubiksrube113


Top
 Profile  
 
 Post subject: Re: Looking for Short Cube Solving programs
PostPosted: Fri Oct 16, 2009 10:51 am 
Offline
User avatar

Joined: Thu Jan 06, 2005 8:53 pm
Location: Los Angeles
ndiamond wrote:
In your C or C++ textbook of choice, look up "comma operator" and "compound assignment".

(If I gave you any further details, it would be like showing you how to solve the cube and you'd never have a chance to learn for yourself.)

Yeah I knew about the xor_eq, I'd just never seen the comma used as an operator before.
Thanks for the point in the right direction.


Top
 Profile  
 
 Post subject: Re: Looking for Short Cube Solving programs
PostPosted: Fri Oct 16, 2009 10:59 am 
Offline
User avatar

Joined: Tue Aug 11, 2009 2:44 pm
In this context there's no reason to use a comma operator; for clarity it should be a semicolon. Usually you see it used in for loops, where you might need to perform multiple side effects in a single expression:

for (int x = 0, char *cp = str; *cp; ++x, ++cp)
...


There are other more obscure uses.


Top
 Profile  
 
 Post subject: Re: Looking for Short Cube Solving programs
PostPosted: Fri Oct 16, 2009 11:55 am 
Offline
User avatar

Joined: Thu Jan 06, 2005 8:53 pm
Location: Los Angeles
In this case, it was used to put two commands in the inside of the loop in one line to save on some {} characters.
Code:
for(...) e1,e2;

rather than
Code:
for(...){
    e1;
    e2;
}


This guy had some very "creative" ways of saving a character or two.
So "creative" that I had to run this thing through the pre-compiler to make it even halfway readable.


Top
 Profile  
 
 Post subject: Re: Looking for Short Cube Solving programs
PostPosted: Fri Oct 16, 2009 12:10 pm 
Offline
User avatar

Joined: Tue Aug 11, 2009 2:44 pm
TBTTyler wrote:
In this case, it was used to put two commands in the inside of the loop in one line to save on some {} characters.

This guy had some very "creative" ways of saving a character or two.
So "creative" that I had to run this thing through the pre-compiler to make it even halfway readable.

Ah... got it. :) In that case I'm surprised at the length of the variable names. Unless that was part of your cleanup too...


Top
 Profile  
 
 Post subject: Re: Looking for Short Cube Solving programs
PostPosted: Fri Oct 16, 2009 12:34 pm 
Offline
User avatar

Joined: Thu Jan 06, 2005 8:53 pm
Location: Los Angeles
The rules say that identifiers and keywords only count as a single character.
Thank goodness, 'cause this was a short cube solving contest, not an obfuscated code contest ;)

This is the kind of stuff he pulled (taken from the code, which can be found here)
Code:
#define SH <<
#define PP = -1; ++
#define _F ;)
#define FOR_i for (int i PP i < __LINE__%21 _F
#define FOR_k for (int k PP k <
#define _E );
#define _G ;}
#define _I [i
#define _Q ){
#define FOR_cur_phase ; for (cur_phase PP cur_phase < 4 _F
#define _48_ [48]
#define Ci12 cubelet _I +12].
#define Ci cubelet _I ].
#define FOR_RET2 ret += ret +
#define _IF if (
#define PA cubelet[64^data[20+cur_phase*8+i
#define PB ]]
#define RRR ; FOR_i FOR_RET2 (Ci pos >
#define INVABA (inva[b[0 PB ^inva[b[
#define H0 hash_table[cur_phase  ][h%q]
#define H1 hash_table[cur_phase+4][h/q]

notice the use of __LINE__ ... he's got a lot of whitespace in his program to take advantage of that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Forum powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group