• Welcome to the Speedsolving.com, home of the web's largest puzzle community!
    You are currently viewing our forum as a guest which gives you limited access to join discussions and access our other features.

    Registration is fast, simple and absolutely free so please, join our community of 35,000+ people from around the world today!

    If you are already a member, simply login to hide this message and begin participating in the community!

Really short Javascript cube timer

theZcuber

Premium Member
Joined
May 8, 2011
Messages
2,076
Likes
3
Location
Central NY, US
WCA
2012PRAT02
#3
Using an interval for a timer is not a good idea, as it gets inaccurate pretty quickly. Use the system's time instead (I'm sure this can be quite small as well)
 
Joined
Dec 13, 2014
Messages
393
Likes
11
Location
Smerbia
WCA
2015PANG02
YouTube
molarmanful
Thread starter #4
Using an interval for a timer is not a good idea, as it gets inaccurate pretty quickly. Use the system's time instead (I'm sure this can be quite small as well)
I considered that approach; however, I decided to stick with intervals because they saved more bytes. Such is code golf...

EDIT: Okay, I decided to go with your approach. At least it's got accuracy.
 
Last edited:
Joined
Dec 13, 2014
Messages
393
Likes
11
Location
Smerbia
WCA
2015PANG02
YouTube
molarmanful
Thread starter #7
Bump...

Got down to 261 bytes:
Code:
function z(){for(c=b=j=25,r=Math.random,s[i='innerHTML']='';j;c+b-5|c-m&&b-m?s[i]+="URFBLD"[j--,c=b,b=m]+" 2'"[0|r()*3]+" ":0)m=0|r()*6}z(),k=0,onkeyup=function(x){x.which^32||k?(clearInterval(T),z(),k=0):(S=new Date,k=1,T=setInterval("a[i]=(new Date-S)/1e3"))}
- Change all document.getElementById stuff to shorter variants.
- Use onkeyup.
- Change == to ^ and && to ||.
- Take out second setInterval parameter.

Any more suggestions for lowering byte count?
 
Last edited:
Joined
Dec 13, 2014
Messages
393
Likes
11
Location
Smerbia
WCA
2015PANG02
YouTube
molarmanful
Thread starter #8
More saves (258):
Code:
function z(){for(c=b=j=25,r=Math.random,s[i='innerHTML']='';j;c+b-5|c-m&&b-m?s[i]+="URFBLD"[j--,c=b,b=m]+" 2'"[0|r()*3]+" ":0)m=0|r()*6}z(),k=0,onkeyup=function(x){x.which^32||k?(clearInterval(T),z()):(S=new Date,T=setInterval("a[i]=(new Date-S)/1e3"));k=!k}
-Just merged k=0 and k=1 into k=!k.
 
Joined
Dec 13, 2014
Messages
393
Likes
11
Location
Smerbia
WCA
2015PANG02
YouTube
molarmanful
Thread starter #9
256 now:
Code:
function z(){for(c=b=j=25,r=Math.random,s[i='innerHTML']='';j;c+b-5|c-m&&b-m?s[i]+="URFBLD"[j--,c=b,b=m]+" 2'"[0|r()*3]+" ":0)m=0|r()*6}z(),k=onkeyup=function(x){x.which^32||k?(S=new Date,T=setInterval("a[i]=(new Date-S)/1e3")):(clearInterval(T),z());k=!k}
-Declare k with onkeyup.
 
Top