diff --git a/README.md b/README.md index b8a2aad..4139e83 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ This project can also be run using the amazing [CraftOS-PC emulator](https://git ## Progress -#### Stars: 0/24 +#### Stars: 1/24 |Mon|Tue|Wed|Thu|Fri|Sat|Sun| |:-:|:-:|:-:|:-:|:-:|:-:|:-:| -|1
|2
|3
|4
|5
|6
|7
| +|1
:star:|2
|3
|4
|5
|6
|7
| |8
|9
|10
|11
|12
||| diff --git a/res/examples/day01.txt b/res/examples/day01.txt new file mode 100644 index 0000000..d03fad7 --- /dev/null +++ b/res/examples/day01.txt @@ -0,0 +1,10 @@ +L68 +L30 +R48 +L5 +R60 +L55 +L1 +L99 +R14 +L82 \ No newline at end of file diff --git a/res/stats.json b/res/stats.json index 005fcf1..f9e3c2d 100644 --- a/res/stats.json +++ b/res/stats.json @@ -1,6 +1,6 @@ { "day01": { - "puzzle1": false, + "puzzle1": true, "puzzle2": false }, "day02": { diff --git a/src/day01/puzzle1.lua b/src/day01/puzzle1.lua new file mode 100644 index 0000000..f78927d --- /dev/null +++ b/src/day01/puzzle1.lua @@ -0,0 +1,25 @@ +local utils = require "utils" +local puzzle1 = {} + +function puzzle1.solve(input) + local password = 0 + local cursor = 50 + + local lines = utils.splitLines(input) + for _, line in ipairs(lines) do + local dir = line:sub(1, 1) + local dist = tonumber(line:sub(2)) + if dir == "R" then + cursor = cursor + dist + else + cursor = cursor - dist + end + cursor = cursor % 100 + if cursor == 0 then + password = password + 1 + end + end + return password +end + +return puzzle1 diff --git a/src/day01/puzzle2.lua b/src/day01/puzzle2.lua new file mode 100644 index 0000000..2f4bc9a --- /dev/null +++ b/src/day01/puzzle2.lua @@ -0,0 +1,7 @@ +local puzzle2 = {} + +function puzzle2.solve(input) + return 0 +end + +return puzzle2