Page 1 of 26 12311 ... LastLast
Results 1 to 10 of 253

Thread: My python one-liner scramble generator

  1. #1

    Default My python one-liner scramble generator

    274 bytes
    its a world record, I guess. (until someone do it on perl...)
    Code:
    c,a,l,f,g=__import__('random').choice,['FB','UD','RL'],[],lambda y:lambda x:x in y,lambda y:lambda x:x not in y;h=[l.append(c(filter(g(l[-1:]),c(filter(g(filter(f(a),[''.join(l[-2:][::x]) for x in [-1,1]])),a))))) for u in range(25)];print ' '.join([h+c(" '2",) for h in l])
    It works. copy and paste onto python interpreter. Or save it on a .py file.
    You could also tweak it to generate a lot of scrambles:

    just put a
    Code:
    for n in range(12):
    in the beggining,
    and in DOS do:

    Code:
    scramble.py > output.txt
    result:

    file: output.txt
    ---------------------------------------------------------------------------------------
    R' U2 D' L' R' D2 R2 U F B L' U B D F U' F' L' B' F' L' U2 D' R D2
    B' U2 D2 F L R B' U2 D F' R F' R' B' F' R L2 D' B F D U R2 L2 U2
    D2 U2 F L2 D F B' U D F B L' R' U' D' R2 F L2 D' U2 L2 B' R F U
    L B' D U2 R2 B2 F' D' U2 L' F' B U' D F2 L' R B2 F2 U' D L' B U L'
    F' U2 F2 B2 D' U L U2 B L B2 R F D2 R' U B2 L2 R' U2 D2 B U' L U
    D U2 F U B2 L2 R U D2 R' U F' U L2 R B2 F' U R' D' B F' L' U L
    R D2 U' R' F R L2 U' F' U' D' L2 D' B2 U' D' L R F2 D U2 F' B2 R L
    D2 U' R U' L R F U' D R' U' F D R2 B' R' B2 R F' B2 U B F' L' U2
    D2 U2 F B2 L' R2 U L2 U2 L2 D B' F U D' F B' D' U B' F' L D L' B'
    D U' L' D' U' F' D' U2 L' R' B D2 F' B' L F' R' L2 F R U R B2 F U


    EDIT:
    Code:
    from random import*;c=choice;w,l=['RL','UD','BF'],[]
    for u in range(25):
     a=c(w)
     if sum([ord(x) for x in l[-2:]]) in [158,153,136]:
      while l[-1] in a:a=c(w)
     t=c(a)
     while l[-1:]==[t]:t=c(a)
     l=l+[t]
    
    print ' '.join([x+c(" '2") for x in l])
    ============================================
    
    from random import*;c=choice;w,l=['RL','UD','BF'],[]
    def k():
     m=[y.replace(l[-1],'') for y in w] if l[-1:] else w
     h=[int(''.join(l[-2:]) in [x,x[::-1]]) for x in w]
     if 1 in h:m.pop(h.index(1))
     return m
    
    for u in range(25):
     l.append(c(c(k())))
    
    print ' '.join([x+c(" '2") for x in l])
    first is 242 chars but is brute force.
    second is 288 chars but is more pythonic.
    Last edited by towwdso; 11-12-2010 at 12:50 PM.

  2. #2
    Member Zarxrax's Avatar
    Join Date
    Jan 2009
    Location
    North Carolina
    Posts
    1,227

    Default

    Technically, looks like about 3 lines
    I need to learn some python so I can understand this.
    Single: 15.43; Avg5: 21.20; Avg12: 23.10

  3. #3
    Member qqwref's Avatar
    Join Date
    Dec 2007
    Location
    a <script> tag near you
    WCA Profile
    2006GOTT01
    YouTube
    qqwref2
    Posts
    6,335

    Default

    That's kind of horrible looking, and I'm not sure 275ish characters counts as a single line, but nice job.

    EDIT: hey, since you're only using d once, could you do this?:
    Code:
    c,a,l,f,g=__import__('random').choice,['FB','UD','RL'],[],lambda y:lambda x:x in y,lambda y:lambda x:x not in y;h=[l.append(c(filter(g(l[-1:]),c(filter(g(filter(f(a),[''.join(l[-2:][::x]) for x in [-1,1]])),a))))) for u in range(25)];print ' '.join([h+c(" '2") for h in l])
    Last edited by qqwref; 11-10-2010 at 06:34 PM.
    Computer cube PB averages of 12: [Clock: 5.72] [Pyraminx: 3.44] [Megaminx: 49.52]
    [2x2: 2.66] [3x3: 8.71] [4x4: 29.06] [5x5: 52.69] [6x6: 1:34.78] [7x7: 2:20.34]

  4. #4
    Super-Duper Moderator Lucas Garron's Avatar
    Join Date
    Jul 2007
    Location
    Where the rolling foothills rise
    WCA Profile
    2006GARR01
    YouTube
    LucasGarron
    Posts
    2,833

    Default

    Quote Originally Posted by towwdso View Post
    its a world record, I guess. (until someone do it on perl...)
    Or Mathematica.

    Code:
    StringJoin[ToString[#]<>(c=RandomChoice)[{" ","' ","2 "}]&/@(Flatten[RandomSample[#,Ceiling[Random[]*5/4]]&/@c[{{U,R},{F,B},{L,D}},25]]//.{a___,b_,b_,c___}:>{a,b,c})]
    167 chars, still not tweetable. But I'm sure I could get it there, and coders like Stefan, Kociemba, or Rokicki could probably destroy us.
    garron.us | cubing.net | twisty.js | ACube.js | Mark 2 | Regs | Show people your algs: alg.garron.us

  5. #5
    Administrator
    Join Date
    Apr 2008
    Location
    Buffalo, NY
    WCA Profile
    2007JAME01
    YouTube
    rubiksmaster12
    Posts
    984

    Default

    Quote Originally Posted by towwdso View Post
    until someone do it on perl...
    120 chars.

    Code:
    map{while(($m=int rand 6)==$b||($c+$b==5&&$c==$m)){}print qw(U R F B L D)[$m].qw( ' 2)[int rand 3]." ";$c=$b;$b=$m}1..25
    But yeah, like Lucas said, I'm sure there's a bunch of people who could destroy this, since mine is pretty basic.

    Edit: 115

    Code:
    map{$m=int rand 6while$c+$b==5&&$c==$m||$m==$b;print qw(U R F B L D)[$m].qw( ' 2)[int rand 3]." ";$c=$b;$b=$m}1..25
    >_>
    Last edited by PatrickJameson; 11-10-2010 at 10:43 PM.
    Team #
    SO BIG
    dfdsfd

  6. #6
    Member VP7's Avatar
    Join Date
    Aug 2008
    Location
    Ohio
    Posts
    67

    Default

    Is this open to all languages ?
    My 2nd line of signature space is up for rent.

  7. #7

    Default

    @qqref: yes, It was late night, I'll try to optmise the code some more now. mwahaha >
    @VP7: yeah, it would be great too se your code.

    ok guys, I don't have mathemathica or perl installed here (i had), but you know that the code should output a legal scramble right?
    legal scramble: R L' U B U R2 L2 U B' L F2 ... etc
    illegal scramble: U U' U2 U' U B F B F B F B F B2 B' B B B U R L' R R2 R R R R R R R R R R R ... you see what I mean

  8. #8

    Default

    Quote Originally Posted by towwdso View Post
    you know that the code should output a legal scramble right?
    I asked Patrick earlier; he said the scrambles are valid.
    If anyone wants to add me on Guild Wars 2 send me a PM :tu

  9. #9
    Member
    Join Date
    Apr 2007
    WCA Profile
    2007GOUL01
    YouTube
    cardologist
    Posts
    4,298

    Default

    I'm pretty sure Lucas and Patrick know what valid scrambles are :P
    #

  10. #10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •