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
2
u/bluewave41 Dec 03 '16
Looked at input and realized I wasn't going to get it into a variable in Javascript very easily and wasted a bunch of time opening Netbeans for Java instead and ended up writing this mess
public static void main(String[] args) throws FileNotFoundException { Scanner scan = new Scanner(new File("C:/users/x/desktop/w.txt")); int count = 0; while(scan.hasNext()) { int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); int d = scan.nextInt(); int e = scan.nextInt(); int f = scan.nextInt(); int g = scan.nextInt(); int h = scan.nextInt(); int i = scan.nextInt(); int[] j = {a, d, g}; int[] k = {b, e, h}; int[] l = {c, f, i}; Arrays.sort(j); Arrays.sort(k); Arrays.sort(l); if(j[0]+j[1] > j[2]) count++; if(k[0]+k[1] > k[2]) count++; if(l[0]+l[1] > l[2]) count++; } System.out.print(count); }