Page 2 of 26 FirstFirst 123412 ... LastLast
Results 11 to 20 of 253

Thread: My python one-liner scramble generator

  1. #11
    Member
    Join Date
    Nov 2006
    Location
    Karlsruhe, Germany
    WCA Profile
    2007HABE01
    YouTube
    cin9247
    Posts
    1,671

    Default

    Ruby (1.9):
    Code:
    turns = [%w{R L}, %w{F B}, %w{D U}]
    axis = rand t.size
    output = (1..25).map do
      axis = (axis + rand(turns.size - 1) + 1) % turns.size
      t[axis].sample + ['', "'", '2'].sample
    end.join(' ')
    
    p output
    That's 199 characters and it's still readable and pretty generic (it can be used to generate scrambles for cubes of all sizes).

    After obfuscating it a bit, i got it down to 111 characters:
    Code:
    a=rand 3
    o=(1..25).map{a=(a+rand(2)+1)%3;[%w{R L},%w{F B},%w{D U}][a].sample+['',"'",'2'].sample}.join(' ')
    p o
    Using p instead of puts is probably cheating, though. And i'm sure anyone who really knows Ruby can get this sub-100. I didn't spend more than a few minutes on it and i only used the most obvious shortcuts (like replacing variable names with its content).

    Quote Originally Posted by towwdso View Post
    sub 277 bytes
    So you mean 276 bytes? Or 275 bytes? Or 200 bytes? Or 142 bytes? WTF? "sub" is really the most overused term amongst cubers. It's so annoying...
    Last edited by tim; 11-11-2010 at 07:29 AM.
    tim's PBs on Cubemania

  2. #12
    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

    tim:

    Doesn't run for me on Ruby 1.8.7, not sure what the exact problem is. But I can't run your code to verify?
    Is your program capable of generating U2 D2 in a row? Ours are, and that's a good part of the challenge. ;-)
    Last edited by Lucas Garron; 11-11-2010 at 08:03 AM.
    garron.us | cubing.net | twisty.js | ACube.js | Mark 2 | Regs | Show people your algs: alg.garron.us

  3. #13
    Member
    Join Date
    Nov 2006
    Location
    Karlsruhe, Germany
    WCA Profile
    2007HABE01
    YouTube
    cin9247
    Posts
    1,671

    Default

    Quote Originally Posted by Lucas Garron View Post
    Doesn't run for me on Ruby 1.8.7, not sure what the exact problem is.
    Yep, you need 1.9 for Array#sample

    Quote Originally Posted by Lucas Garron View Post
    1) Does a actually need to be initialized randomly? Can save 5 bytes that way.
    Yes, otherwise your first move will always be U/D.

    Quote Originally Posted by Lucas Garron View Post
    2) Is your program capable of generating U2 D2 in a row? Ours are, and that's a good part of the challenge. ;-)
    Of course not, since that would make the code longer . Actually i didn't know that's necessary. I might give it another try then.
    tim's PBs on Cubemania

  4. #14

    Default

    Quote Originally Posted by tim View Post
    So you mean 276 bytes? Or 275 bytes? Or 200 bytes? Or 142 bytes? WTF? "sub" is really the most overused term amongst cubers. It's so annoying...
    I meant exactly 277 bytes. I wrote sub 1kb then I checked the atual size and just replaced 1KB with 277 bytes. my fault
    now its 274 bytes actually. it's optimal, from the aproach I did.

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

    Default

    Tim is a noob at ruby.
    #

  6. #16
    Member
    Join Date
    Nov 2006
    Location
    Karlsruhe, Germany
    WCA Profile
    2007HABE01
    YouTube
    cin9247
    Posts
    1,671

    Default

    Quote Originally Posted by joey View Post
    Tim is a noob at ruby.
    tim's PBs on Cubemania

  7. #17

    Default

    I found that generating a single scramble of lenght 25000 is faster than generating 1000 scrambles of lenght 25 by 0.0092000007629999825 seconds. =P

    generating 1000 scrambles times:
    0.766000032425,
    0.781000137329,
    0.75,
    0.81200003624,
    0.75,
    0.81299996376,
    0.75,
    0.796999931335,
    0.765000104904,
    0.827999830246
    generating a single scramble of lenght 25000:

    0.75,
    0.765000104904,
    0.780999898911,
    0.719000101089,
    0.81299996376,
    0.766000032425,
    0.81299996376,
    0.766000032425,
    0.796999931335,
    0.75
    obs: generating a single scramble and divide it later would not allow the second scramble to start with the last face turn.
    example:
    1) U R2 F B
    2) B L2 U' F
    woudn't happen
    Last edited by towwdso; 11-11-2010 at 09:09 AM.

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

    Default

    I tried my hand at JavaScript.

    224 (EDIT: 216) chars:
    Code:
    function r(x){return Math.floor(Math.random()*x)}function s(){var d=b=j=c=a=4;for(;j<29;j++){while(a==c&&(d&b)>0){a=r(3);b=r(2)+1}if(a!=c)d=0;c=a;d+=b;document.write("RLFBUD".charAt(a*2+b-1)+" 2'".charAt(r(3))+" ")}}
    Last edited by qqwref; 11-11-2010 at 11:47 AM.
    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]

  9. #19
    Member vcuber13's Avatar
    Join Date
    Oct 2009
    Location
    Near Toronto
    WCA Profile
    2009METH01
    YouTube
    simpsons36109
    Posts
    2,193

    Default

    i tried to make a scrambler and im doing it in batch because its the only thing i know. so what i have now is it generate a random number and depending on the number assign the move. and i know how to stop it from repeating moves, but i dont know how to repeat it for the 25 moves (i know about goto start, but i need different variables). the only thing i can think of is to repeat the code and change say %move1% to %move2% and so on. then display the scramble as: %move1% %move2% ...
    how can i make it loop but use different variables?
    Official 3x3 Personal Bests: 11.72, 13.88
    Official Square-1 Personal Bests: 13.15 NR, 15.31

  10. #20
    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 tim View Post
    Of course not, since that would make the code longer . Actually i didn't know that's necessary. I might give it another try then.
    I think the distribution actually becomes better if you constantly change axes, but don't quote me on that. And it doesn't change the standard we're trying to match with programs here..
    garron.us | cubing.net | twisty.js | ACube.js | Mark 2 | Regs | Show people your algs: alg.garron.us

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
  •