Last active
December 11, 2017 14:05
-
-
Save roccodev/bcd153eed0583488a7f8f07c038010fe to your computer and use it in GitHub Desktop.
AdventOfCode2017/Day11
This file contains hidden or 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
| public static void main(String[] args) throws IOException { | |
| List<String> bloccs = Files.readAllLines(Paths.get(new File("res/day11").getPath())).stream() | |
| .collect(Collectors.toList()); | |
| String s1 = bloccs.get(0).trim(); | |
| int x = 0, y = 0, distance = 0, goal = 0; | |
| for (String s : s1.split(",")) { | |
| Hexagons hex = Hexagons.valueOf(s.toUpperCase()); | |
| x += hex.getX(); | |
| y += hex.getY(); | |
| distance = Hexagons.distanceAsHexagon(x, y); | |
| if(distance > goal) goal = distance; | |
| } | |
| System.out.println(distance); | |
| } |
This file contains hidden or 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
| public static void main(String[] args) throws IOException { | |
| List<String> bloccs = Files.readAllLines(Paths.get(new File("res/day11").getPath())).stream() | |
| .collect(Collectors.toList()); | |
| String s1 = bloccs.get(0).trim(); | |
| int x = 0, y = 0, distance = 0, goal = 0; | |
| for (String s : s1.split(",")) { | |
| Hexagons hex = Hexagons.valueOf(s.toUpperCase()); | |
| x += hex.getX(); | |
| y += hex.getY(); | |
| distance = Hexagons.distanceAsHexagon(x, y); | |
| if(distance > goal) goal = distance; | |
| } | |
| System.out.println(goal); | |
| } |
This file contains hidden or 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
| import static java.lang.Math.*; | |
| public enum Hexagons { | |
| S(0, 1), N(0, -1), SE(1, 0), SW(-1, 1), NE(1, -1), NW(-1, 0); | |
| private int x, y; | |
| Hexagons(int x, int y) { | |
| this.x = x; | |
| this.y = y; | |
| } | |
| public int getX() { | |
| return x; | |
| } | |
| public int getY() { | |
| return y; | |
| } | |
| public static int distanceAsHexagon(int x, int y) { | |
| return (abs(x) + abs(y) + abs(x + y)) / 2; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment