Initial commit

This commit is contained in:
William Brawner 2024-11-30 15:27:55 -06:00
commit e0ebaaa955
4 changed files with 58 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
src/*.txt
*.swp

10
README.md Normal file
View file

@ -0,0 +1,10 @@
# Advent of Code 2023
Here are my solutions to the Advent of Code[^aoc] 2023 challenges. I did the first few days in Kotlin, then switched over to Lua for the rest.
[^aoc]:
[Advent of Code][aoc] An annual event of Christmas-oriented programming challenges started December 2015.
Every year since then, beginning on the first day of December, a programming puzzle is published every day for twenty-five days.
You can solve the puzzle and provide an answer using the language of your choice.
[aoc]: https://adventofcode.com

16
src/_template.lua Normal file
View file

@ -0,0 +1,16 @@
require "util"
function part1(input)
return #input
end
function part2(input)
return #input
end
local test_input = read_test_input()
assert_equals(part1(test_input), 0)
local input = read_input()
print(part1(input))
assert_equals(part2(test_input), 0)
print(part2(input))

30
src/util.lua Normal file
View file

@ -0,0 +1,30 @@
function get_day_name()
return arg[0]:sub(1,5)
end
function read_input()
local day = get_day_name()
return read_file(day .. ".txt")
end
function read_test_input()
local day = get_day_name()
return read_file(day .. "_test.txt")
end
function read_file(file)
local lines = {}
for line in io.lines(file) do
lines[#lines + 1] = line
end
return lines
end
function assert_equals(actual, expected, message)
if actual ~= expected then
print(string.format("assert failed: %s", message or ""))
print(string.format("\texpected: %s", expected))
print(string.format("\tactual: %s", actual))
os.exit(1)
end
end