From e0ebaaa9554127c7ef8a4d15326854dc8411cb68 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Sat, 30 Nov 2024 15:27:55 -0600 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ README.md | 10 ++++++++++ src/_template.lua | 16 ++++++++++++++++ src/util.lua | 30 ++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 src/_template.lua create mode 100644 src/util.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1035004 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +src/*.txt +*.swp diff --git a/README.md b/README.md new file mode 100644 index 0000000..cdf9ece --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file diff --git a/src/_template.lua b/src/_template.lua new file mode 100644 index 0000000..35af346 --- /dev/null +++ b/src/_template.lua @@ -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)) diff --git a/src/util.lua b/src/util.lua new file mode 100644 index 0000000..a76bfac --- /dev/null +++ b/src/util.lua @@ -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