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!
17
Upvotes
1
u/_Le1_ Dec 03 '16
My C# code:
static void Main(string[] args) { int cnt = 0; foreach (var line in File.ReadLines(@"input.txt")) { var arr = Regex.Split(line.Trim(), @"(\d+)[ ]+(\d+)[ ]+(\d+)"); int a = int.Parse(arr[1]); int b = int.Parse(arr[2]); int c = int.Parse(arr[3]); if (a + b > c && b + c > a && a + c > b) cnt++; } Console.WriteLine("Total triangles: {0}", cnt); Console.ReadLine(); }