Skip to content

Instantly share code, notes, and snippets.

@roccodev
Created December 25, 2017 20:45
Show Gist options
  • Select an option

  • Save roccodev/7bf92acb81873434a8d785032d50d4dd to your computer and use it in GitHub Desktop.

Select an option

Save roccodev/7bf92acb81873434a8d785032d50d4dd to your computer and use it in GitHub Desktop.
AdventOfCode2017/Day25
public static HashMap<Integer, Boolean> checksum = new HashMap<Integer, Boolean>(); // Used to be Byte, changed to Boolean for performance
public static void main(String args[]) throws IOException {
int state = 0; // A, B, C, D, E, F
// 0, 1, 2, 3, 4, 5
int currentPos = 0;
for (int i = 0; i < 12173597; i++) {
System.out.println("Running " + i + " (State: " + state + ")");
switch (state) {
case 0:
if (get(currentPos) == false) {
print(currentPos, true);
currentPos += 1;
state = 1;
} else {
print(currentPos, false);
currentPos += -1;
state = 2;
}
break;
case 1:
if (get(currentPos) == false) {
print(currentPos, true);
currentPos += -1;
state = 0;
} else {
print(currentPos, true);
currentPos += 1;
state = 3;
}
break;
case 2:
if (get(currentPos) == false) {
print(currentPos, true);
currentPos += 1;
state = 0;
} else {
print(currentPos, false);
currentPos += -1;
state = 4;
}
break;
case 3:
if (get(currentPos) == false) {
print(currentPos, true);
currentPos += 1;
state = 0;
} else {
print(currentPos, false);
currentPos += 1;
state = 1;
}
break;
case 4:
if (get(currentPos) == false) {
print(currentPos, true);
currentPos += -1;
state = 5;
} else {
print(currentPos, true);
currentPos += -1;
state = 2;
}
break;
case 5:
if (get(currentPos) == false) {
print(currentPos, true);
currentPos += 1;
state = 3;
} else {
print(currentPos, true);
currentPos += 1;
state = 0;
}
break;
}
}
System.out.println(toString(checksum));
System.out.println("Merry Christmas!");
}
public static void print(int pos, boolean toPrint) {
checksum.put(pos, toPrint);
}
public static String toString(HashMap<Integer, Boolean> toAnalyse) {
int i = 0;
for(boolean c : toAnalyse.values()) {
if(c == true) i++;
}
return i + "";
}
public static boolean get(int pos) {
return checksum.getOrDefault(pos, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment