Carrot
Veteran
qqwref: no, just no xD
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.
Alright, I think the normal 3x3 scrambler is getting too easy. Time to make it a little trickier. Here is a *pyraminx optimal scrambler* to try to code-golf. (Written in JavaScript of course.) It's kinda long, you might wanna copy it to Notepad or something before editing.
Code:var j=1,b,mn=11,g=[],f=[],d=[],e=[],k=[],h=[],i=[];function u(){var c,p,q,l,m;for(p=0;p<720;p++){g[p]=-1;d[p]=[];for(m=0;m<4;m++)d[p][m]=w(p,m)}g[0]=0;for(l=0;l<=6;l++)for(p=0;p<720;p++)if(g[p]==l)for(m=0;m<4;m++){q=p;for(c=0;c<2;c++){q=d[q][m];if(g[q]==-1)g[q]=l+1}}for(p=0;p<2592;p++){f[p]=-1;e[p]=[];for(m=0;m<4;m++)e[p][m]=x(p,m)}f[0]=0;for(l=0;l<=5;l++)for(p=0;p<2592;p++)if(f[p]==l)for(m=0;m<4;m++){q=p;for(c=0;c<2;c++){q=e[q][m];if(f[q]==-1)f[q]=l+1}}for(c=0;c<j;c++){k=[];var t=0,s=0;q=0;h=[0,1,2,3,4,5];for(m=0;m<4;m++){p=m+n(6-m);l=h[m];h[m]=h[p];h[p]=l;if(m!=p)s++}if(s%2==1){l=h[4];h[4]=h[5];h[5]=l}s=0;i=[];for(m=0;m<5;m++){i[m]=n(2);s+=i[m]}i[5]=s%2;for(m=6;m<10;m++){i[m]=n(3)}for(m=0;m<6;m++){l=0;for(p=0;p<6;p++){if(h[p]==m)break;if(h[p]>m)l++}q=q*(6-m)+l}for(m=9;m>=6;m--)t=t*3+i[m];for(m=4;m>=0;m--)t=t*2+i[m];if(q!=0||t!=0)for(m=mn;m<99;m++)if(v(q,t,m,-1))break;b="";for(p=0;p<k.length;p++)b+="ULRB"[k[p]&7]+["","'"][(k[p]&8)/8]+" ";var a="lrbu";for(p=0;p<4;p++){q=n(3);if(q<2)b+=a[p]+["","'"][q]+" "}}}function v(q,t,l,c){if(l==0){if(q==0&&t==0)return true}else{if(g[q]>l||f[t]>l)return false;var p,s,a,m;for(m=0;m<4;m++)if(m!=c){p=q;s=t;for(a=0;a<2;a++){p=d[p][m];s=e[s][m];k[k.length]=m+8*a;if(v(p,s,l-1,m))return true;k.length--}}}return false}function w(p,m){var a,l,c,s=[],q=p;for(a=1;a<=6;a++){c=0|(q/a);l=q-a*c;q=c;for(c=a-1;c>=l;c--)s[c+1]=s[c];s[l]=6-a}if(m==0)y(s,0,3,1);if(m==1)y(s,1,5,2);if(m==2)y(s,0,2,4);if(m==3)y(s,3,4,5);q=0;for(a=0;a<6;a++){l=0;for(c=0;c<6;c++){if(s[c]==a)break;if(s[c]>a)l++}q=q*(6-a)+l}return q}function x(p,m){var a,l,c,t=0,s=[],q=p;for(a=0;a<=4;a++){s[a]=q&1;q>>=1;t^=s[a]}s[5]=t;for(a=6;a<=9;a++){c=0|(q/3);l=q-3*c;q=c;s[a]=l}if(m==0){s[6]++;if(s[6]==3)s[6]=0;y(s,0,3,1);s[1]^=1;s[3]^=1}if(m==1){s[7]++;if(s[7]==3)s[7]=0;y(s,1,5,2);s[2]^=1;s[5]^=1}if(m==2){s[8]++;if(s[8]==3)s[8]=0;y(s,0,2,4);s[0]^=1;s[2]^=1}if(m==3){s[9]++;if(s[9]==3)s[9]=0;y(s,3,4,5);s[3]^=1;s[4]^=1}q=0;for(a=9;a>=6;a--)q=q*3+s[a];for(a=4;a>=0;a--)q=q*2+s[a];return q}function y(p,a,c,t){var s=p[a];p[a]=p[c];p[c]=p[t];p[t]=s}function n(c){return 0|Math.random()*c}u();document.write(b);
map{$m=0|rand 6until$c+$b-5|$c-$m&&$m ne$b;$c=$b;print" ".(U,R,F,B,L,D)[$b=$m].qw(' 2)[rand 3]}1..25
the problem is it cannot give scrambles starting with U ...
Perl, pasted just now:
1
map{$m=0|rand 6until$c+$b-5|$c-$m&&$m ne$b;$c=$b;print" ".(U,R,F,B,L,D)[$b=$m].qw(' 2)[rand 3]}1..25
Output:
1
U' F L F' B' D' F2 R F' U' L2 D L U2 F D U L B2 R L' F' B' L B
map{$m=0|rand 6until$c+$b-5|$c ne$m&&$m ne$b;$c=$b;print" ".(U,R,F,B,L,D)[$b=$m].qw(' 2)[rand 3]}1..25
for(int c=0,b=6,j=25,m;j;m-c|c+b-5&&b-m&&cout<<"URFBLD"[j--,c=b,b=m]<<" 2'"[rand()%3]<<" ")m=rand()%6;
$_.=chr rand 99,/[^URFBLD]|(.)\1|LRL|RLR|UDU|DUD|FBF|BFB/&&chop until/.{25}/;s/./" $&".qw(' 2)[rand 3]/ge;print
r=Math.random;for(c=b=j=25;j;c+b-5|c-m&&b-m?document.write("URFBLD"[j--,c=b,b=m]+" 2'"[0|r()*3]+" "):0)m=0|r()*6
$_=join'',map{(U,R,F,B,L,D)[rand 6]}1..25while/^$|(.)\1|LRL|RLR|UDU|DUD|FBF|BFB/;print" $_".qw(' 2)[rand 3]for/./g
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}*" "
for($i=$b=$c=25;$i;$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)].' '
from random import randint as r
m=b=9
for u in range(25):
c=b;b=m
while c+b-4 and m==c or m==b:m=r(0,5)
print "URFBLD"[m]+" '2"[r(0,2)],
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})]
For s = 1 To 25
c = b
b = a
Do While a = b Or a + b = 7 And a = c
a = Int(Rnd * 6 + 1)
Loop
t.Text = t.Text & Mid("URFBLD", a, 1) & Mid(" '2", Int(Rnd * 3 + 1), 1)
Next s
from random import randint as r
c=m=b=9
for u in range(25):
while c+b-4 and m==c or m==b:m=r(0,5)
print "URFBLD"[m]+" '2"[r(0,2)],;c=b;b=m
from random import randint as r
m=b=9
for u in range(25):
c=b;b=m
while c+b-4 and m==c or m==b:m=r(0,5)
print "URFBLD"[m]+" '2"[r(0,2)],
You forgot my Python(140 chars):
Perl: 100 chars
Code:map{$m=0|rand 6until$c+$b-5|$c-$m&&$m ne$b;$c=$b;print" ".(U,R,F,B,L,D)[$b=$m].qw(' 2)[rand 3]}1..25
That's the same I posted earlier, and like I said before, this does not create scrambles starting with DU.
I don't really know the details. The general way it works is to set up some permutation/orientation tables (which I guess explain to the program what each move does) and then does a search, starting at 1 move and going up, to see if any sequences of that length solve the position. The "u();document.write(b);" part calls what is necessary for the scrambler.Before we try,
could you explain us how an optimal scrambler for pyraminx works
and how this specfic scrambler works.
In particular: what is ther role of the functions u, v, w, x ?
Well, it's already condensed and optimized a bit (see the variable names etc.) so I doubt you'll get a huge amount out of it, maybe down to 1500 or so if the approach doesn't change.Finally, if we ever optimize it, how many characteres do you think it could reach ?
1200 ? 1000 ? less ?
In the python one, part of last line:
+" '2"[r(0,2)]
Why is the space there?
Instead, this is better:
+"'2"[r(0,1)]
Saving 1 char...