molarmanful
Veteran
arg... I mean the scramble was randomly generated. If I could find a smaller (random) scramble would I win?
Well, if you enter a submission that's short enough, then I can put it on my gist.
I had a go at it, learned a few things from you. My attempt (129 bytes):
Code:function(){a=l=[];r=Math.random;while(l++<25)a.push('RLUDFB'.replace(a[l-2],'')[0|r()*5]+["'",2,''][0|r()*3]);return a.join(' ')}
Or expanded:
Code:function(){ a=l=[]; r=Math.random; while(l++<25) a.push('RLUDFB'.replace(a[l-2],'')[0|r()*5]+["'",2,''][0|r()*3]); return a.join(' ') }
I love your clever use of taking advantage of the update part of the for loop to add onto the generated move. Instead, I took an approach where I remove the previous move of the possible moves to generate. I still feel like I could make it smaller.
edit: just realized my code for checking the previous move doesn't even work. I fixed it and now it's 132 characters:
Code:function(){a=p=l=[];r=Math.random;while(l++<25)a.push((p="RLUDFB".replace(p,'')[0|r()*5])+["'",2,''][0|r()*3]);return a.join(' ')}()
All I did was add p and set p to the previous move.
Oh yeah, I put your code on the Gist. I also have a suggested modification that puts you at 127 bytes:
Code:
function s(){for(a=p=l=[],r=Math.random;l++<25;)a.push(p="RLUDFB".replace(p,'')[0|r()*5]+["'",2,''][0|r()*3]);return a.join(' ')}
- Changed while to for (no bytes directly saved)
- Took out parentheses between the ( and the p and between the ] and + (2 bytes)
- Put variable declarations inside for loop (1 byte)
This isn't the code I have on the Gist, but let me know if you want me to switch you to this version.
Last edited by a moderator: