Stefan
Legend
Not sure if new, but I came up with a neat way to simulate.
Represent the state as a string like
"UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR"
which for those 20 pieces tell their current location. If we do a U turn, we get:
"UL UF UR UB DF DR DB DL FR FL BR BL ULF UFR URB UBL DRF DFL DLB DBR"
This says the first piece (UF) is now at UL, etc.
This can be implemented by changing exactly those locations having the turn name (U)
"UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR"
and cycling all other characters in that cubie location ("U" cycles F->L->B->R->F):
"UL UF UR UB DF DR DB DL FR FL BR BL ULF UFR URB UBL DRF DFL DLB DBR"
So a state is given as such a string, and moves are defined by for example "U"=>"FLBR". It's really easy and natural to implement, no ugly numbers, which is why I find it neat. Could also be used for Megaminx and Pyraminx, for example (edit: darn, I just realized there aren't many people face-turning the pyraminx
).
Here's a Perl program simulating a T perm (also available for playing at http://ideone.com/bbOhtk):
That code prints this:
Represent the state as a string like
"UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR"
which for those 20 pieces tell their current location. If we do a U turn, we get:
"UL UF UR UB DF DR DB DL FR FL BR BL ULF UFR URB UBL DRF DFL DLB DBR"
This says the first piece (UF) is now at UL, etc.
This can be implemented by changing exactly those locations having the turn name (U)
"UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR"
and cycling all other characters in that cubie location ("U" cycles F->L->B->R->F):
"UL UF UR UB DF DR DB DL FR FL BR BL ULF UFR URB UBL DRF DFL DLB DBR"
So a state is given as such a string, and moves are defined by for example "U"=>"FLBR". It's really easy and natural to implement, no ugly numbers, which is why I find it neat. Could also be used for Megaminx and Pyraminx, for example (edit: darn, I just realized there aren't many people face-turning the pyraminx
Here's a Perl program simulating a T perm (also available for playing at http://ideone.com/bbOhtk):
Code:
@moves = qw(R U R' U' R' F R2 U' R' U' R U R' F');
$state = "UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR";
%turns = (U => 'FLBR', D => 'FRBL', R => 'FUBD', L => 'FDBU', F => 'URDL', B => 'ULDR');
sub move {
my ($pos) = @_;
($cycled = $turns{$side}) =~ s/(.)(.*)/$2$1/;
eval "\$pos =~ y/$turns{$side}/$cycled/";
$pos;
}
print "Moves: @moves\nStart: $state\n";
for $move (@moves) {
$move =~ s/'/3/;
($side, $angle) = split //, $move . 1;
$state =~ s/\w*$side\w*/move($&)/ge while $angle--;
}
print "End: $state\n";
That code prints this:
Code:
Moves: R U R' U' R' F R2 U' R' U' R U R' F'
Start: UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR
End: UF UL UB UR DF DR DB DL FR FL BR BL URB UFR UBL ULF DRF DFL DLB DBR
Last edited: