My python one-liner scramble generator

For TI83/84:

Code:
:ClrHome
:URFDLB '2→Str0
:0→E
:7→D
:For(A,1,6
:For(B,2,14,3
:E→F
:D→E
:Repeat D≠E and (D-3≠E or D+3≠E and D≠F
:randInt(1,6→D
:End
:Output(A,B,sub(Str0,D,1)+sub(Str0,randInt(7,9),1
:End
:End
 
Last edited:
For TI83/84:

Code:
:ClrHome
:URFDLB '2→Str0
:0→E
:7→D
:For(A,1,6
:For(B,2,14,3
:E→F
:D→E
:While D=E or D=F
:randInt(1,6→D
:End
:Output(A,B,sub(Str0,D,1)+sub(Str0,randInt(7,9),1
:End
:End

this didn't work for me.

I changed it to,

Code:
:ClrHome
:"URFDLB '2"→Str0
:0→E
:7→D
:For(A,2,7
:For(B,2,14,3
:E→F
:D→E
:While D=E or D=F
:randInt(1,6→D
:End
:Output(A,B,sub(Str0,D,1)+sub(Str0,randInt(7,9),1
:End
:End

I guess you need "" around a string? also made it print from line 2 to 7 as the "Done" was overwriting the last move on the first line hah. Good job though I really like this.
 
this didn't work for me.

I changed it to,

Code:
:ClrHome
:"URFDLB '2"→Str0
:0→E
:7→D
:For(A,2,7
:For(B,2,14,3
:E→F
:D→E
:While D=E or D=F
:randInt(1,6→D
:End
:Output(A,B,sub(Str0,D,1)+sub(Str0,randInt(7,9),1
:End
:End

I guess you need "" around a string? also made it print from line 2 to 7 as the "Done" was overwriting the last move on the first line hah. Good job though I really like this.

On my TI83, the "" aren't required to end the string, nor does "Done" displays.

Correct me if I'm wrong, but wouldn't Baian's 3x3 scrambler also prevent sequences like B L B'?

Thanks for pointing that out. I changed line 9(the "While" line) to:

Code:
:Repeat D≠E and (D-3≠E or D+3≠E and D≠F
 
Last edited:
JavaScript: You can use 0|x instead of Math.floor(x) and a-c instead of a!=c.

Old Perl golf, 126 chars:
Code:
perl -le 'for(0..24){$a=int rand 6 until$a-$a[0]&&$a+$a[0]-5|$a-$a[1];@a=($a,@a)}print"@{[map{(U,F,R,L,B,D)[$_].(v39,2)[rand 3]}@a]}"'
 
Imma start trying a scrambler in C. But it may take a while. I'm pretty busy here. (But did anyone do it already?)
 
joey: Yeah, I remember that ^^

[abc]toshiro;484589 said:
Imma start trying a scrambler in C. But it may take a while. I'm pretty busy here. (But did anyone do it already?)
A basic scrambler isn't much harder to write than a hello world. So yeah, it's been done in C and probably in <insert programming language here>.
 
JavaScript: You can use 0|x instead of Math.floor(x)

thanks, I didn't know that.

... and a-c instead of a!=c.

yes, you're right, I know that but I forgot to substitute it.

So now, 166 characters in javascript:
Code:
function r(n){if(n)return 0|Math.random()*n;for(d=b=j=c=a=4;j<29;)b=r(2)+1,a=r(3),a==c&&d&b||(d=a-c?b:d+b,c=a,j++,document.write(" RLFBUD"[a*2+b]+" 2'"[r(3)]+" " ))}

There's only 1 function:
r() with no args prints a scramble,
r(n) instead gives a random number in the range [0,n).
It would be nice to avoid the if and use instead the ternary operator (?) but I couldn't make it fit.
 
Last edited:
Getting rid of the function altogether gets us down to 142 characters:
Code:
r=Math.random;for(d=b=j=c=a=4;j<29;)b=0|r()*2+1,a=0|r()*3,a==c&&d&b||(d=a-c?b:d+b,c=a,j++,document.write(" RLFBUD"[a*2+b]+" 2'"[0|r()*3]+" "))
 
Getting rid of the function altogether gets us down to 142 characters:
Code:
r=Math.random;for(d=b=j=c=a=4;j<29;)b=0|r()*2+1,a=0|r()*3,a==c&&d&b||(d=a-c?b:d+b,c=a,j++,document.write(" RLFBUD"[a*2+b]+" 2'"[0|r()*3]+" "))

Nice and easy !!! :tu
 
Last edited:
Just 5 more (less) characters and it's down to half of OP. :p

If we accept that spaces in the output are not evenly distributed than we can get rid of 4 characters more
(reaching 138):

Code:
r=Math.random;for(d=b=j=c=a=4;j<29;)b=0|r()*2+1,a=0|r()*3,a==c&&d&b||(d=a-c?b:d+b,c=a,j++,document.write(" RLFBUD"[a*2+b]+" 2'"[0|r()*3]))

output example:
B R'D U B2U'B F D2R2D2L R'B L2R'D'F R2L'B R'D'U2R'
 
Last edited:
Code:
:ClrHome
:URFBLD '2→Str0
:0→E
:7→D
:For(A,1,6
:For(B,2,14,3
:E→F
:D→E
:While D=E or D+E=7 and D=F
:randInt(1,6→D
:End
:Output(A,B,sub(Str0,D,1)+sub(Str0,randInt(7,9),1
:End
:End
 
Last edited:
Changed around the code for a more efficient setup. 122 characters.

Code:
r=Math.random;for(c=b=j=0;j<25;)m=0|r()*6,c+b==5&&c==m||b==m|(c=b,b=m,j++,document.write("URFBLD"[m]+" 2'"[0|r()*3]+" "))

EDIT: HTML scrambler (as in, working webpage) in 142 characters. Works in my Firefox, anyway. Even uses normal notation thanks to ' (is there a nicer way to do that?).
Code:
<body onload='r=Math.random;for(c=b=j=0;j<25;)m=0|r()*6,c+b==5&&c==m||b==m||(c=b,b=m,j++,document.write("URFBLD"[m]+" 2'"[0|r()*3]+" "))'>
 
Last edited:
Changed around the code for a more efficient setup. 122 characters.

Code:
r=Math.random;for(c=b=j=0;j<25;)m=0|r()*6,c+b==5&&c==m||b==m|(c=b,b=m,j++,document.write("URFBLD"[m]+" 2'"[0|r()*3]+" "))

I woke up thinking about the very same possibility and found out you already made it.
Nice job.
(the number of characters is close to perl, so far, and the main differences are
document.write vs print and Math.random vs rand).


For a working html page, why not just:
Code:
<script>r=Math.random;for(c=b=j=0;j<25;)m=0|r()*6,c+b==5&&c==m||b==m||(c=b,b=m,j++,document.write("URFBLD"[m]+" 2'"[0|r()*3]+" "))</script>
(138 characters).
 
Last edited:
Back
Top