utils={}

function utils.accuracy(beatDivisions, time)
local ticksToPrevDiv=(game.ticker.ticks-1)%beatDivisions
local ticksToNextDiv=beatDivisions-ticksToPrevDiv
local prevDivTime=game.ticker.lastTickTime-ticksToPrevDiv*game.ticker.tickTime
local nextDivTime=game.ticker.lastTickTime+ticksToNextDiv*game.ticker.tickTime
local closest=math.min(math.abs(time-prevDivTime), math.abs(time-nextDivTime))
local halfDivision=beatDivisions/2*game.ticker.tickTime
-- print(math.abs(time-nextDivTime),"to next beat, ",math.abs(time-prevDivTime)," to previous beat. Half division is ",halfDivision,". Closest is ",closest,". The current time is ",time,", and the next division is at ", nextDivTime,", last tick happened at ",game.ticker.lastTickTime," and is tick number ",game.ticker.ticks)
return (halfDivision-closest)/halfDivision -- Math is hard
end