Last active
December 10, 2017 11:55
-
-
Save roccodev/bb65b186dcd52fc800a886f202f9e96e to your computer and use it in GitHub Desktop.
AdventOfCode2017/Day10
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
| List<String> bloccs = Files.readAllLines(Paths.get(new File("res/day10").getPath())).stream() | |
| .collect(Collectors.toList()); | |
| String x = bloccs.get(0).trim(); | |
| String[] lengths = x.split(","); | |
| int[] array = IntStream.range(0, 256).toArray(); | |
| int skipSize = 0; | |
| int currentPos = 0; | |
| for (String s : lengths) { | |
| int i = Integer.parseInt(s); | |
| int cut = 0; | |
| int[] temp = new int[i]; | |
| if (i <= array.length - currentPos) { | |
| cut = i; | |
| } else { | |
| cut = array.length - currentPos; | |
| } | |
| int leftover = i - cut; | |
| System.out.println(currentPos + " / " + i); | |
| System.arraycopy(array, currentPos, temp, 0, cut); | |
| System.arraycopy(array, 0, temp, cut, leftover); | |
| ArrayUtils.reverse(temp); | |
| System.arraycopy(temp, 0, array, currentPos, cut); | |
| System.arraycopy(temp, i - leftover, array, 0, leftover); | |
| currentPos += (i + skipSize); | |
| currentPos %= array.length; | |
| skipSize++; | |
| } | |
| System.out.println(array[0] * array[1]); | |
| } |
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/day10").getPath())).stream() | |
| .collect(Collectors.toList()); | |
| String x = bloccs.get(0).trim(); | |
| int[] lengths = toAscii(x); | |
| int[] array = IntStream.range(0, 256).toArray(); | |
| int[] ascii = new int[255]; | |
| int skipSize = 0; | |
| int currentPos = 0; | |
| for(int i1 = 0; i1 < 64; i1++) { | |
| for (int i : lengths) { | |
| int cut = 0; | |
| int[] temp = new int[i]; | |
| if (i <= array.length - currentPos) { | |
| cut = i; | |
| } else { | |
| cut = array.length - currentPos; | |
| } | |
| int leftover = i - cut; | |
| System.out.println(currentPos + " / " + i); | |
| System.arraycopy(array, currentPos, temp, 0, cut); | |
| System.arraycopy(array, 0, temp, cut, leftover); | |
| ArrayUtils.reverse(temp); | |
| System.arraycopy(temp, 0, array, currentPos, cut); | |
| System.arraycopy(temp, i - leftover, array, 0, leftover); | |
| currentPos += (i + skipSize); | |
| currentPos %= array.length; | |
| skipSize++; | |
| } | |
| } | |
| int[] result = new int[16]; | |
| for(int a = 0; a < 16; a++) { | |
| for(int b = 0; b < 16; b++) { | |
| result[a] ^= array[a * 16 + b]; | |
| } | |
| } | |
| StringBuilder sb = new StringBuilder(); | |
| for(int i : result) { | |
| String toAppend = Integer.toString(i, 16); | |
| sb.append(toAppend.length() == 1 ? '0' + toAppend : toAppend); | |
| } | |
| System.out.println(sb.toString()); | |
| } | |
| private static int[] toAscii(String src) { | |
| int[] toAdd = {17, 31, 73, 47, 23}; | |
| return ArrayUtils.addAll(src.chars().toArray(), toAdd); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment