Day1 done

This commit is contained in:
2025-12-01 13:38:17 +01:00
parent 7bfaed4a85
commit c61e96162b
3 changed files with 48 additions and 0 deletions

4
2025/Day1.lesson.txt Normal file
View File

@@ -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

11
2025/Day1.test Normal file
View File

@@ -0,0 +1,11 @@
R1000
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82

33
2025/Day1b.lua Executable file
View File

@@ -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")