# WCA official scrambler broken?



## Eleredo (Aug 20, 2011)

I was scrambling my 7x7x7 using the WCA scrambler (so I can see whether I scrambled it correctly). I saw something funny:







Anyone else noticed this too?


----------



## Reinier Schippers (Aug 20, 2011)

Yes, I noticed this with my 4x4, I have seen this with other timers aswell, I dont have experience with fixing those timers, I dont think it matters much on 7x7


----------



## Mike Hughey (Aug 20, 2011)

I think it's very concerning (since it's used for official competition scrambles), and I wonder what caused it. I tried generating a bunch of 7x7x7 scrambles and didn't see anything like it. Did someone hack the site at some point?


----------



## PatrickJameson (Aug 20, 2011)

Mike Hughey said:


> Did someone hack the site at some point?


 
I looked at the current online script and the archived script(wayback machine 2009) and used this to see if there were any differences that would cause it. I couldn't find anything.


----------



## qqwref (Aug 20, 2011)

I think I found the problem - it's in the scramblestring function.



Spoiler





```
if( k && size<=5 && !mult ) {
	s+="dlburf".charAt(j);
}else{
	if(size<=5 && mult ){
		s+="DLBURF".charAt(j);
		if(k) s+="w";
	}else{
		if(k)	s+=(k+1);
		s+="DLBURF".charAt(j);
	}
}
```




So, normally, k is an integer specifying the "depth" of this turn, and this works perfectly. Now I'm not really sure why, but sometimes if(k) turns out false, even though if(k>0) turns out true. This shouldn't be happening, but for some reason, it is. I replaced all the if(k) with if(k>0) and the problem went away:



Spoiler





```
if( k>0 && size<=5 && !mult ) {
	s+="dlburf".charAt(j);
}else{
	if(size<=5 && mult ){
		s+="DLBURF".charAt(j);
		if(k>0) s+="w";
	}else{
		if(k>0)	s+=(k+1);
		s+="DLBURF".charAt(j);
	}
}
```




My guess as to the cause: a more recent version of javascript (or an internet browser?) created some kind of way where, even though k is a positive integer, if(k) might be false but if(k>0) might be true. The problem with the scrambler didn't happen before because this wasn't an issue before.


----------



## Mike Hughey (Aug 20, 2011)

qqwref said:


> My guess as to the cause: a more recent version of javascript (or an internet browser?) created some kind of way where, even though k is a positive integer, if(k) might be false but if(k>0) might be true. The problem with the scrambler didn't happen before because this wasn't an issue before.


 
Great detective work!


----------



## Pedro (Aug 20, 2011)

I noticed that in our last competition, but forgot to bring it up.

Did you correct the official version, Michael?


----------



## qqwref (Aug 20, 2011)

I don't have access to the WCA website to make fixes, but this should solve the problem. I only found out about it today, though,


----------



## Stefan (Aug 27, 2011)

Tim Reynolds noticed that a few weeks ago as well and I traced it back to the same point in the code. I'm no javascript expert, but in my view, it's clearly a bug in Firefox's javascript engine (several of us were able to get failures in Firefox but not in other browsers, and the thread starter here used Firefox as well). A value of 1 or 2 should definitely be considered true. I tried to recreate the problem with a short program to submit a bug report, but I couldn't (and then I left to America).


----------

