1

**TI-Nspire / [Lua] Speedcubing Timer**

« **on:**December 20, 2011, 10:33:43 pm »

Hey guys, it's been a while since I've contributed anything here, but over the last week I had some free time.

Last week I took 8 different finals, and in the time after the tests I spent crafting a tool to help me with a new passion of mine.

Speed cubing, or the process of competitively solving a Rubik's cube.

At first I included a simple timer, that was originally measured in milliseconds, but after further work I formatted the time into a 00:00.00 format and added a list of previous times, automagic saving, and statistic keeping (best, total average, average of 10, soon to be median 3 of 5 and 10 of 12)

So, the controls:

Enter: Start/stop the timer

"Y"/"N": After stopping the timer you have the option whether or not to add it to the list of times, the options should be obvious

"D": Clears the current list of times

"S"/"R": Saves/Recalls one saved list of times

Since I wrote this on calc, and not with the assistance of an emulator, I have no screenshots for you, but here's the code (hopefully it works after transcribing it from my calc)

I'll probably add new features here as I make them.

Note: You can just compile this with luna or something and run it on calc.

So if any of you guys are cubers, maybe you'll use this to practice when you can't access a computer

Last week I took 8 different finals, and in the time after the tests I spent crafting a tool to help me with a new passion of mine.

Speed cubing, or the process of competitively solving a Rubik's cube.

At first I included a simple timer, that was originally measured in milliseconds, but after further work I formatted the time into a 00:00.00 format and added a list of previous times, automagic saving, and statistic keeping (best, total average, average of 10, soon to be median 3 of 5 and 10 of 12)

So, the controls:

Enter: Start/stop the timer

"Y"/"N": After stopping the timer you have the option whether or not to add it to the list of times, the options should be obvious

"D": Clears the current list of times

"S"/"R": Saves/Recalls one saved list of times

Since I wrote this on calc, and not with the assistance of an emulator, I have no screenshots for you, but here's the code (hopefully it works after transcribing it from my calc)

I'll probably add new features here as I make them.

Note: You can just compile this with luna or something and run it on calc.

So if any of you guys are cubers, maybe you'll use this to practice when you can't access a computer

Code: (lua) [Select]

`tn, msg = 0, "";`

t, n, aa, a10, b = 0, 0, 0, 0, 0

save = false

times = {};

function a()

local min, avg10, avga = 2^32, 0, 0

for i = 1, tn do

local v = times[i]

if v < min then

min = v

end

if i <= 10 then

avg10 = avg10 + v

end

avga = avga + v

end

b = min

aa = math.floor(avga/tn)

a10 = math.floor(avg10 / math.min(tn, 10))

end

function f(t)

return ("%02d:%02d.%02d"):format(t/60000, t/1000%60, t/10%100)

end

function on.paint(g)

if c then

t = (timer.getMilliSecCounter() - n)

end

g:drawString("time: " .. f(t), 0, 0, "top");

g:drawString(msg, 0, 20, "top");

g:drawString("best: " .. f(b), 150, 0, "top");

g:drawString("average (10): " .. f(a10), 150, 20, "top");

g:drawString("average (all): " .. f(aa), 150, 40, "top");

for i = 1, 8 do

local v = times[i];

if not v then break end

g:drawString(i .. ") " .. f(v), 0, 20+i*20, "top")

end

timer.start(0.01);

end

function on.timer()

timer.stop()

platform.window:invalidate()

end

function on.charIn(c)

if save then

save = false

msg = ""

if c == "y" then

table.insert(times, 1, t)

tn = tn + 1

a()

on.charIn("s")

end

end

if c == "d" then

t = 0

times = {};

tn = 0;

msg = "";

a();

elseif c == "s" then

local s = "" .. tn

msg = "saved"

for i = 1, tn do

s = s .. " " .. times[i]

end

var.store("cube_times", s .. " ");

elseif c == "r" then

local s, b , n = var.recall("cube_times") or "0 ", {}, 0;

msg = "loaded";

for w in s:gmatch("%d+%s") do

n = n + 1;

b[n] = tonumber(w);

end

tn = table.remove(b, 1);

times = b;

a();

end

end

function on.enterKey()

if save then

save = false

msg = ""

return

end

if c then

save = true;

msg = "save? (y/n)";

c = nil;

else

c = true;

msg = "";

n = timer.getMilliSecCounter();

end

end

on.charIn("r")