• 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 40,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!

283 bytes Pyraminx random state optimal scrambler

Stefan

Member
Joined
May 7, 2006
Messages
7,280
WCA
2003POCH01
YouTube
Visit Channel
As suggested by Michael, here's a short random state optimal scrambler for Pyraminx, 283 bytes if written on one line (but I don't like "lines" wider than 80):

Code:
@q=A..X;for($a{"@q"}='';@n=@o=splice@q,0,24;){for$m(UQMNHACDP,LPDEFTVWO
,ROWXSJKMQ,BTFGAHIJS){@m=map{-65+ord}split//,$m.$m;$m=~/./;for('',"'",3
){@n[@m[0..8]]=@n[@m[3..11]];$a{"@n"}//=(push@q,@n)&&$a{"@o"}." $&$_"}}
}@a=values%a;print$a[rand@a],map{rand 3<2?" $_"."'"x rand 2:''}u,l,r,b

The variable names mean:
q: queue
a: algorithm
o: old state
n: new state
m: move

The sticker positions are named like this:
scrambler_pyraminx.png

And here's a more readable version which also shows the progress and total time (admittedly it's slow, preparation takes about three minutes on my laptop) and stores the scramble algorithms in a file (this can be used to test correctness after code changes):

Code:
use Time::HiRes;
my $start = [ Time::HiRes::gettimeofday( ) ];

#--------------------------------------------------------
@q = A..X;
$a{"@q"} = '';
while ( @n = @o = splice @q, 0, 24 ) {
  printf "%6.2f%%\n", $ctr/9331.20 if ++$ctr%1280==0;
  for $m ( UQMNHACDP, LPDEFTVWO, ROWXSJKMQ, BTFGAHIJS ) {
    @m = map { -65+ord } split //, $m.$m;
    $m =~ /./;
    for ( '', "'", 3 ) {
      @n[@m[0..8]] = @n[@m[3..11]];
      $a{"@n"} //= (push @q, @n)
                && $a{"@o"}." $&$_"
    }
  }
}
@a = values %a;
print $a[rand@a],
      map {rand 3<2?" $_"."'"x rand 2:''} u,l,r,b;
#--------------------------------------------------------

my $elapsed = Time::HiRes::tv_interval( $start );
print "\nElapsed time: $elapsed seconds!\n";
      
open OUT, ">algorithms.txt";
for $a ( sort @a ) {
  $a =~ s/^ *//;
  print OUT "$a\n";
}
close OUT;

[SIZE=-2](back to UWR now...)[/SIZE]
 
Last edited:

Stefan

Member
Joined
May 7, 2006
Messages
7,280
WCA
2003POCH01
YouTube
Visit Channel
Isn't it obvious? :p

Straight-forward breadth-first search, mainly. Start with the solved state which is A..X and is generated with algorithm ''. Put it in a queue and then process the queue. Always take one state from the queue, apply all possible moves to it, and put the resulting states you haven't seen before into the queue and store their generating algorithms. At the end, pick one of the generating algorithms and add tip turns.

Or shorter: Compute all possible scrambles, then pick one.
 

Stefan

Member
Joined
May 7, 2006
Messages
7,280
WCA
2003POCH01
YouTube
Visit Channel
282:
Code:
@q=A..Y;for($a{"@q"}='';@o=@n=splice@q,0,25;){for$m(UQMNHACDP,LPDEFTVWO
,ROWXSJKMQ,BTFGAHIJS){@m=map{64^ord}split//,$m.$m;$m=~/./;for('',"'",3
){@n[@m[0..8]]=@n[@m[3..11]];$a{"@n"}//=(push@q,@n)&&$a{"@o"}." $&$_"}}
}@a=values%a;print$a[rand@a],map{rand 3<2?" $_"."'"x rand 2:''}u,l,r,b
Using 25 letters for the state (1-indexed rather than 0-indexed) allowed me to replace -65+ with 64^.
 
Thread starter Similar threads Forum Replies Date
Kirjava Software Area 120
Top