My python one-liner scramble generator

- the program has to give a sequence of 25 letters chosen randomly amogn RFULBD,
- each letter appears with an "exponent" chosen ramdomly among 1,2,3: that is, for instance R may appear as R, R2 or R',
- consecutive letters cannot be the same
- if R follows L, the next letter cannot be L again (and similarly for the other opposite letters in whatever form they appear).

that's it.

and how does the computer find out how the cube looks like after any given scramble?
 
@Charles: I think you might've missed the point. We're not trying to write a nice or practical scrambler, we're just trying to minimize the code.

@guzman: note that the bold brackets are in fact neccessary.
Code:
if([B]([/B]$b-$m=rand()%6[B])[/B]&($c+$b-5|$c-$m))
I was kind of puzzled why my code didn't work until I found out that you were the one who removed those. :)
 
@Charles: I think you might've missed the point. We're not trying to write a nice or practical scrambler, we're just trying to minimize the code.

I understand that, but I'd still like to know how I'd make the PC find the current state of the cube, and... well, this thread has quite a few programmers who could probably explain it.
 
I understand that, but I'd still like to know how I'd make the PC find the current state of the cube, and... well, this thread has quite a few programmers who could probably explain it.

You would have a set of data representing the current state of the cube, starting with a solved state. You can then manipulate the set of data going through every move and modifying the cube's current position based on what you have defined each move to do. Then you can just take that data set and translate it to a graphical thingy if you want.
 
... now it's 121.
Code:
<?for($i=$b=$c=0;$i<25;$M="URFBLD 2'")if(($b-$m=rand()%6)&($c+$b-5|$c-$m)){$c=$b;echo$M[$b=$m].$M[rand(6,8)].' ';$i++;}?>

One last dirty trick and we can reach 120 or 116 without tags:
Code:
for($i=$b=$c=0;$i<25;$M="URFBLD 2'")if(($b-$m=rand()%6)&($c+$b-5|$c-$m))echo$M[$b=$m].$M[rand(6,8+0*$i++*$c=$b)].' '

the trick is:
rand(6,8+0*$i++*$c=$b)

this removes the need for {} in the 'if' and some commas

Edit: we fixed an error in the next posts
 
Last edited:
You would have a set of data representing the current state of the cube, starting with a solved state. You can then manipulate the set of data going through every move and modifying the cube's current position based on what you have defined each move to do. Then you can just take that data set and translate it to a graphical thingy if you want.

this sounds memory/processor hungry. XD

edit: rethinking this; would it be possible to generate a random position for the cube and then find an "algorithm" to solve it, and display the inverse? if so, how do you fix parity?
 
Last edited:
the trick is: rand(6,8+0*$i++*$c=$b)
Wow, man, amazing. It's quite a dirty piace of code alright, but it is shorter and it works.
And this way you could leave out the semicolon at the end, too! php is a real b**** when it comes to semicolons.
 
Last edited:
edit: rethinking this; would it be possible to generate a random position for the cube and then find an "algorithm" to solve it, and display the inverse? if so, how do you fix parity?

Sure, it's possible. Way harder then just generating a scamble and visualizing it though.
 
by "easy" I mean that you can just write in your code the effect of each move (no algs, just wirecoded permutations).
I see.

But I'm very sorry to say that the latest version doesn't work, it gives invalid scrambles time to time. Dunno why.
The one before your "dirty trick" can be found here: http://kerulo.uw.hu/miniscr/miniscr.php
It does seem to be alright, but who knows? Maybe I just haven't run through enough scrambles.
 
It does seem to be alright, but who knows? Maybe I just haven't run through enough scrambles.

:(
We pushed it too far ... Could it be the initialization of M inside the for ?
What kind of error does it make ?
letter repetition: as in R' R2
or
opposite letters error: R2 L R'
 
Back
Top