Skip to content

Instantly share code, notes, and snippets.

@paulhoadley
Created January 2, 2016 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulhoadley/84700134e543925b0470 to your computer and use it in GitHub Desktop.
Save paulhoadley/84700134e543925b0470 to your computer and use it in GitHub Desktop.
package net.logicsquad.advent;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import net.logicsquad.advent.utils.Combination;
public class Day17 {
private static final String INPUT_FILENAME = "etc/day17.input";
private static final int TOTAL = 150;
public static void main(String[] args) throws IOException {
List<Integer> ints = new ArrayList<Integer>();
List<String> lines = Files.readAllLines(Paths.get(INPUT_FILENAME),
StandardCharsets.UTF_8);
for (String line : lines) {
ints.add(Integer.parseInt(line));
}
int result = 0;
for (int i = 1; i <= ints.size(); i++) {
Combination<Integer> comb = new Combination<Integer>(ints, i);
for (List<Integer> candidate : comb) {
int total = 0;
for (Integer j : candidate) {
total += j;
}
if (total == TOTAL) {
result++;
}
}
}
System.out.println("Day17.main: result = " + result);
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment