Stefan
Member
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):
The variable names mean:
q: queue
a: algorithm
o: old state
n: new state
m: move
The sticker positions are named like this:
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):
[SIZE=-2](back to UWR now...)[/SIZE]
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:
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: