Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author /u/Philboyd_Studge on 12/19/2015.
- */
- public class Advent20 {
- public static void main(String[] args) {
- final int TARGET = 36000000;
- final int MAX = 1000000;
- int[] houses = new int[MAX];
- int answer = 0;
- boolean part1 = true;
- for (int elf = 1; elf < MAX; elf++) {
- if (part1) {
- for (int visited = elf; visited < MAX; visited += elf) {
- houses[visited] += elf * 10;
- }
- } else {
- for (int visit = elf; (visit <= elf*50 && visit < MAX); visit += elf) {
- houses[visit] += elf * 11;
- }
- }
- }
- for (int i = 0; i < MAX; i++) {
- if (houses[i] >= TARGET) {
- answer = i;
- break;
- }
- }
- System.out.println(answer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment