diff --git a/2025/Day2/Day2_first.lua b/2025/Day2/Day2_first.lua new file mode 100755 index 0000000..f416188 --- /dev/null +++ b/2025/Day2/Day2_first.lua @@ -0,0 +1,30 @@ +#!/bin/lua + +local TotalInvalid = 0 +local Input = + "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" +-- "11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862" +--"11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124" +local DEBUG = true + +for CheckRange in string.gmatch(Input, "([^,]+)") do + local Start, End = CheckRange:match("^(%d+)-(%d+)$") + if DEBUG then + print(Start .. " to " .. End) + end + for Check = Start, End do + if string.len(Check) % 2 == 0 then + local mid = string.len(Check) / 2 + local first = string.sub(Check, 1, mid) + local second = string.sub(Check, -mid, -1) + if first == second then + print("Invalid " .. Check) + TotalInvalid = TotalInvalid + Check + end + end + end +end + +print("Total Count Invalid IDs " .. TotalInvalid) +-- local diff = 1227775554 - TotalInvalid +-- print("Difference with check " .. diff) diff --git a/2025/Day2/Day2_second.lua b/2025/Day2/Day2_second.lua new file mode 100755 index 0000000..84c2f7a --- /dev/null +++ b/2025/Day2/Day2_second.lua @@ -0,0 +1,44 @@ +#!/bin/lua + +local TotalInvalid = 0 +local Input = + "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" +local DEBUG = true + +function debug(displaystring) + if DEBUG then + print(displaystring) + end +end + +-- TODO Second star, it's not doing the loop for 1 elements +-- TODO Move the self check in function (maybe for cleanup stage) +for CheckRange in string.gmatch(Input, "([^,]+)") do + local Start, End = CheckRange:match("^(%d+)-(%d+)$") + for Check = Start, End do + local valid = true + for L = 1, string.len(Check) / 2 do + 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 + if not valid then + TotalInvalid = TotalInvalid + Check + end + end +end + +print("Total Count Invalid IDs " .. TotalInvalid) +local diff = 4174379265 - TotalInvalid +print("Difference with check " .. diff) diff --git a/2025/Day2/full_input b/2025/Day2/full_input new file mode 100644 index 0000000..4ef64e6 --- /dev/null +++ b/2025/Day2/full_input @@ -0,0 +1 @@ +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 diff --git a/2025/Day2/test_input b/2025/Day2/test_input new file mode 100644 index 0000000..a3f22ef --- /dev/null +++ b/2025/Day2/test_input @@ -0,0 +1 @@ +11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124 diff --git a/2025/Lessons.md b/2025/Lessons.md index e43d084..24e3726 100644 --- a/2025/Lessons.md +++ b/2025/Lessons.md @@ -7,3 +7,11 @@ This is mostly so I can keep notes on my progress, in single markdown format so 1. Read! Oh that brain of mine, skipping half the things and missing things like count clicks not end point dial 2. Setup a proper test, make a smaller input test that you know the answer to to check the code + + +## Lessons second day + +1. More git commits! +2. Clear history so you don't accidentally cp day1 to day2 during testing. (Undo FTW) +3. Put the central check (Serial Valid/Invalid) in a function so it's easy to add self checks in the beginning +