Something went wrong. Try again.
Code for the Advent of Code event
aoc advent-of-code
Something went wrong. Try again.
620 B · 32 lines
Lua
at rust
123456789101112131415161718192021222324252627282930313233#!/usr/bin/env lua
local freqs = {}local part1 = 0
for line in io.lines('input.txt') do local freq = tonumber(line) freqs[#freqs + 1] = freq part1 = part1 + freqend
print('Part 1: ' .. part1)
local occurrences = setmetatable({}, { __index = function() return 0 end })occurrences[0] = 1local current = 0local ind = 1local found = nil
while not found do current = current + freqs[ind] occurrences[current] = occurrences[current] + 1
if occurrences[current] > 1 then found = current end
ind = ind + 1 if ind > #freqs then ind = 1 endend
print('Part 2: ' .. found)