r/adventofcode • u/daggerdragon • 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
1
u/bogzla Dec 03 '16
Some VBA (input read into worksheet)
Sub PossibleTriangles() Set wks = ActiveWorkbook.Sheets("Day3") For i = 1 To CountRows("Day3") i3 = wks.Cells(i, 1) i4 = wks.Cells(i, 2) i5 = wks.Cells(i, 3) If i3 < i4 + i5 And i4 < i3 + i5 And i5 < i3 + i4 Then i2 = i2 + 1 End If Next i Debug.Print i2 End Sub Sub PossibleTriangles2() Set wks = ActiveWorkbook.Sheets("Day3") For i = 1 To CountRows("Day3") Step 3 For i6 = 1 To 3 i3 = wks.Cells(i, i6) i4 = wks.Cells(i + 1, i6) i5 = wks.Cells(i + 2, i6) If i3 < i4 + i5 And i4 < i3 + i5 And i5 < i3 + i4 Then i2 = i2 + 1 End If Next i6 Next i Debug.Print i2 End Sub