Guest User

Untitled

a guest
Dec 20th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. /**
  2.  * @author /u/Philboyd_Studge on 12/19/2015.
  3.  */
  4. public class Advent20 {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         final int TARGET = 36000000;
  9.         final int MAX = 1000000;
  10.         int[] houses = new int[MAX];
  11.         int answer = 0;
  12.  
  13.         boolean part1 = true;
  14.  
  15.         for (int elf = 1; elf < MAX; elf++) {
  16.             if (part1) {
  17.                 for (int visited = elf; visited < MAX; visited += elf) {
  18.                     houses[visited] += elf * 10;
  19.                 }
  20.             } else {
  21.                 for (int visit = elf; (visit <= elf*50 && visit < MAX); visit += elf) {
  22.                     houses[visit] += elf * 11;
  23.                 }
  24.             }
  25.         }
  26.  
  27.         for (int i = 0; i < MAX; i++) {
  28.             if (houses[i] >= TARGET) {
  29.                 answer = i;
  30.                 break;
  31.             }
  32.         }
  33.        
  34.         System.out.println(answer);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment