Need assistance with "simple" math

I am trying to make an equation to simplify a process so I don’t have to do this:

if Unleashed == 1 then
		StarsReleased = 10
	elseif Unleashed == 2 then
		StarsReleased = 20
	elseif Unleashed == 3 then
		StarsReleased = 30
	elseif Unleashed == 4 then
		StarsReleased = 40
	elseif Unleashed == 5 then
		StarsReleased = 50
	elseif Unleashed == 6 then
		StarsReleased = 65
	elseif Unleashed == 7 then
		StarsReleased = 80
	end -- it goes on infinitely or until i get tired of typing it out

I’ve attempted to many different attempts at what the equation is. You can summarize my attempt as follows:

7=80 (10*Points)+10 1 (5*2)
8=95 (10*Points)+15 1 (5*3) 
9=110 (10*Points)+20 1 (5*4) 
10=125 (10*Points)+25 1 (5*5)
11=145 (10*Points)+35 2 (5*7) 
12=165 (10*Points)+45 2 (5*9) 
13=185 (10*Points)+55 2 (5*11)
14=205 (10*Points)+65 2 (5*13)
15=225 (10*Points)+75 2 (5*15) 
16=250 (10*Points)+90 3 (5*18) 
17=275 (10*Points)+105 3 (5*21)
18=300 (10*Points)+120 3 (5*24) 
19=325 (10*Points)+135 3 (5*27)
20=350 (10*Points)+150 3 (5*30) 
21=380 (10*Points)+170 4 (5*34) 
22=410 (10*Points)+190 4 (5*38)
23=440 (10*Points)+210 4 (5*42)
24=470 (10*Points)+230 4 (5*46)
25=500 (10*Points)+250 4 (5*50)
26=535 (10*Points)+275 5 (5*55)

Yeah yeah that sounds like a whole not of nothing so let me explain it in english.

A player can unleash 10 boxes at a time. Every 5 times they unleash boxes, the amount of boxes they can unleash increases by 5. Meaning they unleash 10 boxes the first time, 10 boxes the second time, etc. up to 50 boxes. After they hit the 6th time of unleashing boxes, the amount increases by 15 this time. Meaning the 6th time they unleash, they will have released 65 boxes; 7th time 80 boxes etc…

I attempted equations for this but I’ve run out of hope and time so maybe someone here is a math genius and can help out.

Here was my failed equation, maybe it can help be a reference to the idea:

local Points = 16 -- failed... but close...
if Points%5==0 then 
	numericevaluation = 1
else
	numericevaluation = (Points/5)-math.floor(Points/5)
end
(10*Points)+(5*((((math.ceil(Points/5)-1)-1)*5) + (((10*((numericevaluation)))/(math.ceil(Points/5)-1))*(math.ceil(Points/5)-1)))))

This is something I came up with to match your if-statements. Could this be what you’re looking for?

local starsReleased = 10 * unleashed + math.max(unleashed - 5, 0) * 5

image

Close…
If we replace Unleashed with 17 like here:

print(10 * 17 + math.max(17 - 5, 0) * 5)

the result is 230, but it should be 275.

Here is a list according to my wretched if statements that I’ve listed out in-case all hope is lost for me:

-- THIS IS HONESTLY AN EASIER SOLUTION THE MATH IS TOO MUCH HOLY CRUD
function TranslateStarData(Unleashed)
	local StarsReleased = 0
	if Unleashed == 1 then
		StarsReleased = 10
	elseif Unleashed == 2 then
		StarsReleased = 20
	elseif Unleashed == 3 then
		StarsReleased = 30
	elseif Unleashed == 4 then
		StarsReleased = 40
	elseif Unleashed == 5 then
		StarsReleased = 50
	elseif Unleashed == 6 then
		StarsReleased = 65
	elseif Unleashed == 7 then
		StarsReleased = 80
	elseif Unleashed == 8 then
		StarsReleased = 95
	elseif Unleashed == 9 then
		StarsReleased = 110
	elseif Unleashed == 10 then
		StarsReleased = 125
	elseif Unleashed == 11 then
		StarsReleased = 145
	elseif Unleashed == 12 then
		StarsReleased = 165
	elseif Unleashed == 13 then
		StarsReleased = 185
	elseif Unleashed == 14 then
		StarsReleased = 205
	elseif Unleashed == 15 then
		StarsReleased = 225
	elseif Unleashed == 16 then
		StarsReleased = 250
	elseif Unleashed == 17 then
		StarsReleased = 275
	elseif Unleashed == 18 then
		StarsReleased = 300
	elseif Unleashed == 19 then
		StarsReleased = 325
	elseif Unleashed == 20 then
		StarsReleased = 350
	elseif Unleashed == 21 then
		StarsReleased = 380
	elseif Unleashed == 22 then
		StarsReleased = 410
	elseif Unleashed == 23 then
		StarsReleased = 440
	elseif Unleashed == 24 then
		StarsReleased = 470
	elseif Unleashed == 25 then
		StarsReleased = 500
	elseif Unleashed == 26 then
		StarsReleased = 535
	elseif Unleashed == 27 then
		StarsReleased = 570
	elseif Unleashed == 28 then
		StarsReleased = 605
	elseif Unleashed == 29 then
		StarsReleased = 640
	elseif Unleashed == 30 then
		StarsReleased = 675
	elseif Unleashed == 31 then
		StarsReleased = 715
	elseif Unleashed == 32 then
		StarsReleased = 755
	elseif Unleashed == 33 then
		StarsReleased = 795
	elseif Unleashed == 34 then
		StarsReleased = 835
	elseif Unleashed == 35 then
		StarsReleased = 875
	elseif Unleashed == 36 then
		StarsReleased = 920
	elseif Unleashed == 37 then
		StarsReleased = 965
	elseif Unleashed == 38 then
		StarsReleased = 1010
	elseif Unleashed == 39 then
		StarsReleased = 1055
	elseif Unleashed == 40 then
		StarsReleased = 1100
	elseif Unleashed == 35 then
		StarsReleased = 1150
	elseif Unleashed == 36 then
		StarsReleased = 1200
	elseif Unleashed == 37 then
		StarsReleased = 1250
	elseif Unleashed == 38 then
		StarsReleased = 1300
	elseif Unleashed == 39 then
		StarsReleased = 1350
	elseif Unleashed == 40 then
		StarsReleased = 1400
	elseif Unleashed == 41 then
		StarsReleased = 1455
	elseif Unleashed == 42 then
		StarsReleased = 1510
	elseif Unleashed == 43 then
		StarsReleased = 1565
	elseif Unleashed == 44 then
		StarsReleased = 1620
	elseif Unleashed == 45 then
		StarsReleased = 1675
	elseif Unleashed == 46 then
		StarsReleased = 1735
	elseif Unleashed == 47 then
		StarsReleased = 1795
	elseif Unleashed == 48 then
		StarsReleased = 1855
	elseif Unleashed == 49 then
		StarsReleased = 1915
	elseif Unleashed == 50 then
		StarsReleased = 1975
	elseif Unleashed == 51 then
		StarsReleased = 2040
	elseif Unleashed == 52 then
		StarsReleased = 2105
	elseif Unleashed == 53 then
		StarsReleased = 2170
	elseif Unleashed == 54 then
		StarsReleased = 2235
	elseif Unleashed == 55 then
		StarsReleased = 2300
	end
	return StarsReleased
end

maybe this? I’m on mobile, so formatting is tough

stars = (
   (10*points) +
   5 * (
      5 * (
         math.floor(
            (points-1)/5
         )
      ) +
      (points - 6)
   )
)

given points=26
5 floor((26-1)/5) gives 25
26-6 gives 20
so you add them and get 55
then multiply by 5 again to get 275

Close but…

local points = 19 stars = ((10*points)+5*(5*(math.floor((points-1)/5))+(points - 6))) print(stars)

If we plug in 19, the answer should be 325 but it returned as 330.
If we plug 16 it should be 250 but we got 285. It seems just a little off.

If it is still difficult to understand I kind of converted it into a word problem:

  1. A guy opens a pack of 10 rocks. For every 5 boxes he opens, the amount of rocks increase by 5. For example, the guy opens up 5 boxes for a total of 50 rocks, but the 6th box has 65 rocks. What equation can be used to summarize this problem? To further example for the sake of double checking, this would mean after opening 24 boxes, you would have 470 rocks.

I had some fun solving this problem, and made a function that returns the values as you need.
The function will start diverging from your if-then statements at Unleashed = 31, because you jumped from adding 25 to adding 40 rather than adding 30.

local function getReleasedStars(n)
	local segment = math.floor(n/5)
	local head = 12.5 * segment*segment + 37.5 * segment
	local segmentRemainder = n - segment*5
	local sum = segmentRemainder * (segment*5+10) + head
	return sum
end

I might explain how I created this formula later on, but I don’t quite feel like doing so right now.

1 Like

I finally came up with something that matches these if-statements.

local increaseEvery = 5
local increaseAmount = 5

function TranslateStarData(unleashed)
    local starsReleased = 10 * unleashed
    local increaseTimes = math.floor((unleashed - 1) / increaseEvery)
    
    for i = 1, increaseTimes do
        if (increaseTimes == 0) then break end
        local remainder = math.min(math.max(unleashed - 5 * i, 0), increaseEvery)
        for _ = 1, remainder do
            if (remainder == 0) then break end
            starsReleased = starsReleased + i * increaseAmount
        end
    end
    
    return starsReleased
end

image

You have no idea how many people you’ve just slapped across the face in solving this. Including me! Thank you.

As for how you solved it man I would love to know sometime as would others I’m sure. lol

Thank you and everyone else for the attempts in assisting as well. I didn’t get to plug anything in with yours yet but I’ll test it out too just for the fun of it later.