Created
December 2, 2017 05:29
-
-
Save snarkbait/d9adb1c8fed921acbe0fe444ef4847da to your computer and use it in GitHub Desktop.
Advent of Code 2017 Day 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Advent2017; | |
import util.ArrayUtils; | |
import util.FileIO; | |
import java.util.Arrays; | |
public class Day2 { | |
public static int part1(String s) { | |
Integer[] a = FileIO.StringArrayToInteger(s.split("\\s+")); | |
return ArrayUtils.max(a) - ArrayUtils.min(a); | |
} | |
public static int part2(String s) { | |
Integer[]a = FileIO.StringArrayToInteger(s.split("\\s+")); | |
Arrays.sort(a); | |
for (int i = a.length - 1; i >= 0 ; i--) { | |
for (int j = i - 1; j >=0 ; j--) { | |
if (a[i] % a[j] == 0) { | |
return a[i] / a[j]; | |
} | |
} | |
} | |
return 0; | |
} | |
public static void main(String[] args) { | |
//List<String> input = FileIO.getAOCInputForDay(2017, 2, FileIO.SESSION_ID); | |
String filename = "advent2017_day2.txt"; | |
int sum1 = FileIO.performIntActionOnLine(filename, Day2::part1); | |
int sum2 = FileIO.performIntActionOnLine(filename, Day2::part2); | |
System.out.println("Part 1: " + sum1); | |
System.out.println("Part 2: " + sum2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment