Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local combos = io.open("combos.txt","r")
- currBestTime = 99999
- currBestRoute = ""
- cost = {15, 100, 500, 3000, 10000, 40000, 200000}
- cps = {0.1, 0.5, 4, 10, 40, 100, 400}
- function split(pString, pPattern)
- numchanged = 0
- local Table = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pPattern
- local last_end = 1
- local s, e, cap = pString:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(Table,cap)
- numchanged = numchanged +1
- end
- last_end = e+1
- s, e, cap = pString:find(fpat, last_end)
- end
- if last_end <= #pString then
- cap = pString:sub(last_end)
- table.insert(Table, cap)
- numchanged = numchanged +1
- end
- return Table
- end
- function round(num)
- local upper = math.ceil(num)-num
- local lower = num-math.floor(num)
- if upper > lower then
- return(num - lower)
- elseif lower > upper then
- return(upper + num)
- elseif lower == upper then
- return(upper + num)
- end
- end
- function resetVariables()
- bought = {0,0,0,0,0,0,0}
- bank = 0
- total = 0
- currCPS = 7.576
- currCost = {15, 100, 500, 3000, 10000, 40000, 200000}
- --print(unpack(currCost))
- end
- function determineTime(inputData)
- resetVariables()
- local it = 0
- local completed = false
- while it < currBestTime and completed == false do
- --while completed == false do
- it = it + 1
- bank = bank + currCPS
- total = total + currCPS
- local tower = 1
- local stillBuying = false
- local count = 1
- while not stillBuying and count < 8 do
- if tonumber(inputData[count]) > 0 then
- tower = count
- stillBuying = true
- end
- count = count + 1
- end
- if stillBuying and currCost[tower] < bank then
- bought[tower] = bought[tower]+1
- bank = bank - currCost[tower]
- inputData[tower] = tostring(tonumber(inputData[tower]) - 1)
- currCost[tower] = round(cost[tower] * (1.15 ^ bought[tower]))
- currCPS = currCPS + cps[tower]
- end
- if total > 999999 then
- completed = true
- end
- end
- --wait = io.read()
- --print(it)
- return({completed, it})
- end
- lineNumber = 0
- for line in io.lines("combos.txt") do
- route = determineTime(split(line, ", "))
- if route[1] then
- currBestTime = route[2]
- currBestRoute = line
- print("Time: "..currBestTime..", Route: "..currBestRoute)
- end
- lineNumber = lineNumber + 1
- --print(lineNumber)
- end
- combos:close()
- print("Time: "..currBestTime..", Route: "..unpack(currBestRoute))
- wait = io.read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement