Fix second star day2
This commit is contained in:
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
local TotalInvalid = 0
|
local TotalInvalid = 0
|
||||||
local Input =
|
local Input =
|
||||||
"11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124"
|
--"11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124"
|
||||||
-- Full "78847-119454,636-933,7143759788-7143793713,9960235-10043487,44480-68595,23468-43311,89-123,785189-1014654,3829443354-3829647366,647009-692765,2-20,30-42,120909-197026,5477469-5677783,9191900808-9191943802,1045643-1169377,46347154-46441299,2349460-2379599,719196-779497,483556-641804,265244-450847,210541-230207,195-275,75702340-75883143,58-84,2152-3237,3367-5895,1552-2029,9575-13844,6048-8966,419388311-419470147,936-1409,9292901468-9292987321"
|
"78847-119454,636-933,7143759788-7143793713,9960235-10043487,44480-68595,23468-43311,89-123,785189-1014654,3829443354-3829647366,647009-692765,2-20,30-42,120909-197026,5477469-5677783,9191900808-9191943802,1045643-1169377,46347154-46441299,2349460-2379599,719196-779497,483556-641804,265244-450847,210541-230207,195-275,75702340-75883143,58-84,2152-3237,3367-5895,1552-2029,9575-13844,6048-8966,419388311-419470147,936-1409,9292901468-9292987321"
|
||||||
local DEBUG = true
|
local DEBUG = false
|
||||||
|
--local DEBUG = true
|
||||||
|
|
||||||
function debug(displaystring)
|
function debug(displaystring)
|
||||||
if DEBUG then
|
if DEBUG then
|
||||||
@@ -12,33 +13,60 @@ function debug(displaystring)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO Second star, it's not doing the loop for 1 elements
|
function checkValid(Serial)
|
||||||
-- TODO Move the self check in function (maybe for cleanup stage)
|
for L = 1, math.floor(string.len(Serial) / 2) do
|
||||||
for CheckRange in string.gmatch(Input, "([^,]+)") do
|
local SingleElement = string.sub(Serial, 1, L)
|
||||||
local Start, End = CheckRange:match("^(%d+)-(%d+)$")
|
debug("Checking block size " .. L .. " " .. SingleElement)
|
||||||
for Check = Start, End do
|
local SerialTest = ""
|
||||||
local valid = true
|
for B = 1, math.floor(string.len(Serial) / L) do
|
||||||
for L = 1, string.len(Check) / 2 do
|
SerialTest = SerialTest .. SingleElement
|
||||||
if string.len(Check) % L == 0 then
|
|
||||||
local SingleElement = string.sub(Check, 1, string.len(Check) / L)
|
|
||||||
-- debug(SingleElement)
|
|
||||||
local CheckTest = ""
|
|
||||||
for B = 1, L do
|
|
||||||
CheckTest = CheckTest .. SingleElement
|
|
||||||
end
|
|
||||||
-- debug(" Compare (" .. Check .. ") == (" .. CheckTest .. ")")
|
|
||||||
if tonumber(Check) == tonumber(CheckTest) then
|
|
||||||
debug(" Invalid " .. Check)
|
|
||||||
valid = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if not valid then
|
debug(" Compare (" .. Serial .. ") == (" .. SerialTest .. ")")
|
||||||
TotalInvalid = TotalInvalid + Check
|
if tonumber(Serial) == tonumber(SerialTest) then
|
||||||
|
debug(" Invalid " .. Serial)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function serialTest(Serial)
|
||||||
|
if checkValid(Serial) then
|
||||||
|
print("Valid " .. Serial)
|
||||||
|
else
|
||||||
|
print("Invalid " .. Serial)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function checkRange(Start, End)
|
||||||
|
local Total = 0
|
||||||
|
for Serial = Start, End do
|
||||||
|
if not checkValid(Serial) then
|
||||||
|
debug(" Invalid " .. Serial)
|
||||||
|
Total = Total + Serial
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return Total
|
||||||
|
end
|
||||||
|
|
||||||
|
print("## Selfcheck - Valid")
|
||||||
|
serialTest("12")
|
||||||
|
serialTest("123")
|
||||||
|
|
||||||
|
print("## Selfcheck - Invalid")
|
||||||
|
serialTest("11")
|
||||||
|
serialTest("22")
|
||||||
|
serialTest("99")
|
||||||
|
serialTest("111")
|
||||||
|
serialTest("565656")
|
||||||
|
serialTest("123123")
|
||||||
|
|
||||||
|
print("## Get to work")
|
||||||
|
for CheckRange in string.gmatch(Input, "([^,]+)") do
|
||||||
|
local Start, End = CheckRange:match("^(%d+)-(%d+)$")
|
||||||
|
TotalInvalid = TotalInvalid + checkRange(Start, End)
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Total Count Invalid IDs " .. TotalInvalid)
|
print("Total Count Invalid IDs " .. TotalInvalid)
|
||||||
local diff = 4174379265 - TotalInvalid
|
-- local diff = 4174379265 - TotalInvalid
|
||||||
print("Difference with check " .. diff)
|
-- print("Difference with check " .. diff)
|
||||||
|
|||||||
Reference in New Issue
Block a user