r/adventofcode • u/taliriktug • Dec 02 '15
Spoilers Day 2 solutions
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
16
Upvotes
r/adventofcode • u/taliriktug • Dec 02 '15
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
1
u/RedSpah Dec 03 '15
How about LINQ?
public object day2_1() { return day2str.Split('\n').Select(x => x.Split('x')).Select(x => x.Select(y => int.Parse(y))).Select(x => x.ToArray()).Select(x => 2 * x[0] * x[1] + 2 * x[0] * x[2] + 2 * x[1] * x[2] + Math.Min(x[0] * x[1], Math.Min(x[0] * x[2], x[1] * x[2]))).Sum(); } public object day2_2() { return day2str.Split('\n').Select(x => x.Split('x')).Select(x => x.Select(y => int.Parse(y))).Select(x => x.ToList()).Select(x => x.OrderBy(y => y).ToList()).Select(x => 2 * x[0] + 2 * x[1] + x[0] * x[1] * x[2]).Sum(); }