diff --git a/2025/Day1.lesson.txt b/2025/Day1.lesson.txt new file mode 100644 index 0000000..4c007ed --- /dev/null +++ b/2025/Day1.lesson.txt @@ -0,0 +1,4 @@ +Lessons from first day + +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 diff --git a/2025/Day1.test b/2025/Day1.test new file mode 100644 index 0000000..447ae87 --- /dev/null +++ b/2025/Day1.test @@ -0,0 +1,11 @@ +R1000 +L68 +L30 +R48 +L5 +R60 +L55 +L1 +L99 +R14 +L82 diff --git a/2025/Day1b.lua b/2025/Day1b.lua new file mode 100755 index 0000000..7c8f450 --- /dev/null +++ b/2025/Day1b.lua @@ -0,0 +1,33 @@ +#!/bin/lua +local Dial = 50 +local CountZero = 0 +local CountClick = 0 +for line in io.lines() do + local Direction, Count = line:match("^(%w)(%d+)$") + CountClick = CountClick + math.floor(Count / 100) + Count = Count - (math.floor(Count / 100) * 100) + if Direction == "L" then + Count = 0 - Count + end + if Dial == 0 then + Dial = Dial + Count + else + Dial = Dial + Count + if Dial < 0 or Dial > 100 then + CountClick = CountClick + 1 + end + end + + Dial = Dial % 100 + if Dial == 0 then + CountZero = CountZero + 1 + end + print("Direction=" .. Direction .. " Count=" .. Count .. " Dial=" .. Dial .. " CountClick=" .. CountClick) +end +local Total = CountZero + CountClick + +print("Dial " .. Dial) +print("Zero " .. CountZero) +print("Clicks " .. CountClick) +print("Total " .. Total) +print("Done")