Code for the Advent of Code event
aoc advent-of-code
at main 38 lines 611 B view raw
1local input = io.open("input.txt", "r") 2 3local map = {} 4 5local deliveries = 1 6 7local x = 0 8local y = 0 9 10map[x] = {} 11map[x][y] = true 12 13local char 14 15repeat 16 char = input:read(1) 17 18 if char == "^" then 19 y = y + 1 20 elseif char == "v" then 21 y = y - 1 22 elseif char == "<" then 23 x = x - 1 24 elseif char == ">" then 25 x = x + 1 26 end 27 28 if type(map[x]) ~= "table" then map[x] = {} end 29 30 if not map[x][y] then 31 deliveries = deliveries + 1 32 map[x][y] = true 33 end 34until not char 35 36print("Delivered at least once to " .. deliveries .. " houses") 37 38input:close()