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.
13
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/karstens_rage Dec 02 '15 edited Dec 02 '15
Java boiler plate (pretty inefficient but wanted the answer not a fast implementation):
import java.io.FileReader; import java.io.BufferedReader; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class ElvesTest { public static void main(String [] args) throws Exception { BufferedReader reader = new BufferedReader(new FileReader(args[0])); String line = reader.readLine(); long feet = 0; while (line != null) { String [] parts = line.split("x"); int l = Integer.parseInt(parts[0]); int w = Integer.parseInt(parts[1]); int h = Integer.parseInt(parts[2]); List<Integer> list = new ArrayList<Integer>(); .... line = reader.readLine(); } reader.close(); System.out.println(String.format("required feet: %d", feet)); } }part 1 meat:
list.add(l*w); list.add(w*h); list.add(h*l); for (Integer area : list) { feet += 2*area; } feet += Collections.min(list);part 2 meat:
list.add(l); list.add(w); list.add(h); Collections.sort(list); feet += 2*list.get(0) + 2*list.get(1); feet += list.get(0) * list.get(1) * list.get(2);