guzman
Regular
I see the error in mine:
c=b; // then
b=m;
not the inverse.
c=b; // then
b=m;
not the inverse.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
for($i=$b=$c=0;$i<25;$M="URFBLD 2'")if(($b-$m=rand()%6)&($c+$b-5|$c-$m))echo$M[$c=$b*$i++*0+$b=$m].$M[rand(6,8)].' '
Oh that's right. But that's easily solvable by applying the trick eariler
for($i=$b=$c=0;$i<25;$M="URFBLD 2'")if(($b-$m=rand()%6)&($c+$b-5|$c-$m))echo$M[$b=$m+0*$i++*$c=$b].$M[rand(6,8)].' '
116 chars, still longer then your javascript code with all that crazy evaluation stuff.![]()
Yeah. But as for javascript, "math.random" and "document.write" are just painful.
map{$m=int rand 6until($c+$b-5||$c-$m)&&$m-$b;print+(U,R,F,B,L,D)[$m].qw(' 2)[rand 3]." ";$c=$b;$b=$m}1..25
r=Math.random;for(c=b=j=0;j<25;c+b==5&c==m|b==m||document.write("URFBLD"[j++,c=b,b=m]+" 2'"[0|r()*3]+" "))m=0|r()*6
for($i=$b=$c=0;$i<25;$M="URFBLD 2'")if(($b-$m=rand()%6)&($c+$b-5|$c-$m))echo$M[$b=$m+0*$i++*$c=$b].$M[rand(6,8)].' '
StringJoin[ToString[#]<>(c=RandomChoice)[{" ","' ","2 "}]&/@(Flatten[RandomSample[#,Ceiling[Random[]*5/4]]&/@c[{{U,R},{F,B},{L,D}},25]]//.{a___,b_,b_,c___}:>{a,b,c})]
c,a,l,f,g=__import__('random').choice,['FB','UD','RL'],[],lambda y:lambda x:x in y,lambda y:lambda x:x not in y;h=[l.append(c(filter(g(l[-1:]),c(filter(g(filter(f(a),[''.join(l[-2:][::x]) for x in [-1,1]])),a))))) for u in range(25)];print ' '.join([h+c(" '2") for h in l])
More specifically:- 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).
perl: 107
Code:map{$m=int rand 6until($c+$b-5||$c-$m)&&$m-$b;print+(U,R,F,B,L,D)[$m].qw(' 2)[rand 3]." ";$c=$b;$b=$m}1..25
$_.=chr rand 99,/[^URFBLD]|(.)\1|LRL|RLR|UDU|DUD|FBF|BFB/&&chop until/.{25}/;s/./" $&".qw(' 2)[rand 3]/ge;print
$_.=chr rand 99,s/[^URFBLD]|(.)\1|LRL|RLR|UDU|DUD|FBF|BFB// until/.{25}/;s/./" $&".qw(' 2)[rand 3]/ge;print
The following (with 107 bytes) also works, but I'm unsure about the randomness:
Code:$_.=chr rand 99,s/[^URFBLD]|(.)\1|LRL|RLR|UDU|DUD|FBF|BFB// until/.{25}/;s/./" $&".qw(' 2)[rand 3]/ge;print
I'm not actually sure the normal scrambling algorithm does this. Consider 3-move scrambles, ignoring suffixes. The probability of the first two moves being R B and R L are exactly the same (1/30). However, R B can be followed by 5 moves (so each 3-move scramble starting with R B has probability 1/150) but R L can be followed by only 4 moves (so each 3-move scramble starting with R L has probability 1/120). The same thing should happen with more moves.However, if we include in the requirements that every valid scramble must be generated with equal probability
do {
generate random sequence of 25 faces
} until the sequence contains no duplicates or sequences such as RLR
randomly add a suffix after each face
Can anyone write an efficient adaptation of this algorithm (here in pseudocode)?:
Code:do { generate random sequence of 25 faces } until the sequence contains no duplicates or sequences such as RLR randomly add a suffix after each face
do{@a=map{(U,R,F,B,L,D)[rand 6]}1..25}while(join'',@a)=~/((.)\2|LRL|RLR|UDU|DUD|FBF|BFB)/;print$_.qw(' 2)[rand 3]." "for@a
do{$_=join'',map{(U,R,F,B,L,D)[rand 6]}1..25}while/((.)\2|LRL|RLR|UDU|DUD|FBF|BFB)/;print$_.qw(' 2)[rand 3]." "for split//
for(int c=0,b=0,j=0;j<25;){int m=rand()%18;c+b==5&c==m%6|b==m%6||(cout<<"URFBLD"[j++,c=b,b=m%6]<<" 2'"[m/6]<<" ");}
Edit: And another, mixing around a few things. Still 122.
Code:do{$_=join'',map{(U,R,F,B,L,D)[rand 6]}1..25}while/((.)\2|LRL|RLR|UDU|DUD|FBF|BFB)/;print$_.qw(' 2)[rand 3]." "for split//
do{$_=join'',map{(U,R,F,B,L,D)[rand 6]}1..25}while/(.)\1|LRL|RLR|UDU|DUD|FBF|BFB/;print$_.qw(' 2)[rand 3]." "for/./g
(x=y=0..25).map{z=x;x=(w=[%(UD),%(FB),%(RL)][rand 3])[rand 2] until x!=y||(z!=x&&w[y]);(y=x)+"2'"[rand 3].to_s}*" "
p (x=y=0..25).map{z=x;x=(w=[%(UD),%(FB),%(RL)][rand 3])[rand 2] until x!=y||z!=x&&w[y];(y=x)+"2'"[rand 3].to_s}*" "
Using /./g instead of split// and removing the outer parentheses in the regex we get 116 chars.
Code:do{$_=join'',map{(U,R,F,B,L,D)[rand 6]}1..25}while/(.)\1|LRL|RLR|UDU|DUD|FBF|BFB/;print$_.qw(' 2)[rand 3]." "for/./g
do{$_=join'',map{(U,R,F,B,L,D)[rand 6]}1..25}while/(.)\1|LRL|RLR|UDU|DUD|FBF|BFB/;print" $_".qw(' 2)[rand 3]for/./g