• 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

cubernya

Premium Member
Joined
May 8, 2011
Messages
2,076
Location
Central NY, US
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)
 

molarmanful

Member
Joined
Dec 13, 2014
Messages
393
Location
Smerbia
WCA
2015PANG02
YouTube
Visit Channel
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:

00

Member
Joined
May 1, 2015
Messages
37
if you hold one key down and then press another, everything breaks.
 

molarmanful

Member
Joined
Dec 13, 2014
Messages
393
Location
Smerbia
WCA
2015PANG02
YouTube
Visit Channel
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:

molarmanful

Member
Joined
Dec 13, 2014
Messages
393
Location
Smerbia
WCA
2015PANG02
YouTube
Visit Channel
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.
 

molarmanful

Member
Joined
Dec 13, 2014
Messages
393
Location
Smerbia
WCA
2015PANG02
YouTube
Visit Channel
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