Skip to content

Commit

Permalink
D1: add solution in lua
Browse files Browse the repository at this point in the history
  • Loading branch information
benhsm committed Jan 22, 2023
1 parent 78c2d95 commit 840a0e7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions day01/day01.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/lua

function solve()
io.input("input")
local calorie_counts = {}
local calories = 0
for line in io.lines() do
if line ~= "" then
local food_item = tonumber(line)
calories = calories + food_item
else
table.insert(calorie_counts, calories)
calories = 0
end
end
print(calorie_counts[1])
print(calorie_counts[1]+calorie_counts[2]+calorie_counts[3])
end

solve()

0 comments on commit 840a0e7

Please sign in to comment.