Skip to content

Instantly share code, notes, and snippets.

@snarkbait
Created December 11, 2017 06:09
Show Gist options
  • Save snarkbait/9f1e9dba0a49f15d68ee5e7fde505862 to your computer and use it in GitHub Desktop.
Save snarkbait/9f1e9dba0a49f15d68ee5e7fde505862 to your computer and use it in GitHub Desktop.
Advent of Code 2017 - Day 11
package Advent2017;
import util.FileIO;
public class Day11 {
enum HexDir {
n(0, -1), ne(1, -1), se(1, 0), s(0, 1), sw(-1, 1), nw(-1, 0);
int dx, dy;
HexDir(int dx, int dy) { this.dx = dx; this.dy = dy; }
}
private static int hexDistance(int x, int y) {
return ((Math.abs(x) + Math.abs(y) + Math.abs(x + y))/ 2);
}
public static void main(String[] args) {
String input = FileIO.getFileAsString("advent2017_day11.txt");
//String input = "se,sw,se,sw,sw";
int x = 0;
int y = 0;
int furthest = 0;
int dist = 0;
for (String each : input.split(",")) {
HexDir current = HexDir.valueOf(each);
x += current.dx;
y += current.dy;
dist = hexDistance(x, y);
if (dist > furthest) furthest = dist;
}
System.out.println(x + ":" + y);
System.out.println(dist);
System.out.println(furthest);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment