2x2 scrambler programming project suggestion

Stefan

Legend
Joined
May 7, 2006
Messages
7,286
WCA ID
2003POCH01
YouTube
Visit Channel
As mentioned in a WCA thread I believe it's possible and fairly easy to create non-canceling 11-moves scrambles for all states of the 2x2. This would allow fast scrambling while preventing giving a clue about short solutions. Anyone capable and interested in verifying/implementing this? I myself dont' have the time right now.

Holding let's say DBL fixed and only scrambling in <U,R,F> leads to 3,674,160 possible states (7! * 3^6), easily allowing brute force.

I'd suggest to first check that it's indeed possible. For that I'd have a field reachable[M] which tells whether state S is reachable in exactly M moves. Init with reachable[solved][0]=true, fill progressively, check that reachable[11] is true for all states S.

This is a one-time research so it doesn't need to be efficient or runnable on all computers. Not like the scramble program for use in competitions. For that, here's a more efficient but still easy approach:

Compute all pairs <state,lastTurnedAxis> reachable from the solved cube in exactly six moves. That's at most 69,984 pairs (9*6^5). This should still be efficient enough even with trivial brute force, and needs to be done just once per program start (or could be precomputed once and stored for reloading). Then for a cube state you want to generate, backwards-compute all pairs <state,firstTurnedAxis> that can reach the desired state in exactly five moves. For each of those, look up a matching pair six moves from solved and ending in a different axis then the finisher-path starts with. The scramble is then the concatenation of the starter path and the finisher path (these paths need to be in some way reconstructable for this, of course, but that's a minore issue and what's best depends on the actual overall implementation).

I don't have time to do it, can anyone else here? The above ideas are just how I would do it without thinking much, it can certainly be done other ways as well, and possibly better. Maybe this could also become the official WCA scrambler, though I think it's also an interesting and rewarding project by itself and it would certainly be very useful for unofficial practice.
 
Last edited:
Create a precalculated look up table having all possible solutions, it will make some megs but not 'that' much. Then you can find the correct solution in no time at all.

EDIT: when thinking about it, you don't need to "find"a solution for a random state to create a scramble, just pick one of the solutions directly from the table by random instead.
 
Last edited:
I think your 'not that much' is still 'too much'. Ok, Cube Explorer uses even larger lookup tables, but the 2x2 is so easy that this would be unnecessary wasteful overkill. Plus where's the fun in lookup tables doing the whole job? I'm envisioning a slim javascript scrambler here. Maybe I'll do a quick-and-dirty proof-of-concept in perl.
 
Actually Cube Explorer already has implemented a table reachable[M] not only for the 2X2 but for the corners of the 3x3 which is 8!*3^7 possibilites and hence 24 times as much as the number of possibilites of the 2x2 cube. Because of reduction by 16 symmetries, this table uses about 1.5 MB and is generated on the fly when starting cube explorer. It is used if you solve incomplete cubes where all corners are defined.
So if there is some interest for a 2x2 scrambler which gives optimal generators (or 11 move generators), it would be easy to implement it.
 
Last edited:
I have ripped up Jaap's 2x2 simulator and modded it into a optimal 2x2 scrambler. To prevent 4 move scrambles from appearing, it has a 9 move lower boundary.
This is not what Stefan asked for, and not even an implementation of his goal.
Your scrambler should either always give 11 moves, or you might as well make it optimal.
Also, you don't use the standard color scheme.

It's written in JavaScript, so it is portable. Currently it randomizes the cube by doing 100 random moves - is this random enough?
No, that's just silly. You should use a randomly generated state (not a shortened "sufficiently long" scramble).
 
Last edited:
I have never claimed to have done exactly what Stefan proposed. I have simply read over the discussion, and I've made what I think the scrambler should be like.

Since the better part of 2x2 scrambles can be solved in nine moves or less, I thought that would be 'the best' lower boundary. If in the discussion it is decided later on that another number would make a better boundary - it is as simple as changing a single number in the source code.

The colour scheme matches that of an ES 4x4 (with the exception of purple) or a Rubik's 3x3. Since most cubes use this scheme I also used this colour scheme. I know that official rubik's 2x2's have a different layout, but there aren't many people using it.

As for the scrambles, you are right. The 100 move thing was an act of lazyness. I guess completely random positions should be fairly easy to implement.
 
I have never claimed to have done exactly what Stefan proposed. I have simply read over the discussion, and I've made what I think the scrambler should be like.
Ah, that's not what I thought you'd meant to do.

Since the better part of 2x2 scrambles can be solved in nine moves or less, I thought that would be 'the best' lower boundary. If in the discussion it is decided later on that another number would make a better boundary - it is as simple as changing a single number in the source code.
Could you upload a separate version with lower bound 0?
And can you also upload one with lower bound 11, to see if it works?

The colour scheme matches that of an ES 4x4 (with the exception of purple) or a Rubik's 3x3. Since most cubes use this scheme I also used this colour scheme. I know that official rubik's 2x2's have a different layout, but there aren't many people using it.
Seems to be working now. When I used it earlier, I saw gray stickers.

As for the scrambles, you are right. The 100 move thing was an act of lazyness. I guess completely random positions should be fairly easy to implement.
:)
(Be careful about the PRNG!)
 
(sorry for the absence)

Looks good, especially the 11 moves version. Is it guaranteed to always find a generator with 11 moves? Or are there cases that can't be done in exactly 11? Maybe Herbert can answer this one...

Since Cube Explorer is already used for competitions, that might be a nice option, too.

Btw, here's a link to the WCA thread about this (of which this thread here is a spin-off):
http://www.worldcubeassociation.org/forum/viewtopic.php?f=4&t=485

What's PRNG anyway?
http://tinyurl.com/5gp47u
 
I am not sure on the 11 move limit. I think if a scramble can be generated in N moves, it must also be generatable in N+M moves.

There would be (3*3)*(2*3)^10 different 11 move scrambles, which means that if the scrambles were distributed evenly, each scramble would have about 150 generators.

Of course this isn't a proof, but there is an easy workaround: set the upper bound to 20, so that if no 11 move generator exists, it will find a generator with more moves. That would take care of the problem. And as it quits searching once a generator is found, it wouldn't present a 12 move generator if a 11 move could be found.

This one begins the search at 11 moves, and ends at 20: http://zandenonline.nl/22scrambler/20upper/

That's a very nice just****ingoogleitwebsite. Damn, I thought PRNG was just some kind of insider's joke.
 
The 2x2x1 has a three moves diameter but only half of all states can be reached in exactly three moves. No idea about the 2x2, though, just proving it's not the case for all puzzles.

About PRNG: There once was a TopCoder competition where input cases were supposed to be generated randomly and they used the Random class which produced significant patterns that really shouldn't have been there, screwing the competition results a lot. SecureRandom would've been better. No idea about JavaScript, but the issue is worth researching if you rely on randomness.

And yeah that googling site is great, I've used it a few times already.
 
About PRNG: There once was a TopCoder competition where input cases were supposed to be generated randomly and they used the Random class which produced significant patterns that really shouldn't have been there, screwing the competition results a lot. SecureRandom would've been better. No idea about JavaScript, but the issue is worth researching if you rely on randomness.
I posted an implementation of CMWC4096 (google it) in Python here:
http://www.speedsolving.com/forum/showpost.php?p=53481&postcount=23

It should be pretty easy to adapt to any other language. The original was implemented in C using bit shifts (very efficient), I ported those using mods, (fast, but not as efficient), but I don't know what is the most efficient way to do that in JS. I also use /dev/urandom to get my pool of seeds, I'm not sure how to do that portably, but I don't really care about programming in anything except Unix.
 
Here is the distribution of the 2x2x2
HTML:
  0                    1              
  1                    9       
  2                   54          
  3                  321   
  4                1,847    
  5                9,992      
  6               50,136   
  7              227,536      
  8              870,072        
  9            1,887,748           
 10              623,800             
 11                2,644
So 11 moves suffice in all cases. I have two more questions concerning an implementation of a scrambler in Cube Explorer. For a random scrambler, is it a good suggenstion to exclude all cases with depth <8 or depth<7 for example ?
The 2x2x2 has no centers. Is there nevertheless any WCA-rule, where for example the position of a certain corner is in the scramble?
 
So 11 moves suffice in all cases.
But can you also tell whether every case can be solved not in "at most" but in "exactly" 11 moves? Because the idea is to always have the same scramble length so that there are no short scrambles hinting at a short solution.

For a random scrambler, is it a good suggenstion to exclude all cases with depth <8 or depth<7 for example ?
This has been discussed a few times (most currently in this current WCA thread), but no, we don't exclude any cases. I hope we'll change that to exclude anything that "counts as solved" (which would mean up to one turn away from solved) in order to prevent confusion, but currently even that would be allowed.

Is there nevertheless any WCA-rule, where for example the position of a certain corner is in the scramble?
The rule is indeed U=white and F=green. And the official scrambler turns only <U,R,F>, leaving the DBL corner fixed (that's not explicitly in the rules, but I recommend adopting it). Have a look:
http://www.worldcubeassociation.org...e.htm?size=2&num=5&len=25&col=yobwrg&multi=on
 
So 11 moves suffice in all cases.
But can you also tell whether every case can be solved not in "at most" but in "exactly" 11 moves? Because the idea is to always have the same scramble length so that there are no short scrambles hinting at a short solution.

I assumed this also meant exactly 11 moves with no trivial redundancies in the scramble, so no consecutive turns of the same layer. (Conventional scramble programs avoided such redundancies.) With less than 4 million total positions, it wouldn't be hard to use a brute force check of all possible positions to verify this. If consecutive turns of the same layer were allowed, you could trivially convert a single turn such a R into two turns such as R' R2, as necessary in order to get the length up to 11.
 
I can't add anything to this topic other than saying I can't think of any way to non-constructively prove that every state has an 11-move generator, but here are some for all positions of distance 1 or less up to symmetry:
identity: R2 U R U R' U' R' U' R' U R'
U: R2 U2 R U2 R2 U F2 U2 F' U2 F2
U': R2 U2 R U2 R2 U F2 U2 F' U2 F2
R2: R2 U R U R' U' R' U' R' U R
:) Good luck guys, this is a really cool idea.
 
Back
Top