• Welcome to the Speedsolving.com, home of the web's largest puzzle community!
    You are currently viewing our forum as a guest which gives you limited access to join discussions and access our other features.

    Registration is fast, simple and absolutely free so please, join our community of 35,000+ people from around the world today!

    If you are already a member, simply login to hide this message and begin participating in the community!

My python one-liner scramble generator

campos20

Member
Joined
Dec 26, 2015
Messages
35
Location
Brazil, MG
WCA
2015CAMP17
YouTube
Visit Channel
A while ago I created this one. It's very readable.

Code:
import random

faces = "ULFRBD"
modifiers = ["", "'", "2"]

def random_move():
    """Random face turn."""
   
    face = faces[random.randint(0, 5)]
    modifier = modifiers[random.randint(0, 2)]

    return face+modifier

def same(face1, face2):
    """Checks if two moves are of the same type."""
    return face1[0] == face2[0]

def intersection(face1, face2):
    """Checks if two moves do not intersect.""" # avoiding U D U.

    if face1[0] in "UD": return face2[0] not in "UD"
    if face1[0] in "LR": return face2[0] not in "LR"
    if face1[0] in "FB": return face2[0] not in "FB"

def generate():

    n = 20 # size of the scramble
    scramble = []
    todos = []

    while len(scramble) < n:

        move = random_move()
        flag = True
       
        if len(scramble)>0 and same(move, scramble[-1]): flag = False
        elif len(scramble)>1 and (not intersection(scramble[-2], scramble[-1]) and not intersection(scramble[-1], move)): flag = False
       
        if flag: scramble.append(move)
        todos.append(move)
   
    return " ".join(scramble)

scrambles = 10
for i in range(scrambles):
    print generate()
Sample output.
Code:
R' L' D R2 B R' U D L2 F' U' F L' F' U B U F' D' U2
B F' L2 R2 F2 R' D' B' L' D2 U2 L' U' F B' U' L B2 D' U'
F' R L2 B D' F' D2 B2 D' F L2 F' D2 U' F2 D2 F' R' D' F
U2 L R2 F' U' R F2 U' L B2 D2 R F2 R' U D' B2 F R U'
D' B' U R F2 L2 F' U F2 U2 F B2 R2 D' R F2 U2 F' D R
D R' U2 R2 B2 F D2 R' U' R' L' U2 D2 B L2 D L' R2 D U'
F' U' R2 B2 D2 F L' B' L F2 B2 L' U2 L' B D B2 F D' B
R2 B U2 L' F' L' F D2 B L B2 D' U' R' U R2 L2 U R2 F2
R' L U' R2 B2 U L2 B2 L U' L B' L2 R B D' F2 R' L' U'
F L2 D2 L B' L' B' U2 B' L' D L D' B D2 U2 R2 B D2 R
B D F' R B2 D U R' B' F' L2 B' U R2 L U D' F R' U'
B' L B R L F R2 D' R' U' F U2 L2 R2 B D2 F' U' L' U'
L' F' L' D' B' F' R' U' L2 F D R2 U2 L' R' F2 L' U D' F2
D2 L2 U' L F' U' R U2 D L' D F' U L' F2 D L2 U L D'
L' U' D R2 B' L2 U2 B2 R' F U2 F U' R2 U2 L' F' R B2 D2
B D F2 U' B' R B R F2 R2 U F' D U R F2 R D' R2 U'
B2 D F2 R2 F R U2 D2 F L B2 L2 F B' L2 D' F U' B L2
B' F D U2 F R' L U' R' L D F B L U F2 B D' F2 L
L2 D L2 R' D U2 L F L' R' U2 R' F R' D2 R F L2 U F'
L2 D' R B' D2 B' L F D2 F2 L2 R F U L U2 R F D U
 
Joined
May 24, 2016
Messages
806
YouTube
Visit Channel
python3 megaminx scrambler:

Python:
import random as r;pow = lambda a, b: lambda: r.choice([a,b]);RD = pow('++','--');U = pow("","'");print('\n'.join([' '.join(['R%s D%s' % (RD(), RD()) for i in range(5)]) + " U" + U() for ii in range(7)]))
 

Want to hide this ad and support the community?
Top