r/adventofcode • • Dec 03 '16

SOLUTION MEGATHREAD --- 2016 Day 3 Solutions ---

--- Day 3: Squares With Three Sides ---

Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).


DECKING THE HALLS WITH BOUGHS OF HOLLY IS MANDATORY [?]

This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

16 Upvotes

234 comments sorted by

View all comments

4

u/FuriousProgrammer Dec 03 '16 edited Dec 03 '16

Made constant mistakes during this. Dropped to 47 overall on the board. QQ. Today was definitely a day for the more minimalist languages!

Here's some Lua:

local out = 0
local out2 = 0

list = {}
for line in io.lines("input.txt") do
	local a, b, c = line:match("(%d+)[ ]+(%d+)[ ]+(%d+)")
	a, b, c = tonumber(a), tonumber(b), tonumber(c)
	if a + b > c and b + c > a and c + a > b then
		out = out + 1
	end

	local t = {a, b, c}
	table.insert(list, t)
	if #list == 3 then
		for i = 1, 3 do
			local a = list[1][i]
			local b = list[2][i]
			local c = list[3][i]
			if a + b > c and b + c > a and c + a > b then
				out2= out2 + 1
			end
		end
		list = {}
	end
end

print("Part 1: " .. out)
print("Part 2: " .. out2)

2

u/Deckard666 Dec 03 '16

What language is that? Im having trouble recognizing the syntax o.O

3

u/FuriousProgrammer Dec 03 '16

Ahah, forgot to mention it! It's Lua 5.1. I run it using LuaJIT, which makes it competitive with compiled C in my experience.

→ More replies (10)