My python one-liner scramble generator

Shortened C++ version, 113 chars (not my work) EDIT: wrong.
Code:
for(int c=0,b=0,j=0,m;j++<25;){m=rand()%18;c+b==5&&c==m%6||b==m%6||(cout<<"URFBLD"[c=b,b=m%6]<<" 2'"[m/6]<<" ");}

Wow, 104! And that's my work :D EDIT: wrong.
Code:
for(int c=0,b=0,j=0,m;j++<25;)c==(m=rand()%6)&&c+b==5||b==m||(cout<<"URFBLD"[c=b,b=m]<<" 2'"[m%3]<<" ");

102. So close... EDIT: wrong.
Code:
for(int c=0,b=0,j=0,m;j++<25;)c==(m=rand()%6)&c+b==5|b==m||(cout<<"URFBLD"[c=b,b=m]<<" 2'"[m%3]<<" ");
 
Last edited:
And... 100. :p
Code:
for(int c=0,b=0,j=0,m;j++<25;)c-(m=rand()%6)|c+b-5&&b-m&&(cout<<"URFBLD"[c=b,b=m]<<" 2'"[m%3]<<" ");

EDIT: wrong.
 
Last edited:
1. frankly, I don't know.
2. haha, you're right

So 102. EDIT: wrong again.
Code:
for(int c=0,b=0,j=0,m;j<25;c-(m=rand()%6)|c+b-5&&b-m&&(cout<<"URFBLD"[j++,c=b,b=m]<<" 2'"[m%3]<<" "));
 
Last edited:
There's a mistake:
by setting m=rand()%6
and choosing the suffix for the move with m%3

you'll always have D' or L2 or U or B etc ... but never D or L' or U' or B' ...
'cause it creates a dependence of the suffix on the move
 
Last edited:
How about
Code:
for(int c=0,b=0,j=0,m;j<25;(m=rand()%6)-c|c+b-5&&b-m&&(cout<<"URFBLD"[j++,c=b,b=m]<<" 2'"[rand()%3]<<" "));

I don't get it. (m=rand()%6)-c works, but (m=rand())%6-c doesn't.
 
Nice, qqwref!

This is 106, guzman check please :P
Code:
for(int c=0,b=0,j=0,m;j<25;m=rand(),c-m%6|c+b-5&&b-m%6&&(cout<<"URFBLD"[j++,c=b,b=m%6]<<" 2'"[m%3]<<" "));
 
@joey: theoritically, yes. But ((m=rand())%6)-c gives me Acces violation error message (although INT_MAX is way bigger then RAND_MAX).

@guzman: You're right.
But at least I realised that the ( ) are unneccessary. 105.
Code:
for(int c=0,b=0,j=0,m;j<25;(m=rand()%6)-c|c+b-5&&b-m&&cout<<"URFBLD"[j++,c=b,b=m]<<" 2'"[rand()%3]<<" ");
 
Last edited:
hah I noticed the j++ being incremented everytime too and was like whoops and moved it to inside the [] a hour before marcell posted in all fairness XP.


I think we may be able to save a char or 2 more if instead of initializing c and b we just check if j<2.

also you can't use m%6 and m%3 as if (m%6==0) then(m%3==0) so any time got a U it would have no suffix (same for other 5 letters would all appear with same sufix) so maybe if m can be chosen between the 2?
 
In any normal program that part would be written as:
Code:
cout<<"URFBLD"[m];
j++; c=b; b=m;
Does the same. The expressions separated by commas are evaluated from left to right, and only the last one passes a value about which element of the array to return.
(But correct me if I'm wrong, honestly I never learned C++.)
 
In any normal program that part would be written as:
Code:
cout<<"URFBLD"[m];
j++; c=b; b=m;
Does the same. The expressions separated by commas are evaluated from left to right, and only the last one passes a value about which element of the array to return.
(But correct me if I'm wrong, honestly I never learned C++.)

OOH ok, now I get it. but wouldn't it do the inverse of what you said, like:

Code:
 j++; c=b; b=m;
cout<<"URFBLD"[m];

?
 
Back
Top