My python one-liner scramble generator

If I do that on C++, does the count have to include the includes and the "void main" or only the line?

The line is as follows:
for(int i=25;i;i--)printf("%c%c ","UDFBRL"[rand()%6]," 2'"[rand()%3]);

(70 chars)

output :
B' R2 B2 D2 L2 U' F' U R2 F D2 F R' F2 D' F2 L U' L2 U2 F' B U D2 L
This wouldn't quite work. There is no provision in your code to prevent sequences such as R R or R L R.

Someone should start an official scrambler programming contest.
I don't know about official, but this topic was a pretty decent contest.
 
Someone should start an official scrambler programming contest.

Here's my pathetic attempt in Ruby:


m= ["R", "U", "D", "B", "F", "L"]
x = [" ", "2 ", "' "]
o = 0
d = 0
while d < 26
n = m.at(rand(6))
if n != o
print n
o = n
print x.at(rand(3))
d = d + 1
end
end


148 characters.


Doesn't work..
U' D' F' L2 F2 D2 R' D2 U2 D' F D L B D' R B' D' R L B R2 L2 B' F B'

And it doesn't allow R as the first move if I'm right :)
 
Doesn't work..
U' D' F' L2 F2 D2 R' D2 U2 D' F D L B D' R B' D' R L B R2 L2 B' F B'

And it doesn't allow R as the first move if I'm right :)

Blah. I'm bad at programming. I shortened all the variables, so now I can't even understand how it works.

But it can start with R, I don't know where you got that idea.


EDIT:

http://codepad.org/7EHN0e5M

This appears to solve the problem, but it seems too good to be true...
 
Last edited by a moderator:
Blah. I'm bad at programming. I shortened all the variables, so now I can't even understand how it works.

But it can start with R, I don't know where you got that idea.


EDIT:

http://codepad.org/7EHN0e5M

This appears to solve the problem, but it seems too good to be true...

True, it didn't solve any problems

Because of this line:
if n != o
you claim o=0 in the beginning, so n cannot be 0 for the first run, therefore you'll never get position 0 (R move) for the first move


This is my attempt to save your code:

Code:
m,x=["R","U","B","F","D","L"],[" ","2 ","' "]
a=b=c=d=6
while d<31
a=rand(6)
if a!=b&&!(a==c&&b+a=5)
print m.at(a)+x.at(rand(3))
c,b=b,a
d+=1
end
end
 
Code:
b=c=d=6
while d<32
if (a=rand 6)!=b&&!(a==c&&b+a==5)
$><<%w[R U B F D L][a]+[" ","2 ","' "][rand 3]
c,b=b,a
d+=1
end
end

Just a few mins on it.
 
This wouldn't quite work. There is no provision in your code to prevent sequences such as R R or R L R.
Right.

Fixed solution:
for(int i=25,t=6,k;i;(k=rand()%6)-t&&t%2-1|k-t+1&&printf("%c%c ","UDFBRL"[i--,t=k]," 2'"[rand()%3]));
101 chars.

I wanted to write on pure C, but cout makes it shorter:
for(int i=25,t=6,k;i;(k=rand()%6)-t&&t%2-1|k-t+1&&cout<<"UDFBRL"[i--,t=k]<<" 2'"[rand()%3]<<" ");
97 chars

L after R is possible but R after L isn't. Each L->R move can be shown as R->L, and we avoid R->L->R.
 
Last edited:
Code:
b=c=d=6
while d<32
if (a=rand 6)!=b&&!(a==c&&b+a==5)
$><<%w[R U B F D L][a]+[" ","2 ","' "][rand 3]
c,b=b,a
d+=1
end
end

Just a few mins on it.

Code:
a=b=d=6
while d<32
c,b=b,a
while c+b==5&&a==c||a==b:a=rand 6;end
$><<%w[R U B F D L][a]+[" ","2 ","' "][rand 3]
d+=1
end
(120 chars) damn... same number of chars :(
 
Last edited:
Because of this line:
if n != o
you claim o=0 in the beginning, so n cannot be 0 for the first run, therefore you'll never get position 0 (R move) for the first move

Is that some weird Ruby stuff I don't know? I'd say n=m.at(rand(6)) never gets you n=0, just n="R". So that shouldn't be a problem.
 
I think so, because my original code generated scrambles beginning with R on multiple occasions.
 
Is that some weird Ruby stuff I don't know? I'd say n=m.at(rand(6)) never gets you n=0, just n="R". So that shouldn't be a problem.

I think so, because my original code generated scrambles beginning with R on multiple occasions.

I'm no good at Ruby :( Ruby is retarded xD I'was god damn sure that rand(6) generated 0-5 -.-' (I generated like 30 scrambles without a leading R move :O )


EDIT:

Chen Shuang:
Your distribution is wrong..
Code:
U->L=25%
D->L=20%
 
Last edited:
Its algorithm can be describe as:
generate random moves
and then check it, let RR->R, LL->L, RL->LR, and UD, FB as well
is it really wrong?
 
Its algorithm can be describe as:
generate random moves
and then check it, let RR->R, LL->L, RL->LR, and UD, FB as well
is it really wrong?

I'm pretty confident that I'm right. But I'm already looking for a place to hide when you prove me wrong.

(a=rand 6)!=b&&a!=b+3

same as:
a!=b and a!=b+3

well, a!=b is obvious..

a!=b+3 can be described like this:
setA=[U,R,F], setB=[D,L,B]
then we have: setA[x]+3=setB[x], where x is the position.
but setB[x]+3 != setA[x].... (as 5+3 != 2)
this means that for any moves in setA, there is 4 valid next-moves, but for setB we have 5.

The goal for the scrambles is to have:
5 valid moves, unless we have just had two opposite moves in a row, then it should be 4
 
Last edited:
why should valid moves of setA be the same as of setB
if we only allow "LR" but disallow "RL", of course setA is difference to setB...
 
Imagine you have the move R

R doesn't allow the next move to be L, therefore you can't get RL.. (RL is not converted to LR) (which leaves 4 valid moves only)

now take L

L does allow the next move to be R... (5 valid moves, YAY!! :D)
 
Last edited:
Another Python code(prevents R R' or R L)

I know the code doesn't suit the title and it is slightly long, but my purpose was to avoid Cancellation moves.
Here is my code (Python 2.7)

Code:
import random                                                                   

no=input("Input the number of scrambles you require.")                          
length=input("Input the length of the scramble.")                               
scramble=''

set_1=[" R"," R'"," R2"," L"," L'"," L2"]                                       
set_2=[" F"," F'"," F2"," B"," B'"," B2"," U"," U'"," U2"," D"," D'"," D2"]     

for i in range(no):                                                             
    scramble= scramble + '('+str(i+1)+')'
    for i in range(length):                                                     
        if i%2 == 0:                                                            
            scramble=scramble + random.choice(set_1)
        else:
            scramble=scramble + random.choice(set_2)
    print scramble                                                              
                                                                                
    print "\n"                                                                  
    scramble=''


Output:
Code:
(1) L2 D' L2 B' L U2 L' U L2 U2 R' F2 R2 D2 R' U2 R U2 L' D' R' F2 R' F2 L'
(2) L2 U' R2 U2 R' B' R2 F2 L' F L' F' L' B L2 U2 L2 B L' F R2 D2 L2 D R2
(3) L F2 L' U' R' B2 L F2 L B2 L U L' D2 R' D' R' U2 R F2 R U R2 F2 R'
(4) R2 F2 R2 U' R U2 L2 B R2 B R B R F2 R' F R2 D' L B' R F2 L B2 R
(5) L F R D R D L D' R' B2 R2 F R2 U2 R D2 L' U' R' U R2 B' R2 U' L'
 
Back
Top