├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── com │ └── adventofcode │ ├── shared │ ├── Debug.java │ ├── Direction.java │ └── Position.java │ ├── year2015 │ ├── Day1.java │ ├── Day10.java │ ├── Day11.java │ ├── Day12.java │ ├── Day13.java │ ├── Day14.java │ ├── Day15.java │ ├── Day16.java │ ├── Day17.java │ ├── Day18.java │ ├── Day19.java │ ├── Day2.java │ ├── Day20.java │ ├── Day21.java │ ├── Day22.java │ ├── Day23.java │ ├── Day24.java │ ├── Day25.java │ ├── Day3.java │ ├── Day4.java │ ├── Day5.java │ ├── Day6.java │ ├── Day7.java │ ├── Day8.java │ └── Day9.java │ ├── year2016 │ ├── Day10.java │ ├── Day11.java │ ├── Day12.java │ ├── Day13Part1.java │ ├── Day13Part2.java │ ├── Day14Part1.java │ ├── Day14Part2.java │ ├── Day15.java │ ├── Day16.java │ ├── Day17.java │ ├── Day18.java │ ├── Day19Part1.java │ ├── Day19Part2.java │ ├── Day1Part1.java │ ├── Day1Part2.java │ ├── Day2.java │ ├── Day20Part1.java │ ├── Day20Part2.java │ ├── Day21Part1.java │ ├── Day21Part2.java │ ├── Day22Part1.java │ ├── Day22Part2.java │ ├── Day23.java │ ├── Day24Part1.java │ ├── Day24Part2.java │ ├── Day25.java │ ├── Day3.java │ ├── Day4.java │ ├── Day5Part1.java │ ├── Day5Part2.java │ ├── Day6Part1.java │ ├── Day6Part2.java │ ├── Day7Part1.java │ ├── Day7Part2.java │ ├── Day8.java │ ├── Day9Part1.java │ └── Day9Part2.java │ ├── year2017 │ ├── Day10Part1.java │ ├── Day10Part2.java │ ├── Day11Part1.java │ ├── Day11Part2.java │ ├── Day12Part1.java │ ├── Day12Part2.java │ ├── Day13Part1.java │ ├── Day13Part2.java │ ├── Day14Part1.java │ ├── Day14Part2.java │ ├── Day15Part1.java │ ├── Day15Part2.java │ ├── Day16Part1.java │ ├── Day16Part2.java │ ├── Day17Part1.java │ ├── Day17Part2.java │ ├── Day18Part1.java │ ├── Day18Part2.java │ ├── Day19Part1.java │ ├── Day19Part2.java │ ├── Day1Part1.java │ ├── Day1Part2.java │ ├── Day20Part1.java │ ├── Day20Part2.java │ ├── Day21Part1.java │ ├── Day21Part2.java │ ├── Day22Part1.java │ ├── Day22Part2.java │ ├── Day23Part1.java │ ├── Day23Part2.java │ ├── Day24Part1.java │ ├── Day24Part2.java │ ├── Day25Part1.java │ ├── Day2Part1.java │ ├── Day2Part2.java │ ├── Day3Part1.java │ ├── Day3Part2.java │ ├── Day4Part1.java │ ├── Day4Part2.java │ ├── Day5Part1.java │ ├── Day5Part2.java │ ├── Day6Part1.java │ ├── Day6Part2.java │ ├── Day8Part1.java │ ├── Day8Part2.java │ ├── Day9Part1.java │ └── Day9Part2.java │ ├── year2018 │ ├── Day10Part1.java │ ├── Day10Part2.java │ ├── Day11Part1.java │ ├── Day11Part2.java │ ├── Day12Part1.java │ ├── Day12Part2.java │ ├── Day13Part1.java │ ├── Day13Part2.java │ ├── Day14Part1.java │ ├── Day14Part2.java │ ├── Day15Part1.java │ ├── Day1Part1.java │ ├── Day1Part2.java │ ├── Day2Part1.java │ ├── Day2Part2.java │ ├── Day3Part1.java │ ├── Day3Part2.java │ ├── Day4Part1.java │ ├── Day4Part2.java │ ├── Day5Part1.java │ ├── Day5Part2.java │ ├── Day6Part1.java │ ├── Day6Part2.java │ ├── Day7Part1.java │ ├── Day7Part2.java │ ├── Day8Part1.java │ ├── Day8Part2.java │ ├── Day9Part1.java │ └── Day9Part2.java │ ├── year2019 │ ├── Day10Part1.java │ ├── Day10Part2.java │ ├── Day11Part1.java │ ├── Day11Part2.java │ ├── Day12Part1.java │ ├── Day12Part2.java │ ├── Day13Part1.java │ ├── Day13Part2.java │ ├── Day14Part1.java │ ├── Day14Part2.java │ ├── Day15Part1.java │ ├── Day15Part2.java │ ├── Day16Part1.java │ ├── Day16Part2.java │ ├── Day17Part1.java │ ├── Day17Part2.java │ ├── Day18Part1.java │ ├── Day18Part2.java │ ├── Day19Part1.java │ ├── Day19Part2.java │ ├── Day1Part1.java │ ├── Day1Part2.java │ ├── Day20Part1.java │ ├── Day20Part2.java │ ├── Day21Part1.java │ ├── Day21Part2.java │ ├── Day22Part1.java │ ├── Day22Part2.java │ ├── Day23Part1.java │ ├── Day23Part2.java │ ├── Day24Part1.java │ ├── Day24Part2.java │ ├── Day2Part1.java │ ├── Day2Part2.java │ ├── Day3Part1.java │ ├── Day3Part2.java │ ├── Day4Part1.java │ ├── Day4Part2.java │ ├── Day5Part1.java │ ├── Day5Part2.java │ ├── Day6Part1.java │ ├── Day6Part2.java │ ├── Day7Part1.java │ ├── Day7Part2.java │ ├── Day8Part1.java │ ├── Day8Part2.java │ ├── Day9Part1.java │ └── Day9Part2.java │ ├── year2022 │ ├── Day10Part1.java │ ├── Day10Part2.java │ ├── Day11Part1.java │ ├── Day11Part2.java │ ├── Day12Part1.java │ ├── Day12Part2.java │ ├── Day13Part1.java │ ├── Day13Part2.java │ ├── Day14Part1.java │ ├── Day14Part2.java │ ├── Day15Part1.java │ ├── Day15Part2.java │ ├── Day16Part1.java │ ├── Day16Part2.java │ ├── Day17Part1.java │ ├── Day17Part2.java │ ├── Day18Part1.java │ ├── Day18Part2.java │ ├── Day19Part1.java │ ├── Day19Part2.java │ ├── Day1Part1.java │ ├── Day1Part2.java │ ├── Day20Part1.java │ ├── Day20Part2.java │ ├── Day21Part1.java │ ├── Day21Part2.java │ ├── Day22Part1.java │ ├── Day22Part2.java │ ├── Day23Part1.java │ ├── Day23Part2.java │ ├── Day24Part1.java │ ├── Day24Part2.java │ ├── Day25Part1.java │ ├── Day2Part1.java │ ├── Day2Part2.java │ ├── Day3Part1.java │ ├── Day3Part2.java │ ├── Day4Part1.java │ ├── Day4Part2.java │ ├── Day5Part1.java │ ├── Day5Part2.java │ ├── Day6Part1.java │ ├── Day6Part2.java │ ├── Day7Part1.java │ ├── Day7Part2.java │ ├── Day8Part1.java │ ├── Day8Part2.java │ ├── Day9Part1.java │ └── Day9Part2.java │ ├── year2023 │ ├── Day10Part1.java │ ├── Day10Part2.java │ ├── Day11Part1.java │ ├── Day11Part2.java │ ├── Day12Part1.java │ ├── Day12Part2.java │ ├── Day13Part1.java │ ├── Day13Part2.java │ ├── Day14Part1.java │ ├── Day14Part2.java │ ├── Day15Part1.java │ ├── Day15Part2.java │ ├── Day16Part1.java │ ├── Day16Part2.java │ ├── Day17Part1.java │ ├── Day17Part2.java │ ├── Day18Part1.java │ ├── Day18Part2.java │ ├── Day19Part1.java │ ├── Day19Part2.java │ ├── Day1Part1.java │ ├── Day1Part2.java │ ├── Day20Part1.java │ ├── Day21Part1.java │ ├── Day2Part1.java │ ├── Day2Part2.java │ ├── Day3Part1.java │ ├── Day3Part2.java │ ├── Day4Part1.java │ ├── Day4Part2.java │ ├── Day5Part1.java │ ├── Day5Part2.java │ ├── Day6Part1.java │ ├── Day6Part2.java │ ├── Day7Part1.java │ ├── Day7Part2.java │ ├── Day8Part1.java │ ├── Day8Part2.java │ ├── Day9Part1.java │ └── Day9Part2.java │ └── year2024 │ ├── Day13Part1.java │ ├── Day13Part2.java │ ├── Day14Part1.java │ ├── Day14Part2.java │ ├── Day15Part1.java │ ├── Day15Part2.java │ ├── Day15Part2Test.java │ ├── Day16Part1.java │ ├── Day16Part2.java │ ├── Day17Part1.java │ ├── Day1Part1.java │ ├── Day1Part2.java │ ├── Day2Part1.java │ ├── Day2Part2.java │ ├── Day3Part1.java │ ├── Day3Part2.java │ ├── Day4Part1.java │ ├── Day4Part2.java │ ├── Day7Part1.java │ ├── Day7Part2.java │ ├── Day8Part1.java │ └── Day8Part2.java └── resources ├── 2015 ├── day12_1.txt ├── day13_1.txt ├── day14_1.txt ├── day15_1.txt ├── day16_1.txt ├── day17_1.txt ├── day18_1.txt ├── day18_test.txt ├── day19_1.txt ├── day1_1.txt ├── day23_1.txt ├── day23_test.txt ├── day24_1.txt ├── day2_1.txt ├── day3_1.txt ├── day5_1.txt ├── day6_1.txt ├── day7_1.txt ├── day8_1.txt ├── day8_test.txt └── day9_1.txt ├── 2016 ├── day10_1.txt ├── day12_1.txt ├── day20_1.txt ├── day21_1.txt ├── day22_1.txt ├── day23_1.txt ├── day24_1.txt ├── day25_1.txt ├── day2_1.txt ├── day3_1.txt ├── day4_1.txt ├── day6_1.txt ├── day7_1.txt ├── day8_1.txt └── day9_1.txt ├── 2017 ├── day11_1.txt ├── day12_1.txt ├── day13_1.txt ├── day13_test.txt ├── day16_1.txt ├── day18_1.txt ├── day18_test.txt ├── day18_test2.txt ├── day19_1.txt ├── day19_test.txt ├── day1_1.txt ├── day20_1.txt ├── day21_1.txt ├── day21_test.txt ├── day22_1.txt ├── day22_test.txt ├── day23_1.txt ├── day24_1.txt ├── day24_test.txt ├── day25_1.txt ├── day25_test.txt ├── day2_1.txt ├── day4_1.txt ├── day5_1.txt ├── day6_1.txt ├── day8_1.txt ├── day8_test.txt └── day9_1.txt ├── 2018 ├── day1.txt ├── day10.txt ├── day10_test.txt ├── day12.txt ├── day12_test.txt ├── day13.txt ├── day13_test.txt ├── day13_test2.txt ├── day2.txt ├── day2_test.txt ├── day2_test2.txt ├── day3.txt ├── day3_test.txt ├── day4.txt ├── day4_test.txt ├── day5.txt ├── day6.txt ├── day6_test.txt ├── day7.txt ├── day7_test.txt ├── day8.txt └── day8_test.txt ├── 2019 ├── day10_1.txt ├── day11_1.txt ├── day13_1.txt ├── day14_1.txt ├── day15_1.txt ├── day16_1.txt ├── day17_1.txt ├── day18_1.txt ├── day18_2.txt ├── day19_1.txt ├── day1_1.txt ├── day20_1.txt ├── day21_1.txt ├── day22_1.txt ├── day23_1.txt ├── day24_1.txt ├── day24_a.txt ├── day3_1.txt ├── day5_1.txt ├── day6_1.txt ├── day7_1.txt ├── day8_1.txt └── day9_1.txt ├── 2022 ├── day1.txt ├── day10.txt ├── day10_test.txt ├── day11.txt ├── day11_test.txt ├── day12.txt ├── day12_test.txt ├── day13.txt ├── day13_test.txt ├── day14.txt ├── day14_test.txt ├── day15.txt ├── day15_test.txt ├── day16.txt ├── day16_test.txt ├── day17.txt ├── day17_test.txt ├── day18.txt ├── day18_test.txt ├── day19.txt ├── day19_test.txt ├── day1_test.txt ├── day2.txt ├── day20.txt ├── day20_test.txt ├── day21.txt ├── day21_test.txt ├── day22.txt ├── day22_test.txt ├── day23.txt ├── day23_test.txt ├── day23_test2.txt ├── day24.txt ├── day24_test.txt ├── day25.txt ├── day25_test.txt ├── day2_test.txt ├── day3.txt ├── day3_test.txt ├── day4.txt ├── day5.txt ├── day5_test.txt ├── day7.txt ├── day7_test.txt ├── day8.txt ├── day8_test.txt ├── day9.txt ├── day9_test.txt └── day9_test2.txt ├── 2023 ├── day1.txt ├── day10.txt ├── day10_test.txt ├── day10_test2.txt ├── day10_test3.txt ├── day10_test4.txt ├── day11.txt ├── day11_test.txt ├── day12.txt ├── day12_test.txt ├── day13.txt ├── day13_test.txt ├── day14.txt ├── day14_test.txt ├── day15.txt ├── day15_test.txt ├── day16.txt ├── day16_test.txt ├── day17.txt ├── day17_test.txt ├── day17_test2.txt ├── day18.txt ├── day18_test.txt ├── day19.txt ├── day19_test.txt ├── day1_test.txt ├── day1_test2.txt ├── day2.txt ├── day20.txt ├── day21.txt ├── day21_test.txt ├── day2_test.txt ├── day3.txt ├── day3_test.txt ├── day4.txt ├── day4_test.txt ├── day5.txt ├── day5_test.txt ├── day6.txt ├── day6_test.txt ├── day7.txt ├── day7_test.txt ├── day8.txt ├── day8_test.txt ├── day8_test2.txt ├── day9.txt └── day9_test.txt └── 2024 ├── day1.txt ├── day13.txt ├── day14.txt ├── day15.txt ├── day16.txt ├── day17.txt ├── day2.txt ├── day3.txt ├── day4.txt ├── day7.txt └── day8.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by http://www.gitignore.io 2 | 3 | ### Eclipse ### 4 | *.pydevproject 5 | .metadata 6 | .gradle 7 | bin/ 8 | tmp/ 9 | *.tmp 10 | *.bak 11 | *.swp 12 | *~.nib 13 | local.properties 14 | .settings/ 15 | .loadpath 16 | .classpath 17 | .project 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | # sbteclipse plugin 32 | .target 33 | 34 | # TeXlipse plugin 35 | .texlipse 36 | 37 | 38 | ### Gradle ### 39 | .gradle 40 | build/ 41 | 42 | # InteliJ 43 | *.iml 44 | .idea 45 | out/ 46 | 47 | **/.DS_Store 48 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.configuration.updateBuildConfiguration": "automatic", 3 | "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx4G -Xms100m", 4 | "java.compile.nullAnalysis.mode": "automatic", 5 | "java.debug.settings.onBuildFailureProceed": true 6 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Solutions to [Advent Of Code](http://adventofcode.com/) in Java 2 | 3 | Advent of Code is a series of small programming puzzles for a variety of skill levels. They are self-contained and are just as appropriate for an expert who wants to stay sharp as they are for a beginner who is just learning to code. Each puzzle calls upon different skills and has two parts that build on a theme. 4 | 5 | I am sharing my sources which are written in Java 10-17 to anyone who is interested. 6 | 7 | Some coding considerations: 8 | 9 | * prefer readability (clean code) more than performance 10 | * adapting new language features in the latest Java version 11 | * including unit test cases in most of the solutions 12 | 13 | ## How to get the answer 14 | 15 | Put your input inside java source file or correspondent text file. Then, running the java class as Java Application. The result will be printed to the console logs. 16 | 17 | ## Author 18 | 19 | Timmy Wong (thcathy@gmail.com) 20 | 21 | ###### Remark for 2015 Day 19 second part 22 | 23 | The solution of this part is tricky. It is only applicable based on specific input analysis. i.e. This may not correct if the input pattern changed. 24 | For more information, you can read the discussion from [reddit](https://www.reddit.com/r/adventofcode/comments/3xflz8/day_19_solutions/) 25 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | java { 6 | toolchain { 7 | languageVersion = JavaLanguageVersion.of(23) 8 | } 9 | } 10 | 11 | version = '1.0' 12 | 13 | repositories { 14 | mavenCentral() 15 | } 16 | 17 | dependencies { 18 | implementation 'org.apache.commons:commons-collections4:4.4' 19 | implementation 'com.google.guava:guava:31.1-jre' 20 | implementation 'ch.qos.logback:logback-classic:1.2.11' 21 | implementation 'org.slf4j:slf4j-api:1.7.36' 22 | implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3' 23 | implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1' 24 | implementation group: 'junit', name: 'junit', version: '4.13.1' 25 | } 26 | 27 | test { 28 | systemProperties 'property': 'value' 29 | } 30 | 31 | sourceSets { 32 | test { 33 | java.srcDir file('src/main/java') 34 | resources.srcDir file('src/main/resources') 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thcathy/advent-of-code/4e0fcaacaa9f6e9f8914a8e60469f00b98878921/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | 2 | rootProject.name = 'advent-of-code' 3 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/shared/Debug.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.shared; 2 | 3 | import java.util.Set; 4 | 5 | public class Debug { 6 | static public void print(int width, int height, Set position) { 7 | System.out.println(">>> debug"); 8 | for (int y = 0 ; y < height; y++) { 9 | for (int x = 0; x < width; x++) { 10 | var c = position.contains(new Position(x, y)) ? 'X' : '.'; 11 | System.out.print(c); 12 | } 13 | System.out.println(); 14 | } 15 | System.out.println(">>>>>>>>>"); 16 | } 17 | 18 | public static void printMap(char[][] map) { 19 | for (var i = 0; i < map.length; i++) { 20 | for (var j = 0; j < map[i].length; j++) { 21 | System.out.print(map[i][j]); 22 | } 23 | System.out.println(); 24 | } 25 | System.out.println(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/shared/Direction.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.shared; 2 | 3 | public enum Direction { NORTH, SOUTH, WEST, EAST } 4 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/shared/Position.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.shared; 2 | 3 | import java.util.List; 4 | 5 | public record Position(int x, int y) { 6 | public static int distance(Position a, Position b) { 7 | return Math.abs(a.x - b.x) + Math.abs(a.y - b.y); 8 | } 9 | 10 | public Position move(Direction direction) { 11 | return switch (direction) { 12 | case NORTH -> new Position(x, y - 1); 13 | case SOUTH -> new Position(x, y + 1); 14 | case WEST -> new Position(x - 1, y); 15 | case EAST -> new Position(x + 1, y); 16 | }; 17 | } 18 | 19 | public List neighbors() { 20 | return List.of( 21 | new Position(x-1, y), 22 | new Position(x+1, y), 23 | new Position(x, y-1), 24 | new Position(x, y+1) 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2015/Day1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2015; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | 6 | import java.util.List; 7 | 8 | public class Day1 { 9 | final static String inputFile = "2015/day1_1.txt"; 10 | 11 | public static void main(String... args) throws Exception { 12 | firstStar(); 13 | secondStar(); 14 | } 15 | 16 | private static void secondStar() throws Exception { 17 | List lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 18 | int[] intArray = lines.stream() 19 | .flatMapToInt(String::chars) 20 | .map(Day1::mapToValue) 21 | .toArray(); 22 | 23 | int level = 0; 24 | for (int i=0; i < intArray.length; i++) { 25 | level += intArray[i]; 26 | if (level == -1) { 27 | System.out.println(i+1); 28 | return; 29 | } 30 | } 31 | 32 | } 33 | 34 | public static void firstStar() throws Exception { 35 | List lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 36 | int result = lines.stream() 37 | .flatMapToInt(String::chars) 38 | .map(Day1::mapToValue) 39 | .sum(); 40 | System.out.println(result); 41 | } 42 | 43 | public static int mapToValue(int in) { 44 | if (in == 40) return 1; 45 | else if (in == 41) return -1; 46 | else return 0; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2015/Day10.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2015; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | public class Day10 { 7 | final static Logger log = LoggerFactory.getLogger(Day10.class); 8 | 9 | public static void main(String... args) throws Exception { 10 | test1(); 11 | firstStar(); 12 | secondStar(); 13 | } 14 | 15 | static void test1() throws Exception { 16 | String pattern = "1"; 17 | 18 | for (int i=1; i<=5; i++) { 19 | pattern = lookAndSay(pattern); 20 | log.debug("Turn {} pattern: {}", i, pattern); 21 | } 22 | } 23 | 24 | private static String lookAndSay(String pattern) { 25 | StringBuffer sb = new StringBuffer(); 26 | 27 | int pos = 0; 28 | int count = 1; 29 | int length = pattern.length(); 30 | while (pos < length) { 31 | if (pos+1 < length && pattern.charAt(pos) == pattern.charAt(pos+1)) { 32 | count++; 33 | } else { 34 | sb.append(count); 35 | sb.append(pattern.charAt(pos)); 36 | count = 1; 37 | } 38 | pos++; 39 | } 40 | return sb.toString(); 41 | } 42 | 43 | static void secondStar() throws Exception { 44 | String pattern = "1321131112"; 45 | 46 | for (int i=1; i<=50; i++) { 47 | pattern = lookAndSay(pattern); 48 | } 49 | log.info("Second Star pattern.length: {}", pattern.length()); 50 | } 51 | 52 | static void firstStar() throws Exception { 53 | String pattern = "1321131112"; 54 | 55 | for (int i=1; i<=40; i++) { 56 | pattern = lookAndSay(pattern); 57 | } 58 | log.info("First Star pattern.length: {}", pattern.length()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2015/Day12.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2015; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.regex.Matcher; 12 | import java.util.regex.Pattern; 13 | import java.util.stream.IntStream; 14 | 15 | public class Day12 { 16 | static Logger log = LoggerFactory.getLogger(Day12.class); 17 | 18 | public static void main(String... args) throws Exception { 19 | test(); 20 | firstStar(); 21 | secondStar(); 22 | } 23 | 24 | private static void secondStar() throws Exception { 25 | ObjectMapper mapper = new ObjectMapper(); 26 | Object document = mapper.readValue(Resources.getResource("2015/day12_1.txt"), Object.class); 27 | 28 | log.info("sum of document ignored 'red' is {}", sumIgnoreRed(document).sum()); 29 | } 30 | 31 | private static void firstStar() throws Exception { 32 | List input = Resources.readLines(Resources.getResource("2015/day12_1.txt"), Charsets.UTF_8); 33 | log.info("sum of first document is {}", sum(input.get(0))); 34 | } 35 | 36 | private static void test() { 37 | log.info("sum of [1,2,3] is {}", sum("[1,2,3]")); 38 | log.info("sum of {\"a\":2,\"b\":4} is {}", sum("{\"a\":2,\"b\":4}")); 39 | log.info("sum of [[[3]]] is {}", sum("[[[3]]]")); 40 | log.info("sum of {\"a\":{\"b\":4},\"c\":-1} is {}", sum("{\"a\":{\"b\":4},\"c\":-1}")); 41 | log.info("sum of {\"a\":[-1,1]} is {}", sum("{\"a\":[-1,1]}")); 42 | log.info("sum of [-1,{\"a\":1}] is {}", sum("[-1,{\"a\":1}]")); 43 | log.info("sum of [] is {}", sum("[]")); 44 | } 45 | 46 | @SuppressWarnings({ "unchecked" }) 47 | private static IntStream sumIgnoreRed(Object a) { 48 | if (a instanceof Integer) 49 | return IntStream.of((int) a); 50 | else if (a instanceof List) 51 | return ((List) a).stream().flatMapToInt(Day12::sumIgnoreRed); 52 | else if (a instanceof Map && !containsValueRed(a)) 53 | return ((Map) a).values().stream().flatMapToInt(Day12::sumIgnoreRed); 54 | return IntStream.empty(); 55 | 56 | } 57 | 58 | private static boolean containsValueRed(Object a) { 59 | return ((Map) a).containsValue("red"); 60 | } 61 | 62 | private static int sum(String string) { 63 | int total = 0; 64 | Pattern p = Pattern.compile("-?\\d+"); 65 | Matcher m = p.matcher(string); 66 | 67 | while (m.find()) { 68 | total += Integer.valueOf(m.group()); 69 | } 70 | 71 | return total; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2015/Day2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2015; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.util.List; 9 | import java.util.stream.IntStream; 10 | 11 | public class Day2 { 12 | final static String inputFile = "2015/day2_1.txt"; 13 | final static Logger log = LoggerFactory.getLogger(Day2.class); 14 | 15 | public static void main(String... args) throws Exception { 16 | firstStar(); 17 | secondStar(); 18 | } 19 | 20 | private static void secondStar() throws Exception { 21 | List lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 22 | int result = lines.stream() 23 | .map(s -> s.split("x")) 24 | .mapToInt(Day2::calculateRibbonLength) 25 | .sum(); 26 | log.info("Total Ribbon length: {}", result); 27 | } 28 | 29 | public static void firstStar() throws Exception { 30 | List lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 31 | int result = lines.stream() 32 | .map(s -> s.split("x")) 33 | .mapToInt(Day2::calculateWrappingPaperArea) 34 | .sum(); 35 | log.warn("Total area: {}", result); 36 | } 37 | 38 | public static int calculateRibbonLength(String[] in) { 39 | int w = Integer.valueOf(in[0]); 40 | int h = Integer.valueOf(in[1]); 41 | int l = Integer.valueOf(in[2]); 42 | 43 | return IntStream.of( 44 | 2*w + 2*h, 45 | 2*w + 2*l, 46 | 2*l + 2*h 47 | ) 48 | .min().getAsInt() + w * h * l; 49 | } 50 | 51 | public static int calculateWrappingPaperArea(String[] in) { 52 | int w = Integer.valueOf(in[0]); 53 | int h = Integer.valueOf(in[1]); 54 | int l = Integer.valueOf(in[2]); 55 | 56 | return IntStream.of( 57 | 2*w*h + 2*w*l + 2*h*l + w*h, 58 | 2*w*h + 2*w*l + 2*h*l + w*l, 59 | 2*w*h + 2*w*l + 2*h*l + h*l 60 | ) 61 | .min().getAsInt(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2015/Day20.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2015; 2 | 3 | import org.junit.Test; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import java.io.IOException; 8 | import java.util.stream.IntStream; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class Day20 { 13 | static Logger log = LoggerFactory.getLogger(Day20.class); 14 | 15 | public static void main(String... args) throws Exception { 16 | Day20 day20 = new Day20(); 17 | day20.firstStar(); 18 | day20.secondStar(); 19 | } 20 | 21 | void secondStar() throws Exception { 22 | log.debug("Start calculate for second star"); 23 | int presents = 36000000; 24 | 25 | int house = IntStream.range(presents/45, presents) 26 | .filter(s -> totalVisitedElvesNumberWhichStopDeliverAfter50House(s) * 11 >= presents) 27 | .findFirst() 28 | .getAsInt(); 29 | 30 | log.debug("House {} is the first one get at least {} presents in second star", house, presents); 31 | } 32 | 33 | void firstStar() throws Exception { 34 | log.debug("Start calculate for first star"); 35 | int presents = 36000000; 36 | 37 | int house = IntStream.range(presents/45, presents) 38 | .filter(s -> totalVisitedElvesNumber(s) * 10 >= presents) 39 | .findFirst() 40 | .getAsInt(); 41 | 42 | log.debug("House {} is the first one get at least {} presents in first star", house, presents); 43 | } 44 | 45 | int totalVisitedElvesNumberWhichStopDeliverAfter50House(int house) { 46 | return IntStream.rangeClosed(1, (int)Math.sqrt(house)) 47 | .filter(i -> house % i == 0) 48 | .flatMap(i -> IntStream.of(i, house / i)) 49 | .filter(i -> i * 50 >= house) 50 | .sum(); 51 | } 52 | 53 | int totalVisitedElvesNumber(int house) { 54 | return IntStream.rangeClosed(1, (int)Math.sqrt(house)) 55 | .filter(i -> house % i == 0) 56 | .flatMap(i -> IntStream.of(i, house / i)) 57 | .sum(); 58 | } 59 | 60 | @Test 61 | public void totalVisitedElvesNumber_shouldCalculateCorrectly() throws IOException { 62 | assertEquals(1, totalVisitedElvesNumber(1)); 63 | assertEquals(3, totalVisitedElvesNumber(2)); 64 | assertEquals(8, totalVisitedElvesNumber(7)); 65 | assertEquals(15, totalVisitedElvesNumber(8)); 66 | assertEquals(13, totalVisitedElvesNumber(9)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2015/Day25.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2015; 2 | 3 | import org.junit.Test; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | 9 | public class Day25 { 10 | static Logger log = LoggerFactory.getLogger(Day25.class); 11 | 12 | public static void main(String... args) throws Exception { 13 | Day25 day25 = new Day25(); 14 | day25.firstStar(); 15 | day25.secondStar(); 16 | } 17 | 18 | void secondStar() throws Exception { 19 | 20 | } 21 | 22 | 23 | void firstStar() throws Exception { 24 | long start = 20151125; 25 | int row = 2978; 26 | int col = 3083; 27 | 28 | long code = calculateCode(start, row, col); 29 | log.info("code for first star: {}", code); 30 | } 31 | 32 | long calculateCode(long start, int row, int col) { 33 | long sequence = sequenceFromLocation(row, col); 34 | long code = start; 35 | for (long i=1l; i < sequence; i++) { 36 | code = (code * 252533) % 33554393; 37 | } 38 | return code; 39 | } 40 | 41 | long sequenceFromLocation(int row, int col) { 42 | return triangleNumber(row + col - 2) + (row + col)-row; 43 | } 44 | 45 | long triangleNumber(long n) { 46 | return n*(n+1)/2; 47 | } 48 | 49 | @Test 50 | public void test_calculateCode() { 51 | long start = 20151125; 52 | assertEquals(20151125, calculateCode(start, 1, 1)); 53 | assertEquals(31916031, calculateCode(start, 2, 1)); 54 | assertEquals(18749137, calculateCode(start, 1, 2)); 55 | assertEquals(1601130, calculateCode(start, 3, 3)); 56 | assertEquals(16474243, calculateCode(start, 3, 6)); 57 | assertEquals(77061, calculateCode(start, 5, 1)); 58 | assertEquals(27995004, calculateCode(start, 6, 6)); 59 | } 60 | 61 | @Test 62 | public void test_sequenceFromLocation() { 63 | assertEquals(1, sequenceFromLocation(1, 1)); 64 | assertEquals(18, sequenceFromLocation(4, 3)); 65 | assertEquals(21, sequenceFromLocation(1, 6)); 66 | assertEquals(16, sequenceFromLocation(6, 1)); 67 | } 68 | 69 | @Test 70 | public void test_triangleNumber() throws Exception { 71 | assertEquals(10, triangleNumber(4)); 72 | assertEquals(15, triangleNumber(5)); 73 | assertEquals(18352711, triangleNumber(6058)); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2015/Day4.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2015; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.security.MessageDigest; 7 | 8 | public class Day4 { 9 | final static Logger log = LoggerFactory.getLogger(Day4.class); 10 | static MessageDigest md = null; 11 | 12 | public static void main(String... args) throws Exception { 13 | md = MessageDigest.getInstance("MD5"); 14 | firstStar(); 15 | secondStar(); 16 | } 17 | 18 | 19 | private static void secondStar() throws Exception { 20 | String input = "bgvyzdsv"; 21 | 22 | for (int i=1; i(discs); 32 | discs.add(new Disc(11, 0)); 33 | log.warn("Second star - What is the first time you can press the button to get a capsule? {}", findTimeCapsuleCanPass(discs)); 34 | } 35 | 36 | int findTimeCapsuleCanPass(List discs) { 37 | for (int i=0; i < Integer.MAX_VALUE; i++) { 38 | if (canCapsulePass(discs, i)) return i; 39 | } 40 | return -1; 41 | } 42 | 43 | boolean canCapsulePass(List discs, int startTime) { 44 | for (int i=0; i < discs.size(); i++) { 45 | if (discs.get(i).positionAtTime(startTime + i + 1) != 0) 46 | return false; 47 | } 48 | return true; 49 | } 50 | 51 | class Disc { 52 | int hasPositions; 53 | int startPosition; 54 | 55 | public Disc(int hasPositions, int startPosition) { 56 | this.hasPositions = hasPositions; 57 | this.startPosition = startPosition; 58 | } 59 | 60 | public int positionAtTime(int time) { return (time + startPosition) % hasPositions; } 61 | } 62 | 63 | @Test 64 | public void test_discPositionAt() { 65 | assertEquals(0, new Disc(5, 4).positionAtTime(1)); 66 | assertEquals(0, new Disc(5, 4).positionAtTime(6)); 67 | assertEquals(1, new Disc(2, 1).positionAtTime(2)); 68 | assertEquals(0, new Disc(2, 1).positionAtTime(7)); 69 | } 70 | 71 | @Test 72 | public void test_findTimeCapsuleCanPass() { 73 | var discs = List.of(new Disc(5, 4), new Disc(2, 1)); 74 | assertEquals(5, findTimeCapsuleCanPass(discs)); 75 | } 76 | } -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2016/Day16.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2016; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | import org.junit.Test; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | public class Day16 { 11 | Logger log = LoggerFactory.getLogger(Day16.class); 12 | 13 | public static void main(String... args) throws Exception { 14 | Day16 solution = new Day16(); 15 | solution.run(); 16 | } 17 | 18 | void run() throws Exception { 19 | log.warn("First star - what is the correct checksum? {}", checksumToFill("01111010110010011", 272)); 20 | log.warn("Second star - what is the correct checksum? {}", checksumToFill("01111010110010011", 35651584)); 21 | } 22 | 23 | String checksumToFill(String input, int lengthToFill) { 24 | while (input.length() < lengthToFill) 25 | input = construct(input); 26 | return checksum(input.substring(0, lengthToFill)); 27 | } 28 | 29 | String construct(String input) { 30 | var copy = StringUtils.reverse(input) 31 | .replaceAll("1"," ") 32 | .replaceAll("0", "1") 33 | .replaceAll(" ", "0"); 34 | return input + '0' + copy; 35 | } 36 | 37 | String checksum(String input) { 38 | var stringBuilder = new StringBuilder(); 39 | for (int i=0; i < input.length(); i+=2) { 40 | if (input.charAt(i) == input.charAt(i+1)) 41 | stringBuilder.append('1'); 42 | else 43 | stringBuilder.append('0'); 44 | } 45 | return (stringBuilder.length() % 2 == 1) ? stringBuilder.toString() : checksum(stringBuilder.toString()); 46 | } 47 | 48 | @Test 49 | public void test_checksumToFill() { 50 | assertEquals("01100", checksumToFill("10000", 20)); 51 | } 52 | 53 | @Test 54 | public void test_checksum() { 55 | assertEquals("100", checksum("110010110100")); 56 | } 57 | 58 | @Test 59 | public void test_construct() { 60 | assertEquals("100", construct("1")); 61 | assertEquals("001", construct("0")); 62 | assertEquals("11111000000", construct("11111")); 63 | assertEquals("1111000010100101011110000", construct("111100001010")); 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2016/Day19Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2016; 2 | 3 | import java.security.MessageDigest; 4 | import java.security.NoSuchAlgorithmException; 5 | 6 | import org.junit.Test; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class Day19Part1 { 13 | Logger log = LoggerFactory.getLogger(Day19Part1.class); 14 | MessageDigest messageDigest = MessageDigest.getInstance("MD5"); 15 | 16 | public Day19Part1() throws NoSuchAlgorithmException {} 17 | 18 | public static void main(String... args) throws Exception { 19 | Day19Part1 solution = new Day19Part1(); 20 | solution.run(); 21 | } 22 | 23 | void run() throws Exception { 24 | log.warn("First star - which Elf gets all the presents? {}", elfGetsAllPresents(3014603)); 25 | } 26 | 27 | int elfGetsAllPresents(int length) { 28 | var thisElf = initElves(length); 29 | 30 | while (thisElf != thisElf.next) { 31 | thisElf.present += thisElf.next.present; 32 | thisElf.next = thisElf.next.next; 33 | thisElf = thisElf.next; 34 | } 35 | return thisElf.id; 36 | } 37 | 38 | Elf initElves(int length) { 39 | var firstElf = new Elf(1, 1, null); 40 | var elf = firstElf; 41 | Elf newElf = null; 42 | for (int i = 2; i <= length; i++) { 43 | newElf = new Elf(i, 1, null); 44 | elf.next = newElf; 45 | elf = newElf; 46 | } 47 | newElf.next = firstElf; 48 | return firstElf; 49 | } 50 | 51 | class Elf { 52 | int id, present; 53 | Elf next; 54 | 55 | public Elf(int id, int present, Elf next) { 56 | this.id = id; 57 | this.present = present; 58 | this.next = next; 59 | } 60 | } 61 | 62 | @Test 63 | public void test_elfGetsAllPresents() { 64 | assertEquals(3, elfGetsAllPresents(5)); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2016/Day19Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2016; 2 | 3 | import java.security.MessageDigest; 4 | import java.security.NoSuchAlgorithmException; 5 | 6 | import org.junit.Test; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class Day19Part2 { 13 | Logger log = LoggerFactory.getLogger(Day19Part2.class); 14 | MessageDigest messageDigest = MessageDigest.getInstance("MD5"); 15 | 16 | public Day19Part2() throws NoSuchAlgorithmException {} 17 | 18 | public static void main(String... args) throws Exception { 19 | Day19Part2 solution = new Day19Part2(); 20 | solution.run(); 21 | } 22 | 23 | void run() throws Exception { 24 | log.warn("WARNING: It takes couple hours to run !"); 25 | log.warn("Second star - which Elf gets all the presents? {}", elfGetsAllPresents(3014603)); 26 | } 27 | 28 | int elfGetsAllPresents(int length) { 29 | var thisElf = initElves(length); 30 | 31 | for (; length > 1; length--) { 32 | var elfBeforeStolen = elfBeforeStolen(thisElf, length); 33 | elfBeforeStolen.next = elfBeforeStolen.next.next; 34 | thisElf = thisElf.next; 35 | if (length % 10000 == 0) log.info("{}", length); 36 | } 37 | return thisElf.id; 38 | } 39 | 40 | Elf elfBeforeStolen(Elf elf, int length) { 41 | for (int i = length / 2; i > 1; i--) { elf = elf.next; } 42 | return elf; 43 | } 44 | 45 | Elf initElves(int length) { 46 | var firstElf = new Elf(1, null); 47 | var elf = firstElf; 48 | Elf newElf = null; 49 | for (int i = 2; i <= length; i++) { 50 | newElf = new Elf(i, null); 51 | elf.next = newElf; 52 | elf = newElf; 53 | } 54 | newElf.next = firstElf; 55 | return firstElf; 56 | } 57 | 58 | class Elf { 59 | int id; 60 | Elf next; 61 | 62 | public Elf(int id, Elf next) { 63 | this.id = id; 64 | this.next = next; 65 | } 66 | } 67 | 68 | @Test 69 | public void test_elfGetsAllPresents() { 70 | assertEquals(2, elfGetsAllPresents(5)); 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2016/Day5Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2016; 2 | 3 | import java.security.MessageDigest; 4 | 5 | import org.junit.Test; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class Day5Part1 { 12 | Logger log = LoggerFactory.getLogger(Day5Part1.class); 13 | 14 | public static void main(String... args) throws Exception { 15 | Day5Part1 solution = new Day5Part1(); 16 | solution.firstStar(); 17 | } 18 | 19 | void firstStar() throws Exception { 20 | log.warn("First star - the password is = {}", decode("ugkcyxxp")); 21 | } 22 | 23 | String decode(String input) throws Exception { 24 | char[] password = new char[8]; 25 | int index = 0, count = 0; 26 | var messageDigest = MessageDigest.getInstance("MD5"); 27 | while (count < 8) { 28 | var md5 = md5Hex(messageDigest, input + String.valueOf(index)); 29 | if (md5.startsWith("00000")) { 30 | log.debug("{} character of password = {}. Found from {} - {}", count+1, md5.charAt(5), index, md5); 31 | password[count] = md5.charAt(5); 32 | count++; 33 | } 34 | index++; 35 | } 36 | return new String(password); 37 | } 38 | 39 | private static String md5Hex(MessageDigest messageDigest, String in) { 40 | byte[] digest = messageDigest.digest(in.getBytes()); 41 | StringBuffer sb = new StringBuffer(); 42 | for (byte b : digest) { 43 | sb.append(String.format("%02x", b & 0xff)); 44 | } 45 | return sb.toString(); 46 | } 47 | 48 | @Test 49 | public void test_decode_abc() throws Exception { 50 | assertEquals("18f47a30", decode("abc")); 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2016/Day5Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2016; 2 | 3 | import java.security.MessageDigest; 4 | 5 | import org.junit.Test; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class Day5Part2 { 12 | Logger log = LoggerFactory.getLogger(Day5Part2.class); 13 | 14 | public static void main(String... args) throws Exception { 15 | Day5Part2 solution = new Day5Part2(); 16 | solution.secondStar(); 17 | } 18 | 19 | void secondStar() throws Exception { 20 | log.warn("Second star - the password is = {}", decode("ugkcyxxp")); 21 | } 22 | 23 | String decode(String input) throws Exception { 24 | char[] password = new char[8]; 25 | int index = 0, count = 0; 26 | var messageDigest = MessageDigest.getInstance("MD5"); 27 | while (count < 8) { 28 | var md5 = md5Hex(messageDigest, input + String.valueOf(index)); 29 | if (md5.startsWith("00000")) { 30 | int position = parsePosition(md5.substring(5, 6)); 31 | if (position >= 0 && password[position] == '\u0000') { 32 | password[position] = md5.charAt(6); 33 | log.debug("password = {}. Found from {} - {}", password, index, md5); 34 | count++; 35 | } 36 | } 37 | index++; 38 | } 39 | return new String(password); 40 | } 41 | 42 | private int parsePosition(String input) { 43 | try { 44 | int position = Integer.valueOf(input); 45 | if (position < 8) 46 | return position; 47 | else 48 | return -1; 49 | } catch (Exception e) { 50 | return -1; 51 | } 52 | } 53 | 54 | String md5Hex(MessageDigest messageDigest, String in) { 55 | byte[] digest = messageDigest.digest(in.getBytes()); 56 | StringBuffer sb = new StringBuffer(); 57 | for (byte b : digest) { 58 | sb.append(String.format("%02x", b & 0xff)); 59 | } 60 | return sb.toString(); 61 | } 62 | 63 | @Test 64 | public void test_decode_abc() throws Exception { 65 | assertEquals("05ace8e3", decode("abc")); 66 | } 67 | } -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2016/Day9Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2016; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | import org.junit.Test; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import com.google.common.base.Charsets; 11 | import com.google.common.io.Resources; 12 | 13 | import static junit.framework.TestCase.assertEquals; 14 | 15 | public class Day9Part1 { 16 | Logger log = LoggerFactory.getLogger(Day9Part1.class); 17 | final static String inputFile = "2016/day9_1.txt"; 18 | 19 | public static void main(String... args) throws IOException { 20 | Day9Part1 solution = new Day9Part1(); 21 | solution.firstStar(); 22 | } 23 | 24 | void firstStar() throws IOException { 25 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 26 | var result = decompress(lines.get(0)).length(); 27 | log.warn("First star - What is the decompressed length of the file? {}", result); 28 | } 29 | 30 | String decompress(String input) { 31 | StringBuilder builder = new StringBuilder(); 32 | int pointer = 0; 33 | while (pointer < input.length()) { 34 | char character = input.charAt(pointer); 35 | if (character == '(') 36 | pointer = processParentheses(input, pointer, builder); 37 | else 38 | builder.append(character); 39 | 40 | pointer++; 41 | } 42 | return builder.toString(); 43 | } 44 | 45 | private int processParentheses(String input, int pointer, StringBuilder builder) { 46 | int closeParenthesesPosition = input.indexOf(')', pointer); 47 | var params = input.substring(pointer+1, closeParenthesesPosition).split("x"); 48 | String pattern = input.substring(closeParenthesesPosition + 1, closeParenthesesPosition + 1 + Integer.valueOf(params[0])); 49 | builder.append(StringUtils.repeat(pattern, Integer.valueOf(params[1]))); 50 | return closeParenthesesPosition + pattern.length(); 51 | } 52 | 53 | @Test 54 | public void test_decompress() { 55 | assertEquals("ADVENT", decompress("ADVENT")); 56 | assertEquals("ABBBBBC", decompress("A(1x5)BC")); 57 | assertEquals("XYZXYZXYZ", decompress("(3x3)XYZ")); 58 | assertEquals("ABCBCDEFEFG", decompress("A(2x2)BCD(2x2)EFG")); 59 | assertEquals("(1x3)A", decompress("(6x1)(1x3)A")); 60 | assertEquals("X(3x3)ABC(3x3)ABCY", decompress("X(8x2)(3x3)ABCY")); 61 | } 62 | 63 | 64 | } -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2016/Day9Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2016; 2 | 3 | import java.io.IOException; 4 | 5 | import org.junit.Test; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import com.google.common.base.Charsets; 10 | import com.google.common.io.Resources; 11 | 12 | import static junit.framework.TestCase.assertEquals; 13 | 14 | public class Day9Part2 { 15 | Logger log = LoggerFactory.getLogger(Day9Part2.class); 16 | final static String inputFile = "2016/day9_1.txt"; 17 | 18 | public static void main(String... args) throws IOException { 19 | Day9Part2 solution = new Day9Part2(); 20 | solution.secondStar(); 21 | } 22 | 23 | void secondStar() throws IOException { 24 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 25 | var result = decompress(lines.get(0)); 26 | log.warn("Second star - What is the decompressed length of the file? {}", result); 27 | } 28 | 29 | long decompress(String input) { 30 | int pointer = 0; 31 | long count = 0; 32 | while (pointer < input.length()) { 33 | char character = input.charAt(pointer); 34 | if (character == '(') { 35 | int closeParenthesesPosition = input.indexOf(')', pointer); 36 | var params = input.substring(pointer+1, closeParenthesesPosition).split("x"); 37 | String pattern = input.substring(closeParenthesesPosition + 1, closeParenthesesPosition + 1 + Integer.valueOf(params[0])); 38 | long patternLength = pattern.length(); 39 | if (pattern.contains("(")) patternLength = decompress(pattern); 40 | count = count + patternLength * Integer.valueOf(params[1]); 41 | pointer = closeParenthesesPosition + Integer.valueOf(params[0]); 42 | } else 43 | count++; 44 | pointer++; 45 | } 46 | return count; 47 | } 48 | 49 | @Test 50 | public void test_decompress() { 51 | assertEquals(9, decompress("(3x3)XYZ")); 52 | assertEquals(20, decompress("X(8x2)(3x3)ABCY")); 53 | assertEquals(445, decompress("(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN")); 54 | assertEquals(241920, decompress("(27x12)(20x12)(13x14)(7x10)(1x12)A")); 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day10Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | import java.io.IOException; 8 | import java.util.stream.IntStream; 9 | 10 | public class Day10Part1 { 11 | 12 | final static int[] puzzleInput = new int[] {183,0,31,146,254,240,223,150,2,206,161,1,255,232,199,88}; 13 | 14 | public static void main(String... args) throws IOException { 15 | Day10Part1 solution = new Day10Part1(); 16 | solution.run(); 17 | } 18 | 19 | void run() throws IOException { 20 | var list = IntStream.rangeClosed(0, 255).toArray(); 21 | var result = puzzleOutput(list, puzzleInput); 22 | System.out.printf("what is the result of multiplying the first two numbers in the list? %d %n", result); 23 | } 24 | 25 | int puzzleOutput(int[] list, int[] puzzleInput) { 26 | int skipSize = 0; 27 | int currentPosition = 0; 28 | for (int input : puzzleInput) { 29 | int start = currentPosition; 30 | int end = start + input - 1; 31 | while (start < end) { 32 | swap(list, start, end); 33 | start++; 34 | end--; 35 | } 36 | currentPosition = (currentPosition + input + skipSize) % list.length; 37 | skipSize++; 38 | } 39 | return list[0] * list[1]; 40 | } 41 | 42 | void swap(int[] array, int pos1, int pos2) { 43 | pos1 = pos1 % array.length; 44 | pos2 = pos2 % array.length; 45 | int temp = array[pos1]; 46 | array[pos1] = array[pos2]; 47 | array[pos2] = temp; 48 | } 49 | 50 | @Test 51 | public void unitTest() { 52 | Assert.assertEquals(12, puzzleOutput(IntStream.rangeClosed(0, 4).toArray(), new int[] {3, 4, 1, 5})); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day11Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * Using Cube coordinates of hex grids 13 | * Reference - https://www.redblobgames.com/grids/hexagons/ 14 | */ 15 | public class Day11Part1 { 16 | final static String inputFile = "2017/day11_1.txt"; 17 | 18 | public static void main(String... args) throws IOException { 19 | Day11Part1 solution = new Day11Part1(); 20 | solution.run(); 21 | } 22 | 23 | void run() throws IOException { 24 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 25 | var result = distance(lines.get(0)); 26 | System.out.printf("the fewest number of steps required? %d %n", result); 27 | } 28 | 29 | int distance(String steps) { 30 | int q=0, r=0, s=0; 31 | for (String step : steps.split(",")) { 32 | if ("n".equals(step)) { 33 | s++; r--; 34 | } else if ("ne".equals(step)) { 35 | q++; r--; 36 | } else if ("se".equals(step)) { 37 | q++; s--; 38 | } else if ("s".equals(step)) { 39 | r++; s--; 40 | } else if ("sw".equals(step)) { 41 | r++; q--; 42 | } else if ("nw".equals(step)) { 43 | s++; q--; 44 | } 45 | } 46 | return (Math.abs(q) + Math.abs(r) + Math.abs(s)) / 2; 47 | } 48 | 49 | 50 | @Test 51 | public void unitTest() { 52 | Assert.assertEquals(3, distance("ne,ne,ne")); 53 | Assert.assertEquals(0, distance("ne,ne,sw,sw")); 54 | Assert.assertEquals(2, distance("ne,ne,s,s")); 55 | Assert.assertEquals(3, distance("se,sw,se,sw,sw")); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day11Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * Using Cube coordinates of hex grids 11 | * Reference - https://www.redblobgames.com/grids/hexagons/ 12 | */ 13 | public class Day11Part2 { 14 | final static String inputFile = "2017/day11_1.txt"; 15 | 16 | public static void main(String... args) throws IOException { 17 | Day11Part2 solution = new Day11Part2(); 18 | solution.run(); 19 | } 20 | 21 | void run() throws IOException { 22 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 23 | var result = furthestDistance(lines.get(0)); 24 | System.out.printf("How many steps away is the furthest he ever got from his starting position? %d %n", result); 25 | } 26 | 27 | int furthestDistance(String steps) { 28 | int q=0, r=0, s=0, maxDistance=0; 29 | for (String step : steps.split(",")) { 30 | if ("n".equals(step)) { 31 | s++; r--; 32 | } else if ("ne".equals(step)) { 33 | q++; r--; 34 | } else if ("se".equals(step)) { 35 | q++; s--; 36 | } else if ("s".equals(step)) { 37 | r++; s--; 38 | } else if ("sw".equals(step)) { 39 | r++; q--; 40 | } else if ("nw".equals(step)) { 41 | s++; q--; 42 | } 43 | maxDistance = Math.max(maxDistance, distance(q, r, s)); 44 | } 45 | return maxDistance; 46 | } 47 | 48 | int distance(int q, int r, int s) { 49 | return (Math.abs(q) + Math.abs(r) + Math.abs(s)) / 2; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day12Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | 7 | import java.io.IOException; 8 | import java.util.*; 9 | 10 | public class Day12Part1 { 11 | final static String inputFile = "2017/day12_1.txt"; 12 | 13 | public static void main(String... args) throws IOException { 14 | Day12Part1 solution = new Day12Part1(); 15 | solution.run(); 16 | } 17 | 18 | void run() throws IOException { 19 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 20 | var result = groupSize(programMap(lines), 0); 21 | System.out.printf("How many programs are in the group that contains program ID 0? %d %n", result); 22 | } 23 | 24 | int groupSize(Map> programMap, int programId) { 25 | Set group = new HashSet<>(); 26 | List programs = new LinkedList<>(); 27 | programs.add(programId); 28 | while (!programs.isEmpty()) { 29 | var program = programs.remove(0); 30 | if (!group.contains(program)) { 31 | group.add(program); 32 | programs.addAll(programMap.get(program)); 33 | } 34 | } 35 | return group.size(); 36 | } 37 | 38 | Map> programMap(List inputs) { 39 | Map> map = new HashMap<>(); 40 | for (String input : inputs) { 41 | var programs = input.split(" <-> "); 42 | int keyProgram = Integer.parseInt(programs[0].trim()); 43 | for (String programString : programs[1].split(",")) { 44 | int program = Integer.parseInt(programString.trim()); 45 | map.computeIfAbsent(keyProgram, v -> new HashSet<>()); 46 | map.get(keyProgram).add(program); 47 | map.computeIfAbsent(program, v -> new HashSet<>()); 48 | map.get(program).add(keyProgram); 49 | } 50 | } 51 | return map; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day12Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | 7 | import java.io.IOException; 8 | import java.util.*; 9 | 10 | public class Day12Part2 { 11 | final static String inputFile = "2017/day12_1.txt"; 12 | 13 | public static void main(String... args) throws IOException { 14 | Day12Part2 solution = new Day12Part2(); 15 | solution.run(); 16 | } 17 | 18 | void run() throws IOException { 19 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 20 | var result = totalGroups(programMap(lines)); 21 | System.out.printf("How many groups are there in total? %d %n", result); 22 | } 23 | 24 | int totalGroups(Map> programMap) { 25 | Set groupedPrograms = new HashSet<>(); 26 | int totalGroups = 0; 27 | for (Map.Entry> entry : programMap.entrySet()) { 28 | if (groupedPrograms.contains(entry.getKey())) continue; 29 | 30 | groupedPrograms.addAll(findGroup(programMap, entry.getKey())); 31 | totalGroups++; 32 | } 33 | return totalGroups; 34 | } 35 | Set findGroup(Map> programMap, int programId) { 36 | Set group = new HashSet<>(); 37 | List programs = new LinkedList<>(); 38 | programs.add(programId); 39 | while (!programs.isEmpty()) { 40 | var program = programs.remove(0); 41 | if (!group.contains(program)) { 42 | group.add(program); 43 | programs.addAll(programMap.get(program)); 44 | } 45 | } 46 | return group; 47 | } 48 | 49 | Map> programMap(List inputs) { 50 | Map> map = new HashMap<>(); 51 | for (String input : inputs) { 52 | var programs = input.split(" <-> "); 53 | int keyProgram = Integer.parseInt(programs[0].trim()); 54 | for (String programString : programs[1].split(",")) { 55 | int program = Integer.parseInt(programString.trim()); 56 | map.computeIfAbsent(keyProgram, v -> new HashSet<>()); 57 | map.get(keyProgram).add(program); 58 | map.computeIfAbsent(program, v -> new HashSet<>()); 59 | map.get(program).add(keyProgram); 60 | } 61 | } 62 | return map; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day13Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | 7 | import java.io.IOException; 8 | import java.util.List; 9 | import java.util.Map; 10 | import java.util.stream.Collectors; 11 | 12 | public class Day13Part1 { 13 | final static String inputFile = "2017/day13_1.txt"; 14 | 15 | public static void main(String... args) throws IOException { 16 | Day13Part1 solution = new Day13Part1(); 17 | solution.run(); 18 | } 19 | 20 | void run() throws IOException { 21 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 22 | var result = totalSeverity(parseFirewallFromInput(lines)); 23 | System.out.printf("what is the severity of your whole trip? %d %n", result); 24 | } 25 | 26 | int totalSeverity(Map firewall) { 27 | int totalSeverity = 0; 28 | for (Map.Entry layer : firewall.entrySet()) { 29 | int depth = layer.getKey(); 30 | int range = layer.getValue(); 31 | 32 | int pos = depth % (2 * range - 2); 33 | if (pos > (range-1)) { 34 | pos = (range-1) - (pos - range + 1); 35 | } 36 | if (pos == 0) { 37 | totalSeverity += depth * range; 38 | } 39 | } 40 | return totalSeverity; 41 | } 42 | 43 | Map parseFirewallFromInput(List inputs) { 44 | return inputs.stream() 45 | .map(s -> s.split(": ")) 46 | .collect(Collectors.toMap(arr -> Integer.parseInt(arr[0]), arr -> Integer.parseInt(arr[1]))); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day13Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | import org.junit.Test; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | import java.util.Map; 11 | import java.util.stream.Collectors; 12 | 13 | import static junit.framework.TestCase.assertEquals; 14 | 15 | public class Day13Part2 { 16 | final static String inputFile = "2017/day13_1.txt"; 17 | 18 | public static void main(String... args) throws IOException { 19 | Day13Part2 solution = new Day13Part2(); 20 | solution.run(); 21 | } 22 | 23 | void run() throws IOException { 24 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 25 | var result = delayToPassFirewall(parseEachLayerCatchTime(lines)); 26 | System.out.printf("What is the fewest number of picoseconds that you need to delay? %d %n", result); 27 | } 28 | 29 | int delayToPassFirewall(Map eachLayerCatchTime) { 30 | int startPicosecond = 0; 31 | boolean passed; 32 | do { 33 | passed = true; 34 | for (Map.Entry layer : eachLayerCatchTime.entrySet()) { 35 | if ((layer.getKey() + startPicosecond) % layer.getValue() == 0) { 36 | passed = false; 37 | break; 38 | } 39 | } 40 | startPicosecond++; 41 | } while (!passed); 42 | return startPicosecond - 1; 43 | } 44 | int catchTime(int range) { 45 | return 2 * range - 2; 46 | } 47 | 48 | Map parseEachLayerCatchTime(List inputs) { 49 | return inputs.stream() 50 | .map(s -> s.split(": ")) 51 | .collect(Collectors.toMap( 52 | arr -> Integer.parseInt(arr[0]), 53 | arr -> catchTime(Integer.parseInt(arr[1]))) 54 | ); 55 | } 56 | 57 | @Test 58 | public void testcase() throws IOException { 59 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 60 | assertEquals(10, delayToPassFirewall(parseEachLayerCatchTime(lines))); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day15Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import static org.junit.Assert.assertEquals; 5 | 6 | import java.io.IOException; 7 | 8 | import org.junit.Test; 9 | 10 | public class Day15Part1 { 11 | final static long GENERATOR_A_ORIGIN_VALUE = 703; 12 | final static long GENERATOR_B_ORIGIN_VALUE = 516; 13 | final static long GENERATOR_A_FACTOR = 16807; 14 | final static long GENERATOR_B_FACTOR = 48271; 15 | final static long TEST_CYCLE = 40_000_000; 16 | 17 | public static void main(String... args) throws IOException { 18 | Day15Part1 solution = new Day15Part1(); 19 | solution.run(); 20 | } 21 | 22 | void run() throws IOException { 23 | var result = totalMatchingPairs(GENERATOR_A_ORIGIN_VALUE, GENERATOR_B_ORIGIN_VALUE); 24 | System.out.printf("what is the judge's final count? %s %n", result); 25 | } 26 | 27 | int totalMatchingPairs(long a, long b) { 28 | int matched = 0; 29 | Generator generatorA = new Generator(GENERATOR_A_FACTOR, a); 30 | Generator generatorB = new Generator(GENERATOR_B_FACTOR, b); 31 | for (int i = 0; i < TEST_CYCLE; i++) { 32 | generatorA.nextValue(); 33 | generatorB.nextValue(); 34 | if (judge(generatorA.value, generatorB.value)) { 35 | matched++; 36 | } 37 | } 38 | return matched; 39 | } 40 | 41 | boolean judge(long a, long b) { 42 | return (a % 65536) == (b % 65536); // 2 ^ 16 43 | } 44 | 45 | class Generator { 46 | final long factor; 47 | long value; 48 | 49 | Generator(long factor, long originValue) { 50 | this.factor = factor; 51 | value = originValue; 52 | } 53 | 54 | long nextValue() { 55 | value = (value * factor) % 2147483647; 56 | return value; 57 | } 58 | } 59 | 60 | @Test 61 | public void unitTest() { 62 | assertEquals(588, totalMatchingPairs(65, 8921)); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day15Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import static org.junit.Assert.assertEquals; 5 | 6 | import java.io.IOException; 7 | 8 | import org.junit.Test; 9 | 10 | public class Day15Part2 { 11 | final static long GENERATOR_A_ORIGIN_VALUE = 703; 12 | final static long GENERATOR_B_ORIGIN_VALUE = 516; 13 | final static long GENERATOR_A_FACTOR = 16807; 14 | final static long GENERATOR_B_FACTOR = 48271; 15 | final static long GENERATOR_A_MULTIPLE = 4; 16 | final static long GENERATOR_B_MULTIPLE = 8; 17 | final static long TEST_CYCLE = 5_000_000; 18 | 19 | public static void main(String... args) throws IOException { 20 | Day15Part2 solution = new Day15Part2(); 21 | solution.run(); 22 | } 23 | 24 | void run() throws IOException { 25 | var result = totalMatchingPairs(GENERATOR_A_ORIGIN_VALUE, GENERATOR_B_ORIGIN_VALUE); 26 | System.out.printf("what is the judge's final count? %s %n", result); 27 | } 28 | 29 | int totalMatchingPairs(long a, long b) { 30 | int matched = 0; 31 | Generator generatorA = new Generator(GENERATOR_A_FACTOR, a, GENERATOR_A_MULTIPLE); 32 | Generator generatorB = new Generator(GENERATOR_B_FACTOR, b, GENERATOR_B_MULTIPLE); 33 | for (int i = 0; i < TEST_CYCLE; i++) { 34 | generatorA.nextValue(); 35 | generatorB.nextValue(); 36 | if (judge(generatorA.value, generatorB.value)) { 37 | matched++; 38 | } 39 | } 40 | return matched; 41 | } 42 | 43 | boolean judge(long a, long b) { 44 | return (a % 65536) == (b % 65536); // 2 ^ 16 45 | } 46 | 47 | class Generator { 48 | final long factor; 49 | long value; 50 | long multiple; 51 | 52 | Generator(long factor, long originValue, long multiple) { 53 | this.factor = factor; 54 | value = originValue; 55 | this.multiple = multiple; 56 | } 57 | 58 | long nextValue() { 59 | do { 60 | value = (value * factor) % 2147483647; 61 | } while ((value % multiple) != 0); 62 | return value; 63 | } 64 | } 65 | 66 | @Test 67 | public void unitTest() { 68 | assertEquals(309, totalMatchingPairs(65, 8921)); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day17Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import static org.junit.Assert.assertEquals; 5 | 6 | import java.io.IOException; 7 | import java.util.LinkedList; 8 | import java.util.List; 9 | 10 | import org.junit.Test; 11 | 12 | public class Day17Part1 { 13 | final static int ENDING_SIZE = 2018; 14 | final static int STEPPING = 354; 15 | 16 | public static void main(String... args) throws IOException { 17 | Day17Part1 solution = new Day17Part1(); 18 | solution.run(); 19 | } 20 | 21 | void run() throws IOException { 22 | var result = findShortCircuitNumber(STEPPING); 23 | System.out.println("What is the value after 2017 in your completed circular buffer? " + result); 24 | } 25 | 26 | int findShortCircuitNumber(int stepping) { 27 | List list = new LinkedList<>(); 28 | list.add(0); 29 | int pos = 0; 30 | for (int i = 1; i < ENDING_SIZE; i++) { 31 | pos = nextState(list, pos, i, stepping); 32 | } 33 | return list.get(pos + 1); 34 | } 35 | 36 | int nextState(List buffer, int position, int nextValue, int stepping) { 37 | position = (position + stepping) % buffer.size(); 38 | buffer.add(position + 1, nextValue); 39 | return position + 1; 40 | } 41 | 42 | @Test 43 | public void unitTest() { 44 | assertEquals(638, findShortCircuitNumber(3)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day17Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import java.io.IOException; 5 | 6 | public class Day17Part2 { 7 | final static int ENDING_SIZE = 50_000_000; 8 | final static int STEPPING = 354; 9 | 10 | public static void main(String... args) throws IOException { 11 | Day17Part2 solution = new Day17Part2(); 12 | solution.run(); 13 | } 14 | 15 | void run() throws IOException { 16 | var result = findShortCircuitNumber(STEPPING, ENDING_SIZE); 17 | System.out.println("What is the value after 0 the moment 50000000 is inserted? " + result); 18 | } 19 | 20 | int findShortCircuitNumber(int stepping, int finalSize) { 21 | int valueAtPosition1 = -1; 22 | int currentPosition = 0; 23 | for (int i = 1; i <= finalSize; i++) { 24 | currentPosition = ((currentPosition + stepping) % i) + 1; 25 | if (currentPosition == 1) { 26 | valueAtPosition1 = i; 27 | } 28 | } 29 | return valueAtPosition1; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day1Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import java.io.IOException; 10 | 11 | public class Day1Part1 { 12 | Logger log = LoggerFactory.getLogger(Day1Part1.class); 13 | final static String inputFile = "2017/day1_1.txt"; 14 | 15 | public static void main(String... args) throws IOException { 16 | Day1Part1 solution = new Day1Part1(); 17 | solution.run(); 18 | } 19 | 20 | void run() throws IOException { 21 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 22 | var result = calculateCaptcha(lines.get(0)); 23 | log.warn("What is the solution to your captcha? {}", result); 24 | } 25 | 26 | public int calculateCaptcha(String input) { 27 | int captcha = 0; 28 | for (int i=0; i components, boolean[] tookComponents, int inputPins, int strength) { 28 | int strongestStrength = strength; 29 | for (int i = 0; i < components.size(); i++) { 30 | if (!tookComponents[i]) { 31 | Component component = components.get(i); 32 | if (component.port1 == inputPins || components.get(i).port2 == inputPins) { 33 | boolean[] nextTookComponents = tookComponents.clone(); 34 | nextTookComponents[i] = true; 35 | int nextPins = (component.port1 == inputPins) ? component.port2 : component.port1; 36 | int newStrength = strongestBridges(components, nextTookComponents, nextPins, strength + component.strength()); 37 | strongestStrength = Math.max(strongestStrength, newStrength); 38 | } 39 | } 40 | } 41 | return strongestStrength; 42 | } 43 | 44 | List parseComponent(List inputs) { 45 | return inputs.stream().map(s -> s.split("/")) 46 | .map(arr -> new Component(Integer.valueOf(arr[0]), Integer.valueOf(arr[1]))) 47 | .toList(); 48 | } 49 | 50 | record Component(int port1, int port2) { 51 | int strength() { return port1 + port2; } 52 | } 53 | 54 | @Test 55 | public void unitTest() throws Exception { 56 | var lines = Resources.readLines(ClassLoader.getSystemResource("2017/day24_test.txt"), Charsets.UTF_8); 57 | assertEquals(31, strongestBridges(parseComponent(lines), new boolean[lines.size()], 0, 0)); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day2Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import java.io.IOException; 10 | import java.util.List; 11 | 12 | public class Day2Part1 { 13 | Logger log = LoggerFactory.getLogger(Day2Part1.class); 14 | final static String inputFile = "2017/day2_1.txt"; 15 | 16 | public static void main(String... args) throws IOException { 17 | Day2Part1 solution = new Day2Part1(); 18 | solution.run(); 19 | } 20 | 21 | void run() throws IOException { 22 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 23 | var result = calculateChecksum(lines); 24 | log.warn("What is the checksum for the spreadsheet in your puzzle input? {}", result); 25 | } 26 | 27 | public int calculateChecksum(List input) { 28 | return input.stream().mapToInt(this::calulateDifference).sum(); 29 | } 30 | 31 | int calulateDifference(String line) { 32 | int min = Integer.MAX_VALUE; 33 | int max = Integer.MIN_VALUE; 34 | for (String input : line.split("\\s+")) { 35 | int value = Integer.valueOf(input); 36 | if (value < min) min = value; 37 | if (value > max) max = value; 38 | } 39 | return max - min; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day2Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import java.io.IOException; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class Day2Part2 { 14 | Logger log = LoggerFactory.getLogger(Day2Part2.class); 15 | final static String inputFile = "2017/day2_1.txt"; 16 | 17 | public static void main(String... args) throws IOException { 18 | Day2Part2 solution = new Day2Part2(); 19 | solution.run(); 20 | } 21 | 22 | void run() throws IOException { 23 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 24 | var result = sumAllChecksum(lines); 25 | log.warn("What is the sum of each row's result in your puzzle input? {}", result); 26 | } 27 | 28 | public int sumAllChecksum(List input) { 29 | return input.stream().mapToInt(this::calculateChecksum).sum(); 30 | } 31 | 32 | int calculateChecksum(String line) { 33 | var values = Arrays.stream(line.split("\\s+")).mapToInt(Integer::valueOf).toArray(); 34 | for (int i=0; i(); 29 | for (String phrase : input.split(" ")) { 30 | if (!phrases.add(phrase)) 31 | return false; 32 | } 33 | return true; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day4Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import java.io.IOException; 10 | import java.util.Arrays; 11 | import java.util.HashSet; 12 | 13 | public class Day4Part2 { 14 | Logger log = LoggerFactory.getLogger(Day4Part2.class); 15 | final static String inputFile = "2017/day4_1.txt"; 16 | 17 | public static void main(String... args) throws IOException { 18 | Day4Part2 solution = new Day4Part2(); 19 | solution.run(); 20 | } 21 | 22 | void run() throws IOException { 23 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 24 | var result = lines.stream().filter(this::isValidPassPhrase).count(); 25 | log.warn("How many passphrases are valid? {}", result); 26 | } 27 | 28 | boolean isValidPassPhrase(String input) { 29 | var phrases = new HashSet(); 30 | for (String phrase : input.split(" ")) { 31 | var chars = phrase.toCharArray(); 32 | Arrays.sort(chars); 33 | if (!phrases.add(new String(chars))) 34 | return false; 35 | } 36 | return true; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day5Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | import org.junit.Test; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import java.io.IOException; 11 | import java.util.List; 12 | 13 | public class Day5Part1 { 14 | Logger log = LoggerFactory.getLogger(Day5Part1.class); 15 | final static String inputFile = "2017/day5_1.txt"; 16 | 17 | public static void main(String... args) throws IOException { 18 | Day5Part1 solution = new Day5Part1(); 19 | solution.run(); 20 | } 21 | 22 | void run() throws IOException { 23 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 24 | var result = runInstruction(convertToArray(lines)); 25 | log.warn("How many steps does it take to reach the exit? {}", result); 26 | } 27 | 28 | int runInstruction(int[] instructions) { 29 | int steps = 0, position = 0; 30 | while (position > -1 && position < instructions.length) { 31 | int value = instructions[position]; 32 | instructions[position]++; 33 | position += value; 34 | steps++; 35 | } 36 | return steps; 37 | } 38 | 39 | int[] convertToArray(List inputs) { 40 | int[] result = new int[inputs.size()]; 41 | for (int i=0; i -1 && position < instructions.length) { 30 | int value = instructions[position]; 31 | if (value >= 3) { 32 | instructions[position]--; 33 | } else { 34 | instructions[position]++; 35 | } 36 | position += value; 37 | steps++; 38 | } 39 | return steps; 40 | } 41 | 42 | int[] convertToArray(List inputs) { 43 | int[] result = new int[inputs.size()]; 44 | for (int i=0; i lines) { 30 | var strings = lines.get(0).split("\\s"); 31 | int[] result = new int[strings.length]; 32 | for (int i=0; i(); 41 | String pattern = ""; 42 | while(true) { 43 | count++; 44 | banks = redistribution(banks); 45 | pattern = Arrays.toString(banks); 46 | if (patterns.contains(pattern)) 47 | return count; 48 | patterns.add(pattern); 49 | } 50 | } 51 | 52 | int[] redistribution(int[] banks) { 53 | int position = positionWithMostBlocks(banks); 54 | int blocks = banks[position]; 55 | banks[position] = 0; 56 | while (blocks > 0) { 57 | blocks--; 58 | position++; 59 | if (position >= banks.length) position = 0; 60 | banks[position]++; 61 | } 62 | return banks; 63 | } 64 | 65 | int positionWithMostBlocks(int[] banks) { 66 | int position = 0; 67 | int maxBlocks = banks[0]; 68 | for (int i=1; i maxBlocks) { 70 | maxBlocks = banks[i]; 71 | position = i; 72 | } 73 | } 74 | return position; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day9Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import java.io.IOException; 10 | 11 | public class Day9Part1 { 12 | final static String inputFile = "2017/day9_1.txt"; 13 | 14 | public static void main(String... args) throws IOException { 15 | Day9Part1 solution = new Day9Part1(); 16 | solution.run(); 17 | } 18 | 19 | void run() throws IOException { 20 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 21 | var result = totalScore(lines.get(0).toCharArray()); 22 | System.out.printf("What is the total score for all groups in your input? %d %n", result); 23 | } 24 | 25 | int totalScore(char[] input) { 26 | int score = 0; 27 | int total = 0; 28 | boolean isGarbage = false; 29 | for (int i=0; i') { 36 | isGarbage = false; 37 | } else if (c == '{' && !isGarbage) { 38 | score++; 39 | } else if (c == '}' && !isGarbage) { 40 | total += score; 41 | score--; 42 | } 43 | } 44 | 45 | return total; 46 | } 47 | 48 | @Test 49 | public void unitTest() { 50 | Assert.assertEquals(1, totalScore("{}".toCharArray())); 51 | Assert.assertEquals(6, totalScore("{{{}}}".toCharArray())); 52 | Assert.assertEquals(5, totalScore("{{},{}}".toCharArray())); 53 | Assert.assertEquals(16, totalScore("{{{},{},{{}}}}".toCharArray())); 54 | Assert.assertEquals(1, totalScore("{,,,}".toCharArray())); 55 | Assert.assertEquals(9, totalScore("{{},{},{},{}}".toCharArray())); 56 | Assert.assertEquals(9, totalScore("{{},{},{},{}}".toCharArray())); 57 | Assert.assertEquals(3, totalScore("{{},{},{},{}}".toCharArray())); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2017/Day9Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2017; 2 | 3 | 4 | import com.google.common.base.Charsets; 5 | import com.google.common.io.Resources; 6 | import org.junit.Test; 7 | 8 | import java.io.IOException; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class Day9Part2 { 13 | final static String inputFile = "2017/day9_1.txt"; 14 | 15 | public static void main(String... args) throws IOException { 16 | Day9Part2 solution = new Day9Part2(); 17 | solution.run(); 18 | } 19 | 20 | void run() throws IOException { 21 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 22 | var result = totalGarbage(lines.get(0).toCharArray()); 23 | System.out.printf("How many non-canceled characters are within the garbage in your puzzle input? %d %n", result); 24 | } 25 | 26 | int totalGarbage(char[] input) { 27 | int totalGarbage = 0; 28 | boolean isGarbage = false; 29 | for (int i=0; i') { 36 | isGarbage = false; 37 | } else if (isGarbage) { 38 | totalGarbage++; 39 | } 40 | } 41 | 42 | return totalGarbage; 43 | } 44 | 45 | @Test 46 | public void unitTest() { 47 | assertEquals(0, totalGarbage("<>".toCharArray())); 48 | assertEquals(17, totalGarbage("".toCharArray())); 49 | assertEquals(3, totalGarbage("<<<<>".toCharArray())); 50 | assertEquals(2, totalGarbage("<{!>}>".toCharArray())); 51 | assertEquals(0, totalGarbage("".toCharArray())); 52 | assertEquals(0, totalGarbage(">".toCharArray())); 53 | assertEquals(10, totalGarbage("<{o\"i!a,<{i".toCharArray())); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2018/Day1Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2018; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class Day1Part1 { 12 | Logger log = LoggerFactory.getLogger(Day1Part1.class); 13 | final static String inputFile = "2018/day1.txt"; 14 | 15 | public static void main(String... args) throws IOException { 16 | Day1Part1 solution = new Day1Part1(); 17 | solution.run(); 18 | } 19 | 20 | void run() throws IOException { 21 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 22 | var result = calculateFrequency(lines); 23 | log.warn("What is the first frequency your device reaches twice? {}", result); 24 | } 25 | 26 | public int calculateFrequency(List inputs) { 27 | int frequency = 0; 28 | for (String s : inputs) { 29 | frequency += Integer.parseInt(s); 30 | } 31 | return frequency; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2018/Day1Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2018; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.IOException; 9 | import java.util.HashSet; 10 | import java.util.List; 11 | import java.util.Set; 12 | 13 | public class Day1Part2 { 14 | Logger log = LoggerFactory.getLogger(Day1Part2.class); 15 | final static String inputFile = "2018/day1.txt"; 16 | 17 | public static void main(String... args) throws IOException { 18 | Day1Part2 solution = new Day1Part2(); 19 | solution.run(); 20 | } 21 | 22 | void run() throws IOException { 23 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 24 | var result = firstDuplicateFrequency(lines); 25 | log.warn("What is the first frequency your device reaches twice? {}", result); 26 | } 27 | 28 | public int firstDuplicateFrequency(List inputs) { 29 | int frequency = 0; 30 | Set frequencies = new HashSet<>(); 31 | frequencies.add(frequency); 32 | while (true) { 33 | for (String s : inputs) { 34 | frequency += Integer.parseInt(s); 35 | if (frequencies.contains(frequency)) { 36 | return frequency; 37 | } 38 | frequencies.add(frequency); 39 | } 40 | } 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2018/Day2Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2018; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | 6 | import org.junit.Test; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | import java.io.IOException; 13 | import java.util.List; 14 | import java.util.Map; 15 | import java.util.function.Function; 16 | import java.util.stream.Collectors; 17 | 18 | public class Day2Part1 { 19 | Logger log = LoggerFactory.getLogger(Day2Part1.class); 20 | final static String inputFile = "2018/day2.txt"; 21 | 22 | public static void main(String... args) throws IOException { 23 | Day2Part1 solution = new Day2Part1(); 24 | solution.run(); 25 | } 26 | 27 | void run() throws IOException { 28 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 29 | var result = checksum(lines); 30 | log.warn("What is the checksum for your list of box IDs? {}", result); 31 | } 32 | 33 | public long checksum(List inputs) { 34 | return boxesWithExactXOfAnyLetter(inputs, 2) * boxesWithExactXOfAnyLetter(inputs, 3); 35 | } 36 | 37 | long boxesWithExactXOfAnyLetter(List inputs, long matchingCount) { 38 | return inputs.stream() 39 | .filter(s -> isExactXOfAnyLetter(s, matchingCount)) 40 | .count(); 41 | } 42 | 43 | boolean isExactXOfAnyLetter(String input, long matchingCount) { 44 | Map counts = input.chars().boxed() 45 | .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); 46 | return counts.values().contains(matchingCount); 47 | } 48 | 49 | @Test 50 | public void unitTest() throws IOException { 51 | var lines = Resources.readLines(ClassLoader.getSystemResource("2018/day2_test.txt"), Charsets.UTF_8); 52 | assertEquals(12, checksum(lines)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2018/Day2Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2018; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.IOException; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import com.google.common.base.Charsets; 13 | import com.google.common.io.Resources; 14 | 15 | public class Day2Part2 { 16 | Logger log = LoggerFactory.getLogger(Day2Part2.class); 17 | final static String inputFile = "2018/day2.txt"; 18 | 19 | public static void main(String... args) throws IOException { 20 | Day2Part2 solution = new Day2Part2(); 21 | solution.run(); 22 | } 23 | 24 | void run() throws IOException { 25 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 26 | var result = correctBoxIdUnionCharacters(lines); 27 | log.warn("What is the checksum for your list of box IDs? {}", result); 28 | } 29 | 30 | String correctBoxIdUnionCharacters(List inputs) { 31 | for (String s1 : inputs) { 32 | for (String s2 : inputs) { 33 | if (!s1.equals(s2) && isExactOneCharacterDiff(s1, s2)) { 34 | return removeDiff(s1, s2); 35 | } 36 | } 37 | } 38 | throw new RuntimeException("cannot find correct boxes"); 39 | } 40 | 41 | 42 | String removeDiff(String s1, String s2) { 43 | StringBuilder sb = new StringBuilder(); 44 | for (int i = 0; i < s1.length(); i++) { 45 | if (s1.charAt(i) == s2.charAt(i)) { 46 | sb.append(s1.charAt(i)); 47 | } 48 | } 49 | return sb.toString(); 50 | } 51 | 52 | boolean isExactOneCharacterDiff(String s1, String s2) { 53 | boolean hasDiff = false; 54 | for (int i = 0; i < s1.length(); i++) { 55 | if (s1.charAt(i) != s2.charAt(i)) { 56 | if (hasDiff) 57 | return false; 58 | else 59 | hasDiff = true; 60 | } 61 | } 62 | return hasDiff; 63 | } 64 | 65 | @Test 66 | public void unitTest() throws IOException { 67 | var lines = Resources.readLines(ClassLoader.getSystemResource("2018/day2_test2.txt"), Charsets.UTF_8); 68 | assertEquals("fgij", correctBoxIdUnionCharacters(lines)); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2018/Day5Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2018; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.IOException; 6 | import java.time.format.DateTimeFormatter; 7 | import java.util.Deque; 8 | import java.util.LinkedList; 9 | 10 | import org.junit.Test; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | 14 | import com.google.common.base.Charsets; 15 | import com.google.common.io.Resources; 16 | 17 | public class Day5Part1 { 18 | final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); 19 | 20 | Logger log = LoggerFactory.getLogger(Day5Part1.class); 21 | final static String inputFile = "2018/day5.txt"; 22 | 23 | public static void main(String... args) throws IOException { 24 | Day5Part1 solution = new Day5Part1(); 25 | solution.run(); 26 | } 27 | 28 | void run() throws IOException { 29 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 30 | var result = remainUnits(lines.get(0)); 31 | log.warn("How many units remain after fully reacting the polymer you scanned? {}", result); 32 | } 33 | 34 | int remainUnits(String polymer) { 35 | Deque result = new LinkedList<>(); 36 | for (char unit : polymer.toCharArray()) { 37 | if (result.size() > 0 && canReact(result.peekLast(), unit)) { 38 | result.pollLast(); 39 | continue; 40 | } 41 | result.add(unit); 42 | } 43 | return result.size(); 44 | } 45 | 46 | boolean canReact(char unit1, char unit2) { 47 | return (Character.isLowerCase(unit1) && Character.toUpperCase(unit1) == unit2) 48 | || (Character.isUpperCase(unit1) && Character.toLowerCase(unit1) == unit2); 49 | } 50 | 51 | @Test 52 | public void unitTest() throws IOException { 53 | assertEquals(10, remainUnits("dabAcCaCBAcCcaDA")); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2019/Day1Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2019; 2 | 3 | 4 | import java.io.IOException; 5 | 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.google.common.base.Charsets; 12 | import com.google.common.io.Resources; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | 16 | public class Day1Part1 { 17 | Logger log = LoggerFactory.getLogger(Day1Part1.class); 18 | final static String inputFile = "2019/day1_1.txt"; 19 | 20 | public static void main(String... args) throws IOException { 21 | Day1Part1 solution = new Day1Part1(); 22 | solution.run(); 23 | } 24 | 25 | void run() throws IOException { 26 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 27 | var result = lines.stream() 28 | .map(Integer::valueOf) 29 | .mapToInt(this::fuelRequiredForModule) 30 | .sum(); 31 | log.warn("What is the sum of the fuel requirements = {}", result); 32 | } 33 | 34 | public int fuelRequiredForModule(int mass) { 35 | return mass / 3 - 2; 36 | } 37 | 38 | @Test 39 | public void testcases() { 40 | assertEquals(2, fuelRequiredForModule(12)); 41 | assertEquals(2, fuelRequiredForModule(14)); 42 | Assert.assertEquals(654, fuelRequiredForModule(1969)); 43 | Assert.assertEquals(33583, fuelRequiredForModule(100756)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2019/Day1Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2019; 2 | 3 | 4 | import java.io.IOException; 5 | 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.google.common.base.Charsets; 12 | import com.google.common.io.Resources; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | 16 | public class Day1Part2 { 17 | Logger log = LoggerFactory.getLogger(Day1Part2.class); 18 | final static String inputFile = "2019/day1_1.txt"; 19 | 20 | public static void main(String... args) throws IOException { 21 | Day1Part2 solution = new Day1Part2(); 22 | solution.firstStar(); 23 | } 24 | 25 | void firstStar() throws IOException { 26 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 27 | var result = lines.stream() 28 | .map(Integer::valueOf) 29 | .mapToInt(this::fuelRequiredForModule) 30 | .sum(); 31 | log.warn("What is the sum of the fuel requirements = {}", result); 32 | } 33 | 34 | public int fuelRequiredForModule(int mass) { 35 | int fuel = mass / 3 - 2; 36 | if (fuel <= 0) 37 | return 0; 38 | else 39 | return fuel + fuelRequiredForModule(fuel); 40 | } 41 | 42 | @Test 43 | public void testcases() { 44 | assertEquals(2, fuelRequiredForModule(14)); 45 | Assert.assertEquals(966, fuelRequiredForModule(1969)); 46 | Assert.assertEquals(50346, fuelRequiredForModule(100756)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2019/Day4Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2019; 2 | 3 | 4 | import org.junit.Test; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.IOException; 9 | import java.util.stream.IntStream; 10 | 11 | import static org.junit.Assert.assertFalse; 12 | import static org.junit.Assert.assertTrue; 13 | 14 | public class Day4Part1 { 15 | Logger log = LoggerFactory.getLogger(Day4Part1.class); 16 | 17 | public static void main(String... args) throws IOException { 18 | Day4Part1 solution = new Day4Part1(); 19 | solution.run(); 20 | } 21 | 22 | void run() throws IOException { 23 | var result = totalPasswords(234208, 765869); 24 | log.warn("How many different passwords = {}", result); 25 | } 26 | 27 | long totalPasswords(int from, int to) { 28 | return IntStream.rangeClosed(from, to).mapToObj(String::valueOf) 29 | .filter(this::isPassword) 30 | .count(); 31 | } 32 | 33 | boolean isPassword(String value) { 34 | boolean digitNeverDecrease = true, sameTwoAdjacentDigits = false; 35 | for (int i = 1; i < value.length(); i++) { 36 | if (value.charAt(i-1) == value.charAt(i)) sameTwoAdjacentDigits = true; 37 | if (value.charAt(i-1) > value.charAt(i)) digitNeverDecrease = false; 38 | } 39 | return digitNeverDecrease && sameTwoAdjacentDigits; 40 | } 41 | 42 | @Test 43 | public void program_testcases() { 44 | assertTrue(isPassword("111111")); 45 | assertFalse(isPassword("223450")); 46 | assertFalse(isPassword("123789")); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2019/Day4Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2019; 2 | 3 | 4 | import org.junit.Test; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.IOException; 9 | import java.util.stream.IntStream; 10 | 11 | import static org.junit.Assert.assertFalse; 12 | import static org.junit.Assert.assertTrue; 13 | 14 | public class Day4Part2 { 15 | Logger log = LoggerFactory.getLogger(Day4Part2.class); 16 | 17 | public static void main(String... args) throws IOException { 18 | Day4Part2 solution = new Day4Part2(); 19 | solution.run(); 20 | } 21 | 22 | void run() throws IOException { 23 | var result = totalPasswords(234208, 765869); 24 | log.warn("How many different passwords = {}", result); 25 | } 26 | 27 | long totalPasswords(int from, int to) { 28 | return IntStream.rangeClosed(from, to).mapToObj(String::valueOf) 29 | .filter(this::isPassword) 30 | .count(); 31 | } 32 | 33 | boolean isPassword(String value) { 34 | boolean digitNeverDecrease = true; 35 | boolean exactSameTwoAdjacentDigits = false; 36 | 37 | for (int i = 1; i < value.length(); i++) { 38 | if (isExactSameTwoAdjacentDigits(value, i)) exactSameTwoAdjacentDigits = true; 39 | if (value.charAt(i-1) > value.charAt(i)) digitNeverDecrease = false; 40 | } 41 | 42 | return digitNeverDecrease && exactSameTwoAdjacentDigits; 43 | } 44 | 45 | private boolean isExactSameTwoAdjacentDigits(String value, int i) { 46 | if (value.charAt(i-1) != value.charAt(i)) return false; 47 | if (i >= 2 && value.charAt(i-2) == value.charAt(i-1)) return false; 48 | if (i < value.length() - 1 && value.charAt(i) == value.charAt(i+1)) return false; 49 | return true; 50 | } 51 | 52 | @Test 53 | public void program_testcases() { 54 | assertTrue(isPassword("112233")); 55 | assertTrue(isPassword("111122")); 56 | assertFalse(isPassword("123444")); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2019/Day8Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2019; 2 | 3 | 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.google.common.base.Charsets; 12 | import com.google.common.io.Resources; 13 | 14 | public class Day8Part1 { 15 | Logger log = LoggerFactory.getLogger(Day8Part1.class); 16 | final static String inputFile = "2019/day8_1.txt"; 17 | final static int PROGRAM_OUTPUT = -1; 18 | 19 | public static void main(String... args) throws IOException { 20 | Day8Part1 solution = new Day8Part1(); 21 | solution.run(); 22 | } 23 | 24 | void run() throws IOException { 25 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 26 | var layer = fewest0Layer(convertToLayer(lines.get(0), 25, 6)); 27 | var result = layer.totalDigits('1') * layer.totalDigits('2'); 28 | log.warn("what is the number of 1 digits multiplied by the number of 2 digits = {}", result); 29 | } 30 | 31 | Layer fewest0Layer(List layers) { 32 | long fewestZero = Integer.MAX_VALUE; 33 | Layer fewestZeroLayer = null; 34 | for (Layer l : layers) { 35 | long totalZero = l.totalDigits('0'); 36 | if (totalZero < fewestZero) { 37 | fewestZero = totalZero; 38 | fewestZeroLayer = l; 39 | } 40 | } 41 | return fewestZeroLayer; 42 | } 43 | 44 | List convertToLayer(String input, int wide, int tall) { 45 | var layers = new ArrayList(); 46 | int size = wide * tall; 47 | int pointer = size; 48 | while (pointer <= input.length()) { 49 | layers.add(new Layer(input.substring(pointer-size, pointer))); 50 | pointer += size; 51 | } 52 | return layers; 53 | } 54 | 55 | class Layer { 56 | String digits; 57 | 58 | public Layer(String digits) { 59 | this.digits = digits; 60 | } 61 | 62 | public long totalDigits(char s) { 63 | return digits.chars().filter(c -> c == s).count(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2022/Day10Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2022; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.IOException; 6 | import java.nio.charset.Charset; 7 | import java.nio.file.Files; 8 | import java.nio.file.Paths; 9 | import java.util.List; 10 | 11 | import org.junit.Test; 12 | 13 | import com.google.common.base.Charsets; 14 | import com.google.common.io.Resources; 15 | 16 | public class Day10Part1 { 17 | final static String inputFile = "2022/day10.txt"; 18 | final static List CYCLES_TO_CAPTURE = List.of(20, 60, 100, 140, 180, 220); 19 | 20 | public static void main(String... args) throws IOException { 21 | Day10Part1 solution = new Day10Part1(); 22 | solution.run(); 23 | } 24 | 25 | void run() throws IOException { 26 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 27 | var result = sumOfSignalStrengths(lines); 28 | System.out.println("What is the sum of these six signal strengths? " + result); 29 | } 30 | 31 | int sumOfSignalStrengths(List inputs) { 32 | int sum = 0; 33 | int cycle = 0; 34 | int x = 1; 35 | 36 | for (String s : inputs) { 37 | if ("noop".equals(s)) { 38 | cycle++; 39 | if (CYCLES_TO_CAPTURE.contains(cycle)) sum += x * cycle; 40 | } else if (s.startsWith("addx")) { 41 | cycle++; 42 | if (CYCLES_TO_CAPTURE.contains(cycle)) sum += x * cycle; 43 | cycle++; 44 | if (CYCLES_TO_CAPTURE.contains(cycle)) sum += x * cycle; 45 | x += Integer.parseInt(s.split(" ")[1]); 46 | } 47 | } 48 | 49 | return sum; 50 | } 51 | 52 | 53 | @Test 54 | public void unitTest() throws Exception { 55 | var lines = Files.readAllLines(Paths.get(ClassLoader.getSystemResource("2022/day10_test.txt").toURI()), Charset.defaultCharset()); 56 | 57 | assertEquals(13140, sumOfSignalStrengths(lines)); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2022/Day10Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2022; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.IOException; 6 | import java.nio.charset.Charset; 7 | import java.nio.file.Files; 8 | import java.nio.file.Paths; 9 | import java.util.List; 10 | 11 | import org.junit.Test; 12 | 13 | import com.google.common.base.Charsets; 14 | import com.google.common.io.Resources; 15 | 16 | public class Day10Part2 { 17 | final static String inputFile = "2022/day10.txt"; 18 | 19 | public static void main(String... args) throws IOException { 20 | Day10Part2 solution = new Day10Part2(); 21 | solution.run(); 22 | } 23 | 24 | void run() throws IOException { 25 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 26 | var result = CRTString(lines); 27 | System.out.println("What eight capital letters appear on your CRT?"); 28 | printCRT(result); 29 | } 30 | 31 | void printCRT(String string) { 32 | for (int i = 0; i < 6; i++) { 33 | System.out.println(string.substring(i * 40, (i+1) * 40)); 34 | } 35 | } 36 | 37 | String CRTString(List inputs) { 38 | var state = new State(); 39 | 40 | for (String s : inputs) { 41 | if ("noop".equals(s)) { 42 | nextCycle(state); 43 | } else if (s.startsWith("addx")) { 44 | nextCycle(state); 45 | nextCycle(state); 46 | state.spritePosition += Integer.parseInt(s.split(" ")[1]); 47 | } 48 | } 49 | 50 | return state.sb.toString(); 51 | } 52 | 53 | void nextCycle(State state) { 54 | state.cycle++; 55 | state.sb.append(onSprite(state.cycle, state.spritePosition) ? '#' : '.'); 56 | } 57 | 58 | boolean onSprite(int p, int spritePosition) { 59 | return spritePosition <= p % 40 && p % 40 <= spritePosition + 2; 60 | } 61 | 62 | class State { 63 | int sum = 0; 64 | int cycle = 0; 65 | int spritePosition = 1; 66 | StringBuilder sb = new StringBuilder(); 67 | } 68 | 69 | 70 | @Test 71 | public void unitTest() throws Exception { 72 | var lines = Files.readAllLines(Paths.get(ClassLoader.getSystemResource("2022/day10_test.txt").toURI()), Charset.defaultCharset()); 73 | var string = CRTString(lines); 74 | assertEquals("##..##..##..##..##..##..##..##..##..##..", string.substring(0, 40)); 75 | assertEquals("###...###...###...###...###...###...###.", string.substring(40, 80)); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2022/Day18Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2022; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.junit.Test; 6 | 7 | import java.io.IOException; 8 | import java.nio.file.Files; 9 | import java.nio.file.Paths; 10 | import java.util.List; 11 | import java.util.Set; 12 | import java.util.stream.Collectors; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | 16 | public class Day18Part1 { 17 | final static String inputFile = "2022/day18.txt"; 18 | 19 | public static void main(String... args) throws IOException { 20 | Day18Part1 solution = new Day18Part1(); 21 | solution.run(); 22 | } 23 | 24 | void run() throws IOException { 25 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 26 | var result = totalExposedSides(parseInput(lines)); 27 | System.out.println("What is the surface area of your scanned lava droplet? " + result); 28 | } 29 | 30 | int totalExposedSides(Set cubes) { 31 | return cubes.stream().mapToInt(c -> exposedSides(c, cubes)).sum(); 32 | } 33 | 34 | int exposedSides(Position cube, Set cubes) { 35 | int exposedSides = 0; 36 | if (!cubes.contains(new Position(cube.x + 1, cube.y, cube.z))) exposedSides++; 37 | if (!cubes.contains(new Position(cube.x - 1, cube.y, cube.z))) exposedSides++; 38 | if (!cubes.contains(new Position(cube.x, cube.y + 1, cube.z))) exposedSides++; 39 | if (!cubes.contains(new Position(cube.x, cube.y - 1, cube.z))) exposedSides++; 40 | if (!cubes.contains(new Position(cube.x, cube.y, cube.z + 1))) exposedSides++; 41 | if (!cubes.contains(new Position(cube.x, cube.y, cube.z - 1))) exposedSides++; 42 | return exposedSides; 43 | } 44 | 45 | Set parseInput(List inputs) { 46 | return inputs.stream().map(i -> { 47 | var pos = i.split(","); 48 | return new Position(Integer.parseInt(pos[0]), Integer.parseInt(pos[1]), Integer.parseInt(pos[2])); 49 | }).collect(Collectors.toSet()); 50 | } 51 | 52 | record Position(int x, int y, int z) {} 53 | 54 | @Test 55 | public void unitTest() throws Exception { 56 | var lines = Files.readAllLines(Paths.get(ClassLoader.getSystemResource("2022/day18_test.txt").toURI())); 57 | assertEquals(64, totalExposedSides(parseInput(lines))); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2022/Day1Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2022; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | 6 | import org.junit.Test; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | import java.io.IOException; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class Day1Part1 { 17 | Logger log = LoggerFactory.getLogger(Day1Part1.class); 18 | final static String inputFile = "2022/day1.txt"; 19 | 20 | public static void main(String... args) throws IOException { 21 | Day1Part1 solution = new Day1Part1(); 22 | solution.run(); 23 | } 24 | 25 | void run() throws IOException { 26 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 27 | var result = mostCalories(lines); 28 | log.warn("How many total Calories is that Elf carrying? {}", result); 29 | } 30 | 31 | public int mostCalories(List inputs) { 32 | List caloriesOfElfs = new ArrayList<>(); 33 | int sum = 0; 34 | for (String s : inputs) { 35 | if ("".equals(s)) { 36 | caloriesOfElfs.add(sum); 37 | sum = 0; 38 | } else { 39 | sum += Integer.parseInt(s); 40 | } 41 | } 42 | return caloriesOfElfs.stream().mapToInt(v -> v).max().getAsInt(); 43 | } 44 | 45 | @Test 46 | public void unitTest() throws IOException { 47 | var lines = Resources.readLines(ClassLoader.getSystemResource("2022/day1_test.txt"), Charsets.UTF_8); 48 | assertEquals(24000, mostCalories(lines)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2022/Day1Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2022; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | 6 | import org.junit.Test; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | import java.io.IOException; 13 | import java.util.ArrayList; 14 | import java.util.Collections; 15 | import java.util.List; 16 | 17 | public class Day1Part2 { 18 | Logger log = LoggerFactory.getLogger(Day1Part1.class); 19 | final static String inputFile = "2022/day1.txt"; 20 | 21 | public static void main(String... args) throws IOException { 22 | Day1Part2 solution = new Day1Part2(); 23 | solution.run(); 24 | } 25 | 26 | void run() throws IOException { 27 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 28 | var result = sumOftopThreeCalories(lines); 29 | log.warn("How many Calories are those Elves carrying in total? {}", result); 30 | } 31 | 32 | public int sumOftopThreeCalories(List inputs) { 33 | List caloriesOfElfs = new ArrayList<>(); 34 | int sum = 0; 35 | for (String s : inputs) { 36 | if ("".equals(s)) { 37 | caloriesOfElfs.add(sum); 38 | sum = 0; 39 | } else { 40 | sum += Integer.parseInt(s); 41 | } 42 | } 43 | caloriesOfElfs.add(sum); 44 | Collections.sort(caloriesOfElfs); 45 | return caloriesOfElfs.get(caloriesOfElfs.size()-1) + caloriesOfElfs.get(caloriesOfElfs.size()-2) + caloriesOfElfs.get(caloriesOfElfs.size()-3); 46 | } 47 | 48 | @Test 49 | public void unitTest() throws IOException { 50 | var lines = Resources.readLines(ClassLoader.getSystemResource("2022/day1_test.txt"), Charsets.UTF_8); 51 | assertEquals(45000, sumOftopThreeCalories(lines)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2022/Day3Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2022; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import java.io.IOException; 7 | import java.util.Arrays; 8 | import java.util.HashSet; 9 | import java.util.List; 10 | import java.util.Set; 11 | import java.util.stream.Collectors; 12 | 13 | import org.junit.Test; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | 17 | import com.google.common.base.Charsets; 18 | import com.google.common.io.Resources; 19 | 20 | public class Day3Part2 { 21 | Logger log = LoggerFactory.getLogger(Day3Part2.class); 22 | final static String inputFile = "2022/day3.txt"; 23 | 24 | public static void main(String... args) throws IOException { 25 | Day3Part2 solution = new Day3Part2(); 26 | solution.run(); 27 | } 28 | 29 | void run() throws IOException { 30 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 31 | var result = sumOfPrioritiesOfShareItems(lines); 32 | System.out.println("What is the sum of the priorities of those item types? " + result); 33 | } 34 | 35 | int sumOfPrioritiesOfShareItems(List inputs) { 36 | int sum = 0; 37 | for (int i = 0; i < inputs.size(); i += 3) { 38 | sum += prioritesOf(shareItem(inputs.subList(i, i+3))); 39 | } 40 | return sum; 41 | } 42 | 43 | char shareItem(List inputs) { 44 | Set set1 = toSet(inputs.get(0)); 45 | Set set2 = toSet(inputs.get(1)); 46 | Set set3 = toSet(inputs.get(2)); 47 | set1.retainAll(set2); 48 | set1.retainAll(set3); 49 | return set1.iterator().next(); 50 | } 51 | 52 | Set toSet(String input) { 53 | return input.chars().mapToObj(e->(char)e).collect(Collectors.toSet()); 54 | } 55 | 56 | int prioritesOf(char c) { 57 | if (Character.isUpperCase(c)) { 58 | return (int) c - 38; 59 | } else { 60 | return (int) c - 96; 61 | } 62 | } 63 | 64 | @Test 65 | public void unitTest() throws IOException { 66 | assertEquals(16, prioritesOf('p')); 67 | assertEquals(38, prioritesOf('L')); 68 | 69 | var lines = Resources.readLines(ClassLoader.getSystemResource("2022/day3_test.txt"), Charsets.UTF_8); 70 | assertEquals(70, sumOfPrioritiesOfShareItems(lines)); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2022/Day4Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2022; 2 | 3 | import static org.junit.Assert.assertFalse; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import java.io.IOException; 7 | import java.util.List; 8 | 9 | import org.junit.Test; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import com.google.common.base.Charsets; 14 | import com.google.common.io.Resources; 15 | 16 | public class Day4Part1 { 17 | Logger log = LoggerFactory.getLogger(Day4Part1.class); 18 | final static String inputFile = "2022/day4.txt"; 19 | 20 | public static void main(String... args) throws IOException { 21 | Day4Part1 solution = new Day4Part1(); 22 | solution.run(); 23 | } 24 | 25 | void run() throws IOException { 26 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 27 | var result = fullyContainPairs(lines); 28 | System.out.println("In how many assignment pairs does one range fully contain the other? " + result); 29 | } 30 | 31 | long fullyContainPairs(List inputs) { 32 | return inputs.stream().map(this::toRangePair) 33 | .filter(pair -> isFullyContain(pair.range1, pair.range2) || isFullyContain(pair.range2, pair.range1)) 34 | .count(); 35 | } 36 | 37 | RangePair toRangePair(String input) { 38 | var pairs = input.split(","); 39 | return new RangePair(toRange(pairs[0]), toRange(pairs[1])); 40 | } 41 | 42 | Range toRange(String input) { 43 | var numbers = input.split("-"); 44 | return new Range(Integer.parseInt(numbers[0]), Integer.parseInt(numbers[1])); 45 | } 46 | 47 | record RangePair(Range range1, Range range2) {} 48 | 49 | record Range(int start, int end) {} 50 | 51 | boolean isFullyContain(Range inner, Range outer) { 52 | return outer.start <= inner.start && inner.start <= outer.end 53 | && outer.start <= inner.end && inner.end <= outer.end; 54 | } 55 | 56 | @Test 57 | public void unitTest() throws IOException { 58 | assertTrue(isFullyContain(new Range(3, 7), new Range(2, 8))); 59 | assertFalse(isFullyContain(new Range(2, 4), new Range(6, 8))); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2022/Day4Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2022; 2 | 3 | import static org.junit.Assert.assertFalse; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import java.io.IOException; 7 | import java.util.List; 8 | 9 | import org.junit.Test; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import com.google.common.base.Charsets; 14 | import com.google.common.io.Resources; 15 | 16 | public class Day4Part2 { 17 | Logger log = LoggerFactory.getLogger(Day4Part2.class); 18 | final static String inputFile = "2022/day4.txt"; 19 | 20 | public static void main(String... args) throws IOException { 21 | Day4Part2 solution = new Day4Part2(); 22 | solution.run(); 23 | } 24 | 25 | void run() throws IOException { 26 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 27 | var result = overlapPairs(lines); 28 | System.out.println("In how many assignment pairs does one range fully contain the other? " + result); 29 | } 30 | 31 | long overlapPairs(List inputs) { 32 | return inputs.stream().map(this::toRangePair) 33 | .filter(pair -> isOverlap(pair.range1, pair.range2)) 34 | .count(); 35 | } 36 | 37 | RangePair toRangePair(String input) { 38 | var pairs = input.split(","); 39 | return new RangePair(toRange(pairs[0]), toRange(pairs[1])); 40 | } 41 | 42 | Range toRange(String input) { 43 | var numbers = input.split("-"); 44 | return new Range(Integer.parseInt(numbers[0]), Integer.parseInt(numbers[1])); 45 | } 46 | 47 | record RangePair(Range range1, Range range2) {} 48 | 49 | record Range(int start, int end) {} 50 | 51 | boolean isOverlap(Range range1, Range range2) { 52 | return range2.start <= range1.start && range1.start <= range2.end 53 | || range2.start <= range1.end && range1.end <= range2.end 54 | || range1.start <= range2.start && range2.start <= range1.end 55 | || range1.start <= range2.end && range2.end <= range1.end; 56 | } 57 | 58 | @Test 59 | public void unitTest() throws IOException { 60 | assertTrue(isOverlap(new Range(5, 7), new Range(7, 9))); 61 | assertTrue(isOverlap(new Range(2, 8), new Range(3, 7))); 62 | assertFalse(isOverlap(new Range(2, 4), new Range(6, 8))); 63 | assertFalse(isOverlap(new Range(2, 3), new Range(4, 5))); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2023/Day15Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2023; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import java.io.IOException; 11 | import java.util.*; 12 | 13 | public class Day15Part1 { 14 | Logger log = LoggerFactory.getLogger(Day15Part1.class); 15 | final static String inputFile = "2023/day15.txt"; 16 | 17 | public static void main(String... args) throws IOException { 18 | Day15Part1 solution = new Day15Part1(); 19 | solution.run(); 20 | } 21 | 22 | void run() throws IOException { 23 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 24 | var strings = new Day15Part1().parseInput(lines); 25 | var result = sumOfHash(strings); 26 | log.warn("What is the sum of the results? {}", result); 27 | } 28 | 29 | int sumOfHash(List strings) { 30 | return strings.stream().mapToInt(this::hash).sum(); 31 | } 32 | 33 | int hash(String s) { 34 | int value = 0; 35 | for (int i : s.toCharArray()) { 36 | value += i; 37 | value *= 17; 38 | value = value % 256; 39 | } 40 | return value; 41 | } 42 | 43 | //region Data Objects 44 | 45 | //endregion 46 | 47 | //region Input Parsing 48 | 49 | List parseInput(List inputs) { 50 | return Arrays.asList(inputs.get(0).split(",")); 51 | } 52 | 53 | //endregion 54 | 55 | @Test 56 | public void unitTest() throws IOException { 57 | var lines = Resources.readLines(ClassLoader.getSystemResource("2023/day15_test.txt"), Charsets.UTF_8); 58 | var steps = new Day15Part1().parseInput(lines); 59 | var result = sumOfHash(steps); 60 | Assert.assertEquals(1320, result); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2023/Day1Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2023; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.IOException; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import com.google.common.base.Charsets; 13 | import com.google.common.io.Resources; 14 | 15 | public class Day1Part1 { 16 | Logger log = LoggerFactory.getLogger(Day1Part1.class); 17 | final static String inputFile = "2023/day1.txt"; 18 | 19 | public static void main(String... args) throws IOException { 20 | Day1Part1 solution = new Day1Part1(); 21 | solution.run(); 22 | } 23 | 24 | void run() throws IOException { 25 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 26 | var result = sumOfCalibrationValues(lines); 27 | log.warn("What is the sum of all of the calibration values? {}", result); 28 | } 29 | 30 | public long sumOfCalibrationValues(List inputs) { 31 | return inputs.stream().mapToLong(this::getCalibrationValue) 32 | .sum(); 33 | } 34 | 35 | long getCalibrationValue(String input) { 36 | var digits = input.replaceAll("[^0-9]", ""); 37 | return Long.parseLong(digits.substring(0, 1) + digits.substring(digits.length() - 1)); 38 | } 39 | 40 | @Test 41 | public void unitTest() throws IOException { 42 | var lines = Resources.readLines(ClassLoader.getSystemResource("2023/day1_test.txt"), Charsets.UTF_8); 43 | assertEquals(142, sumOfCalibrationValues(lines)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2023/Day2Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2023; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.IOException; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import com.google.common.base.Charsets; 13 | import com.google.common.io.Resources; 14 | 15 | public class Day2Part2 { 16 | Logger log = LoggerFactory.getLogger(Day2Part2.class); 17 | final static String inputFile = "2023/day2.txt"; 18 | 19 | public static void main(String... args) throws IOException { 20 | Day2Part2 solution = new Day2Part2(); 21 | solution.run(); 22 | } 23 | 24 | void run() throws IOException { 25 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 26 | var result = sumOfPowerOfSets(lines); 27 | log.warn("What is the sum of the power of these sets? {}", result); 28 | } 29 | 30 | long sumOfPowerOfSets(List inputs) { 31 | return inputs.stream() 32 | .map(this::parseGame) 33 | .mapToLong(g -> g.cubes.red * g.cubes.green * g.cubes.blue) 34 | .sum(); 35 | } 36 | 37 | record Game(int id, Cubes cubes) {} 38 | 39 | record Cubes(int red, int green, int blue) {} 40 | 41 | Game parseGame(String input) { 42 | var part1 = input.split(": "); 43 | var id = Integer.parseInt(part1[0].replace("Game ", "")); 44 | int maxRed = 0, maxGreen = 0, maxBlue = 0; 45 | 46 | for (String inputs : part1[1].split(";")) { 47 | for (String cubes : inputs.split(",")) { 48 | var cubeArray = cubes.trim().split(" "); 49 | var cube = Integer.parseInt(cubeArray[0].trim()); 50 | switch (cubeArray[1]) { 51 | case "red": 52 | maxRed = Math.max(maxRed, cube); 53 | break; 54 | case "green": 55 | maxGreen = Math.max(maxGreen, cube); 56 | break; 57 | case "blue": 58 | maxBlue = Math.max(maxBlue, cube); 59 | break; 60 | } 61 | } 62 | } 63 | return new Game(id, new Cubes(maxRed, maxGreen, maxBlue)); 64 | } 65 | 66 | @Test 67 | public void unitTest() throws IOException { 68 | var lines = Resources.readLines(ClassLoader.getSystemResource("2023/day2_test.txt"), Charsets.UTF_8); 69 | assertEquals(2286, sumOfPowerOfSets(lines)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2023/Day4Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2023; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.apache.commons.lang3.StringUtils; 6 | import org.junit.Test; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import java.io.IOException; 11 | import java.util.Arrays; 12 | import java.util.List; 13 | import java.util.Set; 14 | import java.util.stream.Collectors; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | public class Day4Part1 { 19 | Logger log = LoggerFactory.getLogger(Day4Part1.class); 20 | final static String inputFile = "2023/day4.txt"; 21 | 22 | public static void main(String... args) throws IOException { 23 | Day4Part1 solution = new Day4Part1(); 24 | solution.run(); 25 | } 26 | 27 | void run() throws IOException { 28 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 29 | var result = sumOfPoints(lines); 30 | log.warn("How many points are they worth in total? {}", result); 31 | } 32 | 33 | int sumOfPoints(List inputs) { 34 | return inputs.stream().map(this::parseCard) 35 | .mapToInt(this::calculatePoints) 36 | .sum(); 37 | } 38 | 39 | int calculatePoints(Card card) { 40 | int point = 0; 41 | for (var number : card.owningNumbers) { 42 | if (card.winningNumbers.contains(number)) { 43 | point = point == 0 ? 1 : point * 2; 44 | } 45 | } 46 | return point; 47 | } 48 | 49 | Card parseCard(String input) { 50 | var parts = input.split("\\|"); 51 | var winningNumbers = Arrays.stream(parts[0].split(": ")[1].split(" ")) 52 | .map(String::trim) 53 | .filter(StringUtils::isNotBlank) 54 | .map(Integer::parseInt) 55 | .collect(Collectors.toSet()); 56 | var owningNumbers = Arrays.stream(parts[1].split(" ")) 57 | .map(String::trim) 58 | .filter(StringUtils::isNotBlank) 59 | .map(Integer::parseInt) 60 | .toList(); 61 | return new Card(winningNumbers, owningNumbers); 62 | } 63 | 64 | record Card(Set winningNumbers, List owningNumbers) {} 65 | 66 | 67 | @Test 68 | public void unitTest() throws IOException { 69 | var lines = Resources.readLines(ClassLoader.getSystemResource("2023/day4_test.txt"), Charsets.UTF_8); 70 | assertEquals(13, sumOfPoints(lines)); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2023/Day6Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2023; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.junit.Test; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import java.io.IOException; 10 | import java.util.List; 11 | import java.util.stream.LongStream; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | 15 | public class Day6Part2 { 16 | Logger log = LoggerFactory.getLogger(Day6Part2.class); 17 | final static String inputFile = "2023/day6.txt"; 18 | 19 | public static void main(String... args) throws IOException { 20 | Day6Part2 solution = new Day6Part2(); 21 | solution.run(); 22 | } 23 | 24 | void run() throws IOException { 25 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 26 | var races = parseRace(lines); 27 | var result = waysCouldWin(races); 28 | log.warn("How many ways can you beat the record in this one much longer race? {}", result); 29 | } 30 | 31 | long waysCouldWin(Race race) { 32 | var minHoldSecond = LongStream.range(1, race.time) 33 | .filter(i -> couldWin(race, i)) 34 | .findFirst().getAsLong(); 35 | 36 | for (long i = race.time; i > 0; i--) { 37 | if (couldWin(race, i)) { 38 | return i - minHoldSecond + 1; 39 | } 40 | } 41 | throw new RuntimeException(); 42 | } 43 | 44 | boolean couldWin(Race race, long holdButtonTime) { 45 | return distanceMoved(holdButtonTime, race.time) > race.bestDistance; 46 | } 47 | 48 | long distanceMoved(long holdButtonTime, long raceTime) { 49 | if (holdButtonTime == 0) return 0; 50 | 51 | var travelTime = raceTime - holdButtonTime; 52 | if (travelTime == 0 ) return 0; 53 | 54 | return travelTime * holdButtonTime; 55 | } 56 | 57 | Race parseRace(List inputs) { 58 | var time = inputs.get(0).split(": ")[1].trim().replaceAll("\\s+", ""); 59 | var distance = inputs.get(1).split(": ")[1].trim().replaceAll("\\s+", ""); 60 | return new Race(Long.parseLong(time), Long.parseLong(distance)); 61 | } 62 | 63 | record Race(long time, long bestDistance) {} 64 | 65 | @Test 66 | public void unitTest() throws IOException { 67 | var lines = Resources.readLines(ClassLoader.getSystemResource("2023/day6_test.txt"), Charsets.UTF_8); 68 | var races = parseRace(lines); 69 | assertEquals(71503, waysCouldWin(races)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2023/Day9Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2023; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.junit.Test; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import java.io.IOException; 10 | import java.util.ArrayList; 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | 16 | public class Day9Part1 { 17 | Logger log = LoggerFactory.getLogger(Day9Part1.class); 18 | final static String inputFile = "2023/day9.txt"; 19 | 20 | public static void main(String... args) throws IOException { 21 | Day9Part1 solution = new Day9Part1(); 22 | solution.run(); 23 | } 24 | void run() throws IOException { 25 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 26 | var puzzle = Puzzle.parse(lines); 27 | var result = puzzle.sumOfExtrapolatedValues(); 28 | log.warn("What is the sum of these extrapolated values? {}", result); 29 | } 30 | 31 | record Puzzle(List> histories) { 32 | static Puzzle parse(List inputs) { 33 | var histories = inputs.stream().map(s -> 34 | Arrays.stream(s.split(" ")).map(Integer::parseInt).toList()) 35 | .toList(); 36 | return new Puzzle(histories); 37 | } 38 | int sumOfExtrapolatedValues() { 39 | return histories.stream().mapToInt(this::predictionValue).sum(); 40 | } 41 | 42 | int predictionValue(List history) { 43 | if (history.stream().allMatch(v -> v == 0)) 44 | return 0; 45 | 46 | var differences = new ArrayList(); 47 | for (int i = 1; i < history.size(); i++) { 48 | differences.add(history.get(i) - history.get(i - 1)); 49 | } 50 | return predictionValue(differences) + history.getLast(); 51 | } 52 | } 53 | 54 | @Test 55 | public void unitTest() throws IOException { 56 | var lines = Resources.readLines(ClassLoader.getSystemResource("2023/day9_test.txt"), Charsets.UTF_8); 57 | var puzzle = Puzzle.parse(lines); 58 | assertEquals(114, puzzle.sumOfExtrapolatedValues()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2023/Day9Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2023; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.junit.Test; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import java.io.IOException; 10 | import java.util.ArrayList; 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | 16 | public class Day9Part2 { 17 | Logger log = LoggerFactory.getLogger(Day9Part2.class); 18 | final static String inputFile = "2023/day9.txt"; 19 | 20 | public static void main(String... args) throws IOException { 21 | Day9Part2 solution = new Day9Part2(); 22 | solution.run(); 23 | } 24 | void run() throws IOException { 25 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 26 | var puzzle = Puzzle.parse(lines); 27 | var result = puzzle.sumOfExtrapolatedValues(); 28 | System.out.println("What is the sum of these extrapolated values? " + result); 29 | log.warn("What is the sum of these extrapolated values? {}", result); 30 | } 31 | 32 | record Puzzle(List> histories) { 33 | static Puzzle parse(List inputs) { 34 | var histories = inputs.stream().map(s -> 35 | Arrays.stream(s.split(" ")).map(Integer::parseInt).toList()) 36 | .toList(); 37 | return new Puzzle(histories); 38 | } 39 | int sumOfExtrapolatedValues() { 40 | return histories.stream().mapToInt(this::predictionValue).sum(); 41 | } 42 | 43 | int predictionValue(List history) { 44 | if (history.stream().allMatch(v -> v == 0)) 45 | return 0; 46 | 47 | var differences = new ArrayList(); 48 | for (int i = 1; i < history.size(); i++) { 49 | differences.add(history.get(i) - history.get(i - 1)); 50 | } 51 | return history.getFirst() - predictionValue(differences); 52 | } 53 | } 54 | 55 | @Test 56 | public void unitTest() throws IOException { 57 | var lines = Resources.readLines(ClassLoader.getSystemResource("2023/day9_test.txt"), Charsets.UTF_8); 58 | var puzzle = Puzzle.parse(lines); 59 | assertEquals(2, puzzle.sumOfExtrapolatedValues()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2024/Day1Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2024; 2 | 3 | import com.adventofcode.year2023.Day14Part1; 4 | import com.adventofcode.year2023.Day21Part1; 5 | import com.google.common.base.Charsets; 6 | import com.google.common.io.Resources; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import java.io.IOException; 11 | import java.nio.file.Files; 12 | import java.nio.file.Paths; 13 | import java.util.ArrayList; 14 | import java.util.Collections; 15 | import java.util.List; 16 | 17 | public class Day1Part1 { 18 | Logger log = LoggerFactory.getLogger(this.getClass()); 19 | final static String inputFile = "2024/day1.txt"; 20 | 21 | public static void main(String... args) throws IOException { 22 | new Day1Part1().run(); 23 | } 24 | 25 | List leftList = new ArrayList<>(); 26 | List rightList = new ArrayList<>(); 27 | 28 | void run() throws IOException { 29 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 30 | parseInput(lines); 31 | var result = calculateTotalDistance(leftList, rightList); 32 | log.warn("What is the total distance between your lists? {}", result); 33 | } 34 | 35 | private void parseInput(List lines) { 36 | for (String line : lines) { 37 | String[] parts = line.trim().split("\\s+"); 38 | leftList.add(Integer.parseInt(parts[0])); 39 | rightList.add(Integer.parseInt(parts[1])); 40 | } 41 | } 42 | 43 | public static int calculateTotalDistance(List leftList, List rightList) { 44 | Collections.sort(leftList); 45 | Collections.sort(rightList); 46 | int totalDistance = 0; 47 | for (int i = 0; i < leftList.size(); i++) { 48 | totalDistance += Math.abs(leftList.get(i) - rightList.get(i)); 49 | } 50 | 51 | return totalDistance; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2024/Day1Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2024; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.IOException; 9 | import java.util.*; 10 | 11 | public class Day1Part2 { 12 | Logger log = LoggerFactory.getLogger(this.getClass()); 13 | final static String inputFile = "2024/day1.txt"; 14 | 15 | public static void main(String... args) throws IOException { 16 | new Day1Part2().run(); 17 | } 18 | 19 | List leftList = new ArrayList<>(); 20 | List rightList = new ArrayList<>(); 21 | 22 | void run() throws IOException { 23 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 24 | parseInput(lines); 25 | var result = calculateSimilarityScore(leftList, rightList);; 26 | log.warn("What is their similarity score? {}", result); 27 | } 28 | 29 | private void parseInput(List lines) { 30 | for (String line : lines) { 31 | String[] parts = line.trim().split("\\s+"); 32 | leftList.add(Integer.parseInt(parts[0])); 33 | rightList.add(Integer.parseInt(parts[1])); 34 | } 35 | } 36 | 37 | public static int calculateSimilarityScore(List leftList, List rightList) { 38 | Map rightCountMap = new HashMap<>(); 39 | for (Integer number : rightList) { 40 | rightCountMap.put(number, rightCountMap.getOrDefault(number, 0) + 1); 41 | } 42 | 43 | int similarityScore = 0; 44 | for (Integer number : leftList) { 45 | int countInRight = rightCountMap.getOrDefault(number, 0); 46 | similarityScore += number * countInRight; 47 | } 48 | 49 | return similarityScore; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2024/Day3Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2024; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.IOException; 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | import java.util.regex.Matcher; 13 | import java.util.regex.Pattern; 14 | import java.util.stream.Collectors; 15 | 16 | public class Day3Part1 { 17 | Logger log = LoggerFactory.getLogger(this.getClass()); 18 | final static String inputFile = "2024/day3.txt"; 19 | 20 | public static void main(String... args) throws IOException { 21 | new Day3Part1().run(); 22 | } 23 | 24 | void run() throws IOException { 25 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 26 | var input = parseInput(lines); 27 | var result = calculateTotalMultiplications(input); 28 | log.warn("What do you get if you add up all of the results of the multiplications? {}", result); 29 | } 30 | 31 | private String parseInput(List lines) { 32 | return lines.getFirst(); 33 | } 34 | 35 | private int calculateTotalMultiplications(String memory) { 36 | int total = 0; 37 | Pattern pattern = Pattern.compile("mul\\s*\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*\\)"); 38 | Matcher matcher = pattern.matcher(memory); 39 | 40 | while (matcher.find()) { 41 | int x = Integer.parseInt(matcher.group(1)); 42 | int y = Integer.parseInt(matcher.group(2)); 43 | total += x * y; 44 | } 45 | 46 | return total; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2024/Day3Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2024; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | import java.util.regex.Matcher; 11 | import java.util.regex.Pattern; 12 | 13 | public class Day3Part2 { 14 | Logger log = LoggerFactory.getLogger(this.getClass()); 15 | final static String inputFile = "2024/day3.txt"; 16 | 17 | public static void main(String... args) throws IOException { 18 | new Day3Part2().run(); 19 | } 20 | 21 | void run() throws IOException { 22 | var lines = Resources.readLines(ClassLoader.getSystemResource(inputFile), Charsets.UTF_8); 23 | var input = parseInput(lines); 24 | var result = calculateTotalMultiplications(input); 25 | log.warn("what do you get if you add up all of the results of just the enabled multiplications? {}", result); 26 | } 27 | 28 | private String parseInput(List lines) {return lines.getFirst();} 29 | 30 | private int calculateTotalMultiplications(String memory) { 31 | int total = 0; 32 | boolean enabled = true; // Multiplications are enabled by default 33 | 34 | // Regex patterns for mul, do and don't instructions 35 | Pattern mulPattern = Pattern.compile("mul\\s*\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*\\)"); 36 | Pattern doPattern = Pattern.compile("do\\s*\\(\\s*\\)"); 37 | Pattern dontPattern = Pattern.compile("don't\\s*\\(\\s*\\)"); 38 | 39 | Matcher matcher = Pattern.compile(mulPattern.pattern() + "|" + doPattern.pattern() + "|" + dontPattern.pattern()).matcher(memory); 40 | 41 | while (matcher.find()) { 42 | if (matcher.group(1) != null) { // If it's a mul instruction 43 | if (enabled) { 44 | int x = Integer.parseInt(matcher.group(1)); 45 | int y = Integer.parseInt(matcher.group(2)); 46 | total += x * y; 47 | } 48 | } else if (matcher.group(0).startsWith("don't")) { // If it's a do() instruction 49 | enabled = false; 50 | } else if (matcher.group(0).startsWith("do")) { // If it's a don't() instruction 51 | enabled = true; 52 | } 53 | } 54 | 55 | return total; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2024/Day7Part1.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2024; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class Day7Part1 { 12 | private static final Logger log = LoggerFactory.getLogger(Day7Part1.class); 13 | private static final String INPUT_FILE = "2024/day7.txt"; 14 | 15 | public static void main(String... args) throws IOException { 16 | new Day7Part1().run(); 17 | } 18 | 19 | private void run() throws IOException { 20 | var lines = Resources.readLines(ClassLoader.getSystemResource(INPUT_FILE), Charsets.UTF_8); 21 | long totalSum = calculateTotalCalibration(lines); 22 | log.warn("Total calibration result: {}", totalSum); 23 | } 24 | 25 | private long calculateTotalCalibration(List lines) { 26 | return lines.stream() 27 | .map(this::parseEquation) 28 | .filter(equation -> evaluateExpressions(equation, 1, equation.numbers[0])) 29 | .mapToLong(Equation::testValue) 30 | .sum(); 31 | } 32 | 33 | private Equation parseEquation(String line) { 34 | var parts = line.split(": "); 35 | long testValue = Long.parseLong(parts[0]); 36 | String[] numbers = parts[1].split(" "); 37 | long[] numberArray = new long[numbers.length]; 38 | 39 | for (int i = 0; i < numbers.length; i++) { 40 | numberArray[i] = Long.parseLong(numbers[i]); 41 | } 42 | 43 | return new Equation(testValue, numberArray); 44 | } 45 | 46 | private boolean evaluateExpressions(Equation equation, int index, long current) { 47 | var numbers = equation.numbers; 48 | if (index == numbers.length) { 49 | return current == equation.testValue; 50 | } 51 | 52 | long nextNumber = numbers[index]; 53 | boolean addResult = evaluateExpressions(equation, index + 1, current + nextNumber); 54 | boolean multiplyResult = evaluateExpressions(equation, index + 1, current * nextNumber); 55 | return addResult || multiplyResult; // Return true if either operation leads to a match 56 | } 57 | 58 | private record Equation(long testValue, long[] numbers) {} 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/adventofcode/year2024/Day7Part2.java: -------------------------------------------------------------------------------- 1 | package com.adventofcode.year2024; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Resources; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | 11 | public class Day7Part2 { 12 | private static final Logger log = LoggerFactory.getLogger(Day7Part2.class); 13 | private static final String INPUT_FILE = "2024/day7.txt"; 14 | 15 | public static void main(String... args) throws IOException { 16 | new Day7Part2().run(); 17 | } 18 | 19 | private void run() throws IOException { 20 | var lines = Resources.readLines(ClassLoader.getSystemResource(INPUT_FILE), Charsets.UTF_8); 21 | long totalSum = calculateTotalCalibration(lines); 22 | log.warn("Total calibration result: {}", totalSum); 23 | } 24 | 25 | private long calculateTotalCalibration(List lines) { 26 | return lines.stream() 27 | .map(this::parseEquation) 28 | .filter(equation -> evaluateExpressions(equation, 1, equation.numbers[0])) 29 | .mapToLong(Equation::testValue) 30 | .sum(); 31 | } 32 | 33 | private Equation parseEquation(String line) { 34 | var parts = line.split(": "); 35 | long testValue = Long.parseLong(parts[0]); 36 | String[] numbers = parts[1].split(" "); 37 | long[] numberArray = new long[numbers.length]; 38 | 39 | for (int i = 0; i < numbers.length; i++) { 40 | numberArray[i] = Long.parseLong(numbers[i]); 41 | } 42 | 43 | return new Equation(testValue, numberArray); 44 | } 45 | 46 | private boolean evaluateExpressions(Equation equation, int index, long current) { 47 | var numbers = equation.numbers; 48 | if (index == numbers.length) { 49 | return current == equation.testValue; 50 | } 51 | 52 | long nextNumber = numbers[index]; 53 | boolean addResult = evaluateExpressions(equation, index + 1, current + nextNumber); 54 | boolean multiplyResult = evaluateExpressions(equation, index + 1, current * nextNumber); 55 | 56 | long concatenatedValue = Long.parseLong(current + "" + nextNumber); 57 | boolean concatResult = evaluateExpressions(equation, index + 1, concatenatedValue); 58 | 59 | return addResult || multiplyResult || concatResult; 60 | } 61 | 62 | private record Equation(long testValue, long[] numbers) {} 63 | } 64 | -------------------------------------------------------------------------------- /src/main/resources/2015/day14_1.txt: -------------------------------------------------------------------------------- 1 | Vixen can fly 8 km/s for 8 seconds, but then must rest for 53 seconds. 2 | Blitzen can fly 13 km/s for 4 seconds, but then must rest for 49 seconds. 3 | Rudolph can fly 20 km/s for 7 seconds, but then must rest for 132 seconds. 4 | Cupid can fly 12 km/s for 4 seconds, but then must rest for 43 seconds. 5 | Donner can fly 9 km/s for 5 seconds, but then must rest for 38 seconds. 6 | Dasher can fly 10 km/s for 4 seconds, but then must rest for 37 seconds. 7 | Comet can fly 3 km/s for 37 seconds, but then must rest for 76 seconds. 8 | Prancer can fly 9 km/s for 12 seconds, but then must rest for 97 seconds. 9 | Dancer can fly 37 km/s for 1 seconds, but then must rest for 36 seconds. -------------------------------------------------------------------------------- /src/main/resources/2015/day15_1.txt: -------------------------------------------------------------------------------- 1 | Frosting: capacity 4, durability -2, flavor 0, texture 0, calories 5 2 | Candy: capacity 0, durability 5, flavor -1, texture 0, calories 8 3 | Butterscotch: capacity -1, durability 0, flavor 5, texture 0, calories 6 4 | Sugar: capacity 0, durability 0, flavor -2, texture 2, calories 1 -------------------------------------------------------------------------------- /src/main/resources/2015/day17_1.txt: -------------------------------------------------------------------------------- 1 | 43 2 | 3 3 | 4 4 | 10 5 | 21 6 | 44 7 | 4 8 | 6 9 | 47 10 | 41 11 | 34 12 | 17 13 | 17 14 | 44 15 | 36 16 | 31 17 | 46 18 | 9 19 | 27 20 | 38 -------------------------------------------------------------------------------- /src/main/resources/2015/day18_test.txt: -------------------------------------------------------------------------------- 1 | .#.#.# 2 | ...##. 3 | #....# 4 | ..#... 5 | #.#..# 6 | ####.. -------------------------------------------------------------------------------- /src/main/resources/2015/day19_1.txt: -------------------------------------------------------------------------------- 1 | Al => ThF 2 | Al => ThRnFAr 3 | B => BCa 4 | B => TiB 5 | B => TiRnFAr 6 | Ca => CaCa 7 | Ca => PB 8 | Ca => PRnFAr 9 | Ca => SiRnFYFAr 10 | Ca => SiRnMgAr 11 | Ca => SiTh 12 | F => CaF 13 | F => PMg 14 | F => SiAl 15 | H => CRnAlAr 16 | H => CRnFYFYFAr 17 | H => CRnFYMgAr 18 | H => CRnMgYFAr 19 | H => HCa 20 | H => NRnFYFAr 21 | H => NRnMgAr 22 | H => NTh 23 | H => OB 24 | H => ORnFAr 25 | Mg => BF 26 | Mg => TiMg 27 | N => CRnFAr 28 | N => HSi 29 | O => CRnFYFAr 30 | O => CRnMgAr 31 | O => HP 32 | O => NRnFAr 33 | O => OTi 34 | P => CaP 35 | P => PTi 36 | P => SiRnFAr 37 | Si => CaSi 38 | Th => ThCa 39 | Ti => BP 40 | Ti => TiTi 41 | e => HF 42 | e => NAl 43 | e => OMg 44 | 45 | ORnPBPMgArCaCaCaSiThCaCaSiThCaCaPBSiRnFArRnFArCaCaSiThCaCaSiThCaCaCaCaCaCaSiRnFYFArSiRnMgArCaSiRnPTiTiBFYPBFArSiRnCaSiRnTiRnFArSiAlArPTiBPTiRnCaSiAlArCaPTiTiBPMgYFArPTiRnFArSiRnCaCaFArRnCaFArCaSiRnSiRnMgArFYCaSiRnMgArCaCaSiThPRnFArPBCaSiRnMgArCaCaSiThCaSiRnTiMgArFArSiThSiThCaCaSiRnMgArCaCaSiRnFArTiBPTiRnCaSiAlArCaPTiRnFArPBPBCaCaSiThCaPBSiThPRnFArSiThCaSiThCaSiThCaPTiBSiRnFYFArCaCaPRnFArPBCaCaPBSiRnTiRnFArCaPRnFArSiRnCaCaCaSiThCaRnCaFArYCaSiRnFArBCaCaCaSiThFArPBFArCaSiRnFArRnCaCaCaFArSiRnFArTiRnPMgArF -------------------------------------------------------------------------------- /src/main/resources/2015/day23_1.txt: -------------------------------------------------------------------------------- 1 | jio a, +16 2 | inc a 3 | inc a 4 | tpl a 5 | tpl a 6 | tpl a 7 | inc a 8 | inc a 9 | tpl a 10 | inc a 11 | inc a 12 | tpl a 13 | tpl a 14 | tpl a 15 | inc a 16 | jmp +23 17 | tpl a 18 | inc a 19 | inc a 20 | tpl a 21 | inc a 22 | inc a 23 | tpl a 24 | tpl a 25 | inc a 26 | inc a 27 | tpl a 28 | inc a 29 | tpl a 30 | inc a 31 | tpl a 32 | inc a 33 | inc a 34 | tpl a 35 | inc a 36 | tpl a 37 | tpl a 38 | inc a 39 | jio a, +8 40 | inc b 41 | jie a, +4 42 | tpl a 43 | inc a 44 | jmp +2 45 | hlf a 46 | jmp -7 -------------------------------------------------------------------------------- /src/main/resources/2015/day23_test.txt: -------------------------------------------------------------------------------- 1 | inc a 2 | jio a, +2 3 | tpl a 4 | inc a -------------------------------------------------------------------------------- /src/main/resources/2015/day24_1.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 3 3 | 5 4 | 11 5 | 13 6 | 17 7 | 19 8 | 23 9 | 29 10 | 31 11 | 41 12 | 43 13 | 47 14 | 53 15 | 59 16 | 61 17 | 67 18 | 71 19 | 73 20 | 79 21 | 83 22 | 89 23 | 97 24 | 101 25 | 103 26 | 107 27 | 109 28 | 113 -------------------------------------------------------------------------------- /src/main/resources/2015/day8_test.txt: -------------------------------------------------------------------------------- 1 | "" 2 | "abc" 3 | "aaa\"aaa" 4 | "\x27" -------------------------------------------------------------------------------- /src/main/resources/2015/day9_1.txt: -------------------------------------------------------------------------------- 1 | Tristram to AlphaCentauri = 34 2 | Tristram to Snowdin = 100 3 | Tristram to Tambi = 63 4 | Tristram to Faerun = 108 5 | Tristram to Norrath = 111 6 | Tristram to Straylight = 89 7 | Tristram to Arbre = 132 8 | AlphaCentauri to Snowdin = 4 9 | AlphaCentauri to Tambi = 79 10 | AlphaCentauri to Faerun = 44 11 | AlphaCentauri to Norrath = 147 12 | AlphaCentauri to Straylight = 133 13 | AlphaCentauri to Arbre = 74 14 | Snowdin to Tambi = 105 15 | Snowdin to Faerun = 95 16 | Snowdin to Norrath = 48 17 | Snowdin to Straylight = 88 18 | Snowdin to Arbre = 7 19 | Tambi to Faerun = 68 20 | Tambi to Norrath = 134 21 | Tambi to Straylight = 107 22 | Tambi to Arbre = 40 23 | Faerun to Norrath = 11 24 | Faerun to Straylight = 66 25 | Faerun to Arbre = 144 26 | Norrath to Straylight = 115 27 | Norrath to Arbre = 135 28 | Straylight to Arbre = 127 -------------------------------------------------------------------------------- /src/main/resources/2016/day12_1.txt: -------------------------------------------------------------------------------- 1 | cpy 1 a 2 | cpy 1 b 3 | cpy 26 d 4 | jnz c 2 5 | jnz 1 5 6 | cpy 7 c 7 | inc d 8 | dec c 9 | jnz c -2 10 | cpy a c 11 | inc a 12 | dec b 13 | jnz b -2 14 | cpy c b 15 | dec d 16 | jnz d -6 17 | cpy 16 c 18 | cpy 12 d 19 | inc a 20 | dec d 21 | jnz d -2 22 | dec c 23 | jnz c -5 -------------------------------------------------------------------------------- /src/main/resources/2016/day23_1.txt: -------------------------------------------------------------------------------- 1 | cpy a b 2 | dec b 3 | cpy a d 4 | cpy 0 a 5 | cpy b c 6 | inc a 7 | dec c 8 | jnz c -2 9 | dec d 10 | jnz d -5 11 | dec b 12 | cpy b c 13 | cpy c d 14 | dec d 15 | inc c 16 | jnz d -2 17 | tgl c 18 | cpy -16 c 19 | jnz 1 c 20 | cpy 93 c 21 | jnz 80 d 22 | inc a 23 | inc d 24 | jnz d -2 25 | inc c 26 | jnz c -5 -------------------------------------------------------------------------------- /src/main/resources/2016/day25_1.txt: -------------------------------------------------------------------------------- 1 | cpy a d 2 | cpy 7 c 3 | cpy 365 b 4 | inc d 5 | dec b 6 | jnz b -2 7 | dec c 8 | jnz c -5 9 | cpy d a 10 | jnz 0 0 11 | cpy a b 12 | cpy 0 a 13 | cpy 2 c 14 | jnz b 2 15 | jnz 1 6 16 | dec b 17 | dec c 18 | jnz c -4 19 | inc a 20 | jnz 1 -7 21 | cpy 2 b 22 | jnz c 2 23 | jnz 1 4 24 | dec b 25 | dec c 26 | jnz 1 -4 27 | jnz 0 0 28 | out b 29 | jnz a -19 30 | jnz 1 -21 31 | -------------------------------------------------------------------------------- /src/main/resources/2016/day2_1.txt: -------------------------------------------------------------------------------- 1 | LRULLRLDUUUDUDDDRLUDRDLDDLUUDLDDLRDRLDRLLURRULURLDRLDUDURLURRULLDDDUDDRRRDLRRDDLDURDULLRDLLLDRDLLDULDUDLLDLDRUDLLDLDDRRRDRLUDRDDLUDRRDUDUDLLDDUUDLRDUDRRUDUDRULRULUDRUUDLDLULLRLDLDDRULLRLLLULUULDURURLUUULDURLDDDURRUUDURDDDULDLURLRDRURDRUDRLLDLDRUURLLLRDRURUDLRLUDULLDDURLRURDLRDUUURRLULRRLDDULUUURLRRRLLLLLURDDRUULUDRRRUDDLLULRRUULDRDDULRLDDDRRUULUDRLRUDURUUULDLDULUUDURLLLRRDDRDLURDDDLDDDLRDRLDDURLRLLRUDRRLLDDDDDURDURRDDULDULLRULDRUURDRRDUDDUDDDDRRDULDUURDRUDRLDULRULURLLRRDRDRDLUUDRRLRLDULDDLUUUUUURRLRRRULLDDDRLRDRRRRRRRDUUDLLUDURUDDLURRUDL 2 | UDUUURRLRLLDDRRDRRRLDDDLURURLLUDDRLUUDRRRDURRLLRURDLLRRDUUDDDDRDRURRLLLLURDLRRRULLLDLLLUDDLDRRRDLDUUDDRDUDDUURDDLULULDURDURDRUULURURRURDUURUDRRUDRLLLLRRDLLDRDDRLLURDDDUDUDUDRUURDDRUURDLRUUDDRDUURUDDLLUURDLUDRUUDRRDLLUUURDULUULDUUDLLULUUDLUDRUUDUUURLDDDRLRURDDULLRDRULULUDLUUDDDUUDLDUUDRULLDUURDDRUDURULDRDDLRUULRRRDLDLRDULRDDRLLRRLURDLDRUDLRLUDLRLDLDURRUULRLUURDULDRRULLRULRDLLDLDUDRUDDUDLDDURDDDRDLUDRULRUULLRURLDDDRDLRRDRULURULDULRDLDULDURDRDRDRDURDRLUURLRDDLDDRLDDRURLLLURURDULDUDDLLUURDUUUDRUDDRDLDRLRLDURRULDULUUDDLRULDLRRRRDLLDRUUDRLLDLUDUULRDRDLRUUDLRRDDLUULDUULRUDRURLDDDURLRRULURR 3 | LDURLLLRLLLUURLLULDLRLLDLURULRULRDUDLDDUDRLRRDLULLDDULUUULDRLDURURLURLDLRUDULLLULDUURLLRDLUULRULLLULRDRULUDLUUULDDURLUDDUDDRDLDRDRUDLUURDDLULDUULURLUULRDRDLURUDRUDLDRLUUUUULUDUDRRURUDRULDLDRDRLRURUUDRDLULLUDLLRUUDUUDUDLLRRRLDUDDDRDUDLDLLULRDURULLLUDLLRUDDUUDRLDUULLDLUUDUULURURLLULDUULLDLUDUURLURDLUULRRLLRUDRDLLLRRRLDDLUULUURLLDRDLUUULLDUDLLLLURDULLRUDUUULLDLRLDRLLULDUDUDRULLRRLULURUURLRLURRLRRRDDRLUDULURUDRRDLUDDRRDRUDRUDLDDRLRDRRLDDRLLDDDULDLRLDURRRRRULRULLUUULUUUDRRDRDRLLURRRRUULUDDUDDDLDURDRLDLLLLLRDUDLRDRUULU 4 | URURRUUULLLLUURDULULLDLLULRUURRDRRLUULRDDRUDRRDUURDUDRUDDRUULURULDRLDRDDDLDLRLUDDRURULRLRLLLDLRRUDLLLLRLULDLUUDUUDRDLRRULLRDRLRLUUDDRRLLDDRULLLRLLURDLRRRRRLLDDRRDLDULDULLDLULLURURRLULRLRLLLLURDDRDDDUUDRRRDUUDDLRDLDRRLLRURUDUUUDLDUULLLRLURULRULRDRLLLDLDLRDRDLLLRUURDDUDDLULRULDLRULUURLLLRRLLLLLLRUURRLULRUUUDLDUDLLRRDDRUUUURRRDRRDULRDUUDULRRRDUUUUURRDUURRRRLDUDDRURULDDURDDRDLLLRDDURUDLLRURLRRRUDDLULULDUULURLUULRDLRDUDDRUULLLRURLDLRRLUDLULDRLUDDDRURUULLDLRLLLDULUDDRLRULURLRDRRDDLDLURUDDUUURRDDLUDDRDUULRRDLDRLLLULLRULRURULRLULULRDUD 5 | RUDLLUDRRDRRLRURRULRLRDUDLRRLRDDUDRDLRRLLRURRDDLRLLRRURULRUULDUDUULDULDLRLRDLRDLRUURLDRLUDRRDDDRDRRRDDLLLRRLULLRRDDUDULRDRDUURLDLRULULUDLLDRUDUURRUDLLRDRLRRUUUDLDUDRRULLDURRDUDDLRURDLDRLULDDURRLULLRDDDRLURLULDLRUDLURDURRUDULDUUDLLLDDDUUURRRDLLDURRDLULRULULLRDURULLURDRLLRUUDDRRUDRDRRRURUUDLDDRLDRURULDDLLULULURDLDLDULLRLRDLLUUDDUDUDDDDRURLUDUDDDRRUDDLUDULLRDLDLURDDUURDLRLUUDRRULLRDLDDDLDULDUDRDUUULULDULUDLULRLRUULLDURLDULDRDLLDULLLULRLRD -------------------------------------------------------------------------------- /src/main/resources/2017/day13_1.txt: -------------------------------------------------------------------------------- 1 | 0: 4 2 | 1: 2 3 | 2: 3 4 | 4: 5 5 | 6: 8 6 | 8: 6 7 | 10: 4 8 | 12: 6 9 | 14: 6 10 | 16: 8 11 | 18: 8 12 | 20: 6 13 | 22: 8 14 | 24: 8 15 | 26: 8 16 | 28: 12 17 | 30: 12 18 | 32: 9 19 | 34: 14 20 | 36: 12 21 | 38: 12 22 | 40: 12 23 | 42: 12 24 | 44: 10 25 | 46: 12 26 | 48: 12 27 | 50: 10 28 | 52: 14 29 | 56: 12 30 | 58: 14 31 | 62: 14 32 | 64: 14 33 | 66: 12 34 | 68: 14 35 | 70: 14 36 | 72: 17 37 | 74: 14 38 | 76: 14 39 | 80: 20 40 | 82: 14 41 | 90: 24 42 | 92: 14 43 | 98: 14 44 | -------------------------------------------------------------------------------- /src/main/resources/2017/day13_test.txt: -------------------------------------------------------------------------------- 1 | 0: 3 2 | 1: 2 3 | 4: 4 4 | 6: 4 5 | -------------------------------------------------------------------------------- /src/main/resources/2017/day18_1.txt: -------------------------------------------------------------------------------- 1 | set i 31 2 | set a 1 3 | mul p 17 4 | jgz p p 5 | mul a 2 6 | add i -1 7 | jgz i -2 8 | add a -1 9 | set i 127 10 | set p 618 11 | mul p 8505 12 | mod p a 13 | mul p 129749 14 | add p 12345 15 | mod p a 16 | set b p 17 | mod b 10000 18 | snd b 19 | add i -1 20 | jgz i -9 21 | jgz a 3 22 | rcv b 23 | jgz b -1 24 | set f 0 25 | set i 126 26 | rcv a 27 | rcv b 28 | set p a 29 | mul p -1 30 | add p b 31 | jgz p 4 32 | snd a 33 | set a b 34 | jgz 1 3 35 | snd b 36 | set f 1 37 | add i -1 38 | jgz i -11 39 | snd a 40 | jgz f -16 41 | jgz a -19 -------------------------------------------------------------------------------- /src/main/resources/2017/day18_test.txt: -------------------------------------------------------------------------------- 1 | set a 1 2 | add a 2 3 | mul a a 4 | mod a 5 5 | snd a 6 | set a 0 7 | rcv a 8 | jgz a -1 9 | set a 1 10 | jgz a -2 -------------------------------------------------------------------------------- /src/main/resources/2017/day18_test2.txt: -------------------------------------------------------------------------------- 1 | snd 1 2 | snd 2 3 | snd p 4 | rcv a 5 | rcv b 6 | rcv c 7 | rcv d -------------------------------------------------------------------------------- /src/main/resources/2017/day19_test.txt: -------------------------------------------------------------------------------- 1 | | 2 | | +--+ 3 | A | C 4 | F---|----E|--+ 5 | | | | D 6 | +B-+ +--+ 7 | 8 | -------------------------------------------------------------------------------- /src/main/resources/2017/day1_1.txt: -------------------------------------------------------------------------------- 1 | 3294199471327195994824832197564859876682638188889768298894243832665654681412886862234525991553276578641265589959178414218389329361496673991614673626344552179413995562266818138372393213966143124914469397692587251112663217862879233226763533911128893354536353213847122251463857894159819828724827969576432191847787772732881266875469721189331882228146576832921314638221317393256471998598117289632684663355273845983933845721713497811766995367795857965222183668765517454263354111134841334631345111596131682726196574763165187889337599583345634413436165539744188866156771585647718555182529936669683581662398618765391487164715724849894563314426959348119286955144439452731762666568741612153254469131724137699832984728937865956711925592628456617133695259554548719328229938621332325125972547181236812263887375866231118312954369432937359357266467383318326239572877314765121844831126178173988799765218913178825966268816476559792947359956859989228917136267178571776316345292573489873792149646548747995389669692188457724414468727192819919448275922166321158141365237545222633688372891451842434458527698774342111482498999383831492577615154591278719656798277377363284379468757998373193231795767644654155432692988651312845433511879457921638934877557575241394363721667237778962455961493559848522582413748218971212486373232795878362964873855994697149692824917183375545192119453587398199912564474614219929345185468661129966379693813498542474732198176496694746111576925715493967296487258237854152382365579876894391815759815373319159213475555251488754279888245492373595471189191353244684697662848376529881512529221627313527441221459672786923145165989611223372241149929436247374818467481641931872972582295425936998535194423916544367799522276914445231582272368388831834437562752119325286474352863554693373718848649568451797751926315617575295381964426843625282819524747119726872193569785611959896776143539915299968276374712996485367853494734376257511273443736433464496287219615697341973131715166768916149828396454638596713572963686159214116763 2 | -------------------------------------------------------------------------------- /src/main/resources/2017/day21_test.txt: -------------------------------------------------------------------------------- 1 | ../.# => ##./#../... 2 | .#./..#/### => #..#/..../..../#..# -------------------------------------------------------------------------------- /src/main/resources/2017/day22_1.txt: -------------------------------------------------------------------------------- 1 | .#.....##..##..###.###..# 2 | ..##..######.#.###.##.#.# 3 | ###..#..#####.##.##.#...# 4 | ###......##..###.#...#.#. 5 | .#.###.##..#.####.#..#... 6 | ..#.#.#####...##.####.### 7 | ..#..#.#..###.#..###.###. 8 | #########...#....##..#.#. 9 | .###..#######..####...### 10 | #####...#..##...###..##.. 11 | ..#......##.#....#...#### 12 | .##.#..#####.#####.##.##. 13 | ####.##.###.#..#.#.#..... 14 | #....##.####.#.#..#.#.##. 15 | ###...##...#.###.#.#.#### 16 | .#.#...#.#.##.##....##.#. 17 | #..##.#.#..#....###..#### 18 | #####...#..#.###...##.### 19 | ##.#..####.###...#....### 20 | ###.#####.....#....#.##.. 21 | ####.##.....######.#..#.# 22 | .#.....####.##...###..##. 23 | ....########.#..###.#..## 24 | ##.##..#...#...##.#....## 25 | .#.######.##....####.#.## -------------------------------------------------------------------------------- /src/main/resources/2017/day22_test.txt: -------------------------------------------------------------------------------- 1 | ..# 2 | #.. 3 | ... -------------------------------------------------------------------------------- /src/main/resources/2017/day23_1.txt: -------------------------------------------------------------------------------- 1 | set b 65 2 | set c b 3 | jnz a 2 4 | jnz 1 5 5 | mul b 100 6 | sub b -100000 7 | set c b 8 | sub c -17000 9 | set f 1 10 | set d 2 11 | set e 2 12 | set g d 13 | mul g e 14 | sub g b 15 | jnz g 2 16 | set f 0 17 | sub e -1 18 | set g e 19 | sub g b 20 | jnz g -8 21 | sub d -1 22 | set g d 23 | sub g b 24 | jnz g -13 25 | jnz f 2 26 | sub h -1 27 | set g b 28 | sub g c 29 | jnz g 2 30 | jnz 1 3 31 | sub b -17 32 | jnz 1 -23 -------------------------------------------------------------------------------- /src/main/resources/2017/day24_1.txt: -------------------------------------------------------------------------------- 1 | 25/13 2 | 4/43 3 | 42/42 4 | 39/40 5 | 17/18 6 | 30/7 7 | 12/12 8 | 32/28 9 | 9/28 10 | 1/1 11 | 16/7 12 | 47/43 13 | 34/16 14 | 39/36 15 | 6/4 16 | 3/2 17 | 10/49 18 | 46/50 19 | 18/25 20 | 2/23 21 | 3/21 22 | 5/24 23 | 46/26 24 | 50/19 25 | 26/41 26 | 1/50 27 | 47/41 28 | 39/50 29 | 12/14 30 | 11/19 31 | 28/2 32 | 38/47 33 | 5/5 34 | 38/34 35 | 39/39 36 | 17/34 37 | 42/16 38 | 32/23 39 | 13/21 40 | 28/6 41 | 6/20 42 | 1/30 43 | 44/21 44 | 11/28 45 | 14/17 46 | 33/33 47 | 17/43 48 | 31/13 49 | 11/21 50 | 31/39 51 | 0/9 52 | 13/50 53 | 10/14 54 | 16/10 55 | 3/24 56 | 7/0 57 | 50/50 -------------------------------------------------------------------------------- /src/main/resources/2017/day24_test.txt: -------------------------------------------------------------------------------- 1 | 0/2 2 | 2/2 3 | 2/3 4 | 3/4 5 | 3/5 6 | 0/1 7 | 10/1 8 | 9/10 -------------------------------------------------------------------------------- /src/main/resources/2017/day25_1.txt: -------------------------------------------------------------------------------- 1 | Begin in state A. 2 | Perform a diagnostic checksum after 12523873 steps. 3 | 4 | In state A: 5 | If the current value is 0: 6 | - Write the value 1. 7 | - Move one slot to the right. 8 | - Continue with state B. 9 | If the current value is 1: 10 | - Write the value 1. 11 | - Move one slot to the left. 12 | - Continue with state E. 13 | 14 | In state B: 15 | If the current value is 0: 16 | - Write the value 1. 17 | - Move one slot to the right. 18 | - Continue with state C. 19 | If the current value is 1: 20 | - Write the value 1. 21 | - Move one slot to the right. 22 | - Continue with state F. 23 | 24 | In state C: 25 | If the current value is 0: 26 | - Write the value 1. 27 | - Move one slot to the left. 28 | - Continue with state D. 29 | If the current value is 1: 30 | - Write the value 0. 31 | - Move one slot to the right. 32 | - Continue with state B. 33 | 34 | In state D: 35 | If the current value is 0: 36 | - Write the value 1. 37 | - Move one slot to the right. 38 | - Continue with state E. 39 | If the current value is 1: 40 | - Write the value 0. 41 | - Move one slot to the left. 42 | - Continue with state C. 43 | 44 | In state E: 45 | If the current value is 0: 46 | - Write the value 1. 47 | - Move one slot to the left. 48 | - Continue with state A. 49 | If the current value is 1: 50 | - Write the value 0. 51 | - Move one slot to the right. 52 | - Continue with state D. 53 | 54 | In state F: 55 | If the current value is 0: 56 | - Write the value 1. 57 | - Move one slot to the right. 58 | - Continue with state A. 59 | If the current value is 1: 60 | - Write the value 1. 61 | - Move one slot to the right. 62 | - Continue with state C. -------------------------------------------------------------------------------- /src/main/resources/2017/day25_test.txt: -------------------------------------------------------------------------------- 1 | Begin in state A. 2 | Perform a diagnostic checksum after 6 steps. 3 | 4 | In state A: 5 | If the current value is 0: 6 | - Write the value 1. 7 | - Move one slot to the right. 8 | - Continue with state B. 9 | If the current value is 1: 10 | - Write the value 0. 11 | - Move one slot to the left. 12 | - Continue with state B. 13 | 14 | In state B: 15 | If the current value is 0: 16 | - Write the value 1. 17 | - Move one slot to the left. 18 | - Continue with state A. 19 | If the current value is 1: 20 | - Write the value 1. 21 | - Move one slot to the right. 22 | - Continue with state A. -------------------------------------------------------------------------------- /src/main/resources/2017/day2_1.txt: -------------------------------------------------------------------------------- 1 | 3458 3471 163 1299 170 4200 2425 167 3636 4001 4162 115 2859 130 4075 4269 2 | 2777 2712 120 2569 2530 3035 1818 32 491 872 113 92 2526 477 138 1360 3 | 2316 35 168 174 1404 1437 2631 1863 1127 640 1745 171 2391 2587 214 193 4 | 197 2013 551 1661 121 206 203 174 2289 843 732 2117 360 1193 999 2088 5 | 3925 3389 218 1134 220 171 1972 348 3919 3706 494 3577 3320 239 120 2508 6 | 239 947 1029 2024 733 242 217 1781 2904 2156 1500 3100 497 2498 3312 211 7 | 188 3806 3901 261 235 3733 3747 3721 267 3794 3814 3995 3004 915 4062 3400 8 | 918 63 2854 2799 178 176 1037 487 206 157 2212 2539 2816 2501 927 3147 9 | 186 194 307 672 208 351 243 180 619 749 590 745 671 707 334 224 10 | 1854 3180 1345 3421 478 214 198 194 4942 5564 2469 242 5248 5786 5260 4127 11 | 3780 2880 236 330 3227 1252 3540 218 213 458 201 408 3240 249 1968 2066 12 | 1188 696 241 57 151 609 199 765 1078 976 1194 177 238 658 860 1228 13 | 903 612 188 766 196 900 62 869 892 123 226 57 940 168 165 103 14 | 710 3784 83 2087 2582 3941 97 1412 2859 117 3880 411 102 3691 4366 4104 15 | 3178 219 253 1297 3661 1552 8248 678 245 7042 260 581 7350 431 8281 8117 16 | 837 80 95 281 652 822 1028 1295 101 1140 88 452 85 444 649 1247 17 | -------------------------------------------------------------------------------- /src/main/resources/2017/day6_1.txt: -------------------------------------------------------------------------------- 1 | 2 8 8 5 4 2 3 1 5 5 1 2 15 13 5 14 2 | -------------------------------------------------------------------------------- /src/main/resources/2017/day8_test.txt: -------------------------------------------------------------------------------- 1 | b inc 5 if a > 1 2 | a inc 1 if b < 5 3 | c dec -10 if a >= 1 4 | c inc -20 if c == 10 5 | -------------------------------------------------------------------------------- /src/main/resources/2018/day10_test.txt: -------------------------------------------------------------------------------- 1 | position=< 9, 1> velocity=< 0, 2> 2 | position=< 7, 0> velocity=<-1, 0> 3 | position=< 3, -2> velocity=<-1, 1> 4 | position=< 6, 10> velocity=<-2, -1> 5 | position=< 2, -4> velocity=< 2, 2> 6 | position=<-6, 10> velocity=< 2, -2> 7 | position=< 1, 8> velocity=< 1, -1> 8 | position=< 1, 7> velocity=< 1, 0> 9 | position=<-3, 11> velocity=< 1, -2> 10 | position=< 7, 6> velocity=<-1, -1> 11 | position=<-2, 3> velocity=< 1, 0> 12 | position=<-4, 3> velocity=< 2, 0> 13 | position=<10, -3> velocity=<-1, 1> 14 | position=< 5, 11> velocity=< 1, -2> 15 | position=< 4, 7> velocity=< 0, -1> 16 | position=< 8, -2> velocity=< 0, 1> 17 | position=<15, 0> velocity=<-2, 0> 18 | position=< 1, 6> velocity=< 1, 0> 19 | position=< 8, 9> velocity=< 0, -1> 20 | position=< 3, 3> velocity=<-1, 1> 21 | position=< 0, 5> velocity=< 0, -1> 22 | position=<-2, 2> velocity=< 2, 0> 23 | position=< 5, -2> velocity=< 1, 2> 24 | position=< 1, 4> velocity=< 2, 1> 25 | position=<-2, 7> velocity=< 2, -2> 26 | position=< 3, 6> velocity=<-1, -1> 27 | position=< 5, 0> velocity=< 1, 0> 28 | position=<-6, 0> velocity=< 2, 0> 29 | position=< 5, 9> velocity=< 1, -2> 30 | position=<14, 7> velocity=<-2, 0> 31 | position=<-3, 6> velocity=< 2, -1> -------------------------------------------------------------------------------- /src/main/resources/2018/day12.txt: -------------------------------------------------------------------------------- 1 | initial state: ##.#.####..#####..#.....##....#.#######..#.#...........#......##...##.#...####..##.#..##.....#..#### 2 | 3 | #..#. => # 4 | .###. => . 5 | ..##. => . 6 | ....# => . 7 | #...# => . 8 | .#.#. => . 9 | #.#.# => # 10 | #.... => . 11 | #.#.. => # 12 | ###.# => . 13 | .#... => # 14 | #.### => . 15 | .#.## => # 16 | ..#.. => # 17 | .#### => . 18 | ..### => # 19 | ...#. => . 20 | ##.#. => # 21 | ##.## => # 22 | .##.# => # 23 | ###.. => . 24 | ..#.# => . 25 | ...## => # 26 | ##... => # 27 | ##### => . 28 | #.##. => . 29 | .#..# => # 30 | ##..# => . 31 | ..... => . 32 | ####. => # 33 | #..## => . 34 | .##.. => # -------------------------------------------------------------------------------- /src/main/resources/2018/day12_test.txt: -------------------------------------------------------------------------------- 1 | initial state: #..#.#..##......###...### 2 | 3 | ...## => # 4 | ..#.. => # 5 | .#... => # 6 | .#.#. => # 7 | .#.## => # 8 | .##.. => # 9 | .#### => # 10 | #.#.# => # 11 | #.### => # 12 | ##.#. => # 13 | ##.## => # 14 | ###.. => # 15 | ###.# => # 16 | ####. => # -------------------------------------------------------------------------------- /src/main/resources/2018/day13_test.txt: -------------------------------------------------------------------------------- 1 | /->-\ 2 | | | /----\ 3 | | /-+--+-\ | 4 | | | | | v | 5 | \-+-/ \-+--/ 6 | \------/ -------------------------------------------------------------------------------- /src/main/resources/2018/day13_test2.txt: -------------------------------------------------------------------------------- 1 | />-<\ 2 | | | 3 | | /<+-\ 4 | | | | v 5 | \>+/ -------------------------------------------------------------------------------- /src/main/resources/2018/day2_test.txt: -------------------------------------------------------------------------------- 1 | abcdef 2 | bababc 3 | abbcde 4 | abcccd 5 | aabcdd 6 | abcdee 7 | ababab -------------------------------------------------------------------------------- /src/main/resources/2018/day2_test2.txt: -------------------------------------------------------------------------------- 1 | abcde 2 | fghij 3 | klmno 4 | pqrst 5 | fguij 6 | axcye 7 | wvxyz -------------------------------------------------------------------------------- /src/main/resources/2018/day3_test.txt: -------------------------------------------------------------------------------- 1 | #1 @ 1,3: 4x4 2 | #2 @ 3,1: 4x4 3 | #3 @ 5,5: 2x2 -------------------------------------------------------------------------------- /src/main/resources/2018/day4_test.txt: -------------------------------------------------------------------------------- 1 | [1518-11-01 00:00] Guard #10 begins shift 2 | [1518-11-01 00:05] falls asleep 3 | [1518-11-01 00:25] wakes up 4 | [1518-11-01 00:30] falls asleep 5 | [1518-11-01 00:55] wakes up 6 | [1518-11-01 23:58] Guard #99 begins shift 7 | [1518-11-02 00:40] falls asleep 8 | [1518-11-02 00:50] wakes up 9 | [1518-11-03 00:05] Guard #10 begins shift 10 | [1518-11-03 00:24] falls asleep 11 | [1518-11-03 00:29] wakes up 12 | [1518-11-04 00:02] Guard #99 begins shift 13 | [1518-11-04 00:36] falls asleep 14 | [1518-11-04 00:46] wakes up 15 | [1518-11-05 00:03] Guard #99 begins shift 16 | [1518-11-05 00:45] falls asleep 17 | [1518-11-05 00:55] wakes up -------------------------------------------------------------------------------- /src/main/resources/2018/day6.txt: -------------------------------------------------------------------------------- 1 | 81, 46 2 | 330, 289 3 | 171, 261 4 | 248, 97 5 | 142, 265 6 | 139, 293 7 | 309, 208 8 | 315, 92 9 | 72, 206 10 | 59, 288 11 | 95, 314 12 | 126, 215 13 | 240, 177 14 | 78, 64 15 | 162, 168 16 | 75, 81 17 | 271, 258 18 | 317, 223 19 | 210, 43 20 | 47, 150 21 | 352, 116 22 | 316, 256 23 | 269, 47 24 | 227, 343 25 | 125, 290 26 | 245, 310 27 | 355, 301 28 | 251, 282 29 | 353, 107 30 | 254, 298 31 | 212, 128 32 | 60, 168 33 | 318, 254 34 | 310, 303 35 | 176, 345 36 | 110, 109 37 | 217, 338 38 | 344, 330 39 | 231, 349 40 | 259, 208 41 | 201, 57 42 | 200, 327 43 | 354, 111 44 | 166, 214 45 | 232, 85 46 | 96, 316 47 | 151, 288 48 | 217, 339 49 | 62, 221 50 | 307, 68 -------------------------------------------------------------------------------- /src/main/resources/2018/day6_test.txt: -------------------------------------------------------------------------------- 1 | 1, 1 2 | 1, 6 3 | 8, 3 4 | 3, 4 5 | 5, 5 6 | 8, 9 -------------------------------------------------------------------------------- /src/main/resources/2018/day7_test.txt: -------------------------------------------------------------------------------- 1 | Step C must be finished before step A can begin. 2 | Step C must be finished before step F can begin. 3 | Step A must be finished before step B can begin. 4 | Step A must be finished before step D can begin. 5 | Step B must be finished before step E can begin. 6 | Step D must be finished before step E can begin. 7 | Step F must be finished before step E can begin. -------------------------------------------------------------------------------- /src/main/resources/2018/day8_test.txt: -------------------------------------------------------------------------------- 1 | 2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2 -------------------------------------------------------------------------------- /src/main/resources/2019/day10_1.txt: -------------------------------------------------------------------------------- 1 | ....#.....#.#...##..........#.......#...... 2 | .....#...####..##...#......#.........#..... 3 | .#.#...#..........#.....#.##.......#...#..# 4 | .#..#...........#..#..#.#.......####.....#. 5 | ##..#.................#...#..........##.##. 6 | #..##.#...#.....##.#..#...#..#..#....#....# 7 | ##...#.............#.#..........#...#.....# 8 | #.#..##.#.#..#.#...#.....#.#.............#. 9 | ...#..##....#........#..................... 10 | ##....###..#.#.......#...#..........#..#..# 11 | ....#.#....##...###......#......#...#...... 12 | .........#.#.....#..#........#..#..##..#... 13 | ....##...#..##...#.....##.#..#....#........ 14 | ............#....######......##......#...#. 15 | #...........##...#.#......#....#....#...... 16 | ......#.....#.#....#...##.###.....#...#.#.. 17 | ..#.....##..........#..........#........... 18 | ..#.#..#......#......#.....#...##.......##. 19 | .#..#....##......#.............#........... 20 | ..##.#.....#.........#....###.........#..#. 21 | ...#....#...#.#.......#...#.#.....#........ 22 | ...####........#...#....#....#........##..# 23 | .#...........#.................#...#...#..# 24 | #................#......#..#...........#..# 25 | ..#.#.......#...........#.#......#......... 26 | ....#............#.............#.####.#.#.. 27 | .....##....#..#...........###........#...#. 28 | .#.....#...#.#...#..#..........#..#.#...... 29 | .#.##...#........#..#...##...#...#...#.#.#. 30 | #.......#...#...###..#....#..#...#......... 31 | .....#...##...#.###.#...##..........##.###. 32 | ..#.....#.##..#.....#..#.....#....#....#..# 33 | .....#.....#..............####.#.........#. 34 | ..#..#.#..#.....#..........#..#....#....#.. 35 | #.....#.#......##.....#...#...#.......#.#.. 36 | ..##.##...........#..........#............. 37 | ...#..##....#...##..##......#........#....# 38 | .....#..........##.#.##..#....##..#........ 39 | .#...#...#......#..#.##.....#...#.....##... 40 | ...##.#....#...........####.#....#.#....#.. 41 | ...#....#.#..#.........#.......#..#...##... 42 | ...##..............#......#................ 43 | ........................#....##..#........# 44 | -------------------------------------------------------------------------------- /src/main/resources/2019/day11_1.txt: -------------------------------------------------------------------------------- 1 | 3,8,1005,8,311,1106,0,11,0,0,0,104,1,104,0,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,0,10,4,10,1002,8,1,29,3,8,102,-1,8,10,1001,10,1,10,4,10,108,0,8,10,4,10,101,0,8,50,1,2,19,10,1006,0,23,1,103,14,10,1,1106,15,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,1,10,4,10,102,1,8,88,1006,0,59,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,1,10,4,10,1002,8,1,113,2,101,12,10,2,1001,0,10,2,1006,14,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,0,8,10,4,10,102,1,8,146,1,1106,11,10,1006,0,2,1,9,8,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,1,10,4,10,101,0,8,180,1,6,13,10,1,1102,15,10,2,7,1,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,108,0,8,10,4,10,1002,8,1,213,1006,0,74,2,1005,9,10,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,1002,8,1,243,3,8,1002,8,-1,10,101,1,10,10,4,10,108,1,8,10,4,10,101,0,8,264,2,104,8,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,108,1,8,10,4,10,1001,8,0,290,101,1,9,9,1007,9,952,10,1005,10,15,99,109,633,104,0,104,1,21101,387512640296,0,1,21101,0,328,0,1106,0,432,21102,1,665749660564,1,21101,339,0,0,1106,0,432,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,21102,179318226984,1,1,21101,386,0,0,1105,1,432,21101,46266346499,0,1,21101,0,397,0,1105,1,432,3,10,104,0,104,0,3,10,104,0,104,0,21102,709580555028,1,1,21102,420,1,0,1106,0,432,21102,1,988220642068,1,21101,0,431,0,1106,0,432,99,109,2,21202,-1,1,1,21101,40,0,2,21102,1,463,3,21102,1,453,0,1106,0,496,109,-2,2106,0,0,0,1,0,0,1,109,2,3,10,204,-1,1001,458,459,474,4,0,1001,458,1,458,108,4,458,10,1006,10,490,1102,0,1,458,109,-2,2105,1,0,0,109,4,2102,1,-1,495,1207,-3,0,10,1006,10,513,21101,0,0,-3,21201,-3,0,1,22101,0,-2,2,21102,1,1,3,21101,532,0,0,1106,0,537,109,-4,2106,0,0,109,5,1207,-3,1,10,1006,10,560,2207,-4,-2,10,1006,10,560,22102,1,-4,-4,1105,1,628,21201,-4,0,1,21201,-3,-1,2,21202,-2,2,3,21102,1,579,0,1105,1,537,22101,0,1,-4,21101,1,0,-1,2207,-4,-2,10,1006,10,598,21101,0,0,-1,22202,-2,-1,-2,2107,0,-3,10,1006,10,620,22101,0,-1,1,21102,620,1,0,106,0,495,21202,-2,-1,-2,22201,-4,-2,-4,109,-5,2105,1,0 2 | -------------------------------------------------------------------------------- /src/main/resources/2019/day14_1.txt: -------------------------------------------------------------------------------- 1 | 4 BFNQL => 9 LMCRF 2 | 2 XGWNS, 7 TCRNC => 5 TPZCH 3 | 4 RKHMQ, 1 QHRG, 5 JDSNJ => 4 XGWNS 4 | 6 HWTBC, 4 XGWNS => 6 CWCD 5 | 1 BKPZH, 2 FLZX => 9 HWFQG 6 | 1 GDVD, 2 HTSW => 8 CNQW 7 | 2 RMDG => 9 RKHMQ 8 | 3 RTLHZ => 3 MSKWT 9 | 1 QLNHG, 1 RJHCP => 3 GRDJ 10 | 10 DLSD, 2 SWKHJ, 15 HTSW => 1 TCRNC 11 | 4 SWKHJ, 24 ZHDSD, 2 DLSD => 3 CPGJ 12 | 1 SWKHJ => 1 THJHK 13 | 129 ORE => 8 KLSMQ 14 | 3 SLNKW, 4 RTLHZ => 4 LPVGC 15 | 1 SLNKW => 5 RLGFX 16 | 2 QHRG, 1 SGMK => 8 RJHCP 17 | 9 RGKCF, 7 QHRG => 6 ZHDSD 18 | 8 XGWNS, 1 CPGJ => 2 QLNHG 19 | 2 MQFJF, 7 TBVH, 7 FZXS => 2 WZMRW 20 | 13 ZHDSD, 11 SLNKW, 18 RJHCP => 2 CZJR 21 | 1 CNQW, 5 GRDJ, 3 GDVD => 4 FLZX 22 | 129 ORE => 4 RHSHR 23 | 2 HWTBC, 2 JDSNJ => 8 QPBHG 24 | 1 BKPZH, 8 SWKHJ => 6 WSWBV 25 | 8 RJHCP, 7 FRGJK => 1 GSDT 26 | 6 QPBHG => 4 BKPZH 27 | 17 PCRQV, 6 BFNQL, 9 GSDT, 10 MQDHX, 1 ZHDSD, 1 GRDJ, 14 BRGXB, 3 RTLHZ => 8 CFGK 28 | 8 RMDG => 6 SGMK 29 | 3 CZJR => 8 RTLHZ 30 | 3 BFRTV => 7 RGKCF 31 | 6 FRGJK, 8 CZJR, 4 GRDJ => 4 BRGXB 32 | 4 VRVGB => 7 PCRQV 33 | 4 TCRNC, 1 TBVH, 2 FZXS, 1 BQGM, 1 THJHK, 19 RLGFX => 2 CRJTJ 34 | 5 RDNJK => 6 SWKHJ 35 | 2 FLVC, 2 SLNKW, 30 HWTBC => 8 DLSD 36 | 6 TBVH, 3 ZHDSD => 5 BQGM 37 | 17 RLGFX => 4 SCZQN 38 | 8 SWKHJ => 6 FZXS 39 | 9 LZHZ => 3 QDCL 40 | 2 ZHDSD => 1 RDNJK 41 | 15 FZXS, 3 TPZCH => 6 MQFJF 42 | 12 RLGFX, 9 QPBHG, 6 HTSW => 1 BFNQL 43 | 150 ORE => 9 BFRTV 44 | 2 BFRTV, 2 KLSMQ => 2 RMDG 45 | 4 VFLNM, 30 RKHMQ, 4 CRJTJ, 24 CFGK, 21 SCZQN, 4 BMGBG, 9 HWFQG, 34 CWCD, 7 LPVGC, 10 QDCL, 2 WSWBV, 2 WTZX => 1 FUEL 46 | 6 RHSHR, 3 RGKCF, 1 QHRG => 6 JDSNJ 47 | 3 MQDHX, 2 XGWNS, 12 GRDJ => 9 LZHZ 48 | 128 ORE => 6 ZBWLC 49 | 9 JDSNJ, 7 RMDG => 8 FLVC 50 | 4 DLSD, 12 CZJR, 3 MSKWT => 4 MQDHX 51 | 2 BXNX, 4 ZBWLC => 3 QHRG 52 | 19 LMCRF, 3 JDSNJ => 2 BMGBG 53 | 1 RJHCP, 26 SGMK => 9 HTSW 54 | 2 QPBHG => 8 VFLNM 55 | 2 RGKCF => 9 SLNKW 56 | 3 LZHZ, 2 GRDJ => 2 TBVH 57 | 100 ORE => 2 BXNX 58 | 4 DLSD, 21 JDSNJ => 8 GDVD 59 | 2 QHRG => 2 HWTBC 60 | 1 LPVGC, 8 XGWNS => 8 FRGJK 61 | 9 FZXS => 7 VRVGB 62 | 7 WZMRW, 1 TBVH, 1 VFLNM, 8 CNQW, 15 LZHZ, 25 PCRQV, 2 BRGXB => 4 WTZX 63 | -------------------------------------------------------------------------------- /src/main/resources/2019/day16_1.txt: -------------------------------------------------------------------------------- 1 | 59731816011884092945351508129673371014862103878684944826017645844741545300230138932831133873839512146713127268759974246245502075014905070039532876129205215417851534077861438833829150700128859789264910166202535524896960863759734991379392200570075995540154404564759515739872348617947354357737896622983395480822393561314056840468397927687908512181180566958267371679145705350771757054349846320639601111983284494477902984330803048219450650034662420834263425046219982608792077128250835515865313986075722145069152768623913680721193045475863879571787112159970381407518157406924221437152946039000886837781446203456224983154446561285113664381711600293030463013 2 | -------------------------------------------------------------------------------- /src/main/resources/2019/day19_1.txt: -------------------------------------------------------------------------------- 1 | 109,424,203,1,21101,11,0,0,1106,0,282,21102,18,1,0,1105,1,259,1201,1,0,221,203,1,21101,0,31,0,1105,1,282,21102,1,38,0,1106,0,259,21001,23,0,2,22101,0,1,3,21102,1,1,1,21101,57,0,0,1106,0,303,1202,1,1,222,21002,221,1,3,20102,1,221,2,21101,259,0,1,21102,1,80,0,1105,1,225,21101,83,0,2,21101,91,0,0,1105,1,303,2102,1,1,223,20102,1,222,4,21102,259,1,3,21101,225,0,2,21101,225,0,1,21102,1,118,0,1105,1,225,20102,1,222,3,21101,0,51,2,21102,1,133,0,1105,1,303,21202,1,-1,1,22001,223,1,1,21102,1,148,0,1106,0,259,1201,1,0,223,21002,221,1,4,21002,222,1,3,21101,13,0,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21102,195,1,0,106,0,108,20207,1,223,2,21002,23,1,1,21102,-1,1,3,21101,0,214,0,1106,0,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,2102,1,-4,249,21202,-3,1,1,21202,-2,1,2,22102,1,-1,3,21101,0,250,0,1105,1,225,22102,1,1,-4,109,-5,2106,0,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,22101,0,-2,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,22101,0,-2,3,21101,0,343,0,1106,0,303,1105,1,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21202,-4,1,1,21102,384,1,0,1106,0,303,1105,1,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,22101,0,1,-4,109,-5,2105,1,0 2 | -------------------------------------------------------------------------------- /src/main/resources/2019/day1_1.txt: -------------------------------------------------------------------------------- 1 | 75592 2 | 56081 3 | 141375 4 | 103651 5 | 132375 6 | 90584 7 | 94148 8 | 85029 9 | 95082 10 | 148499 11 | 108192 12 | 97739 13 | 60599 14 | 140308 15 | 125171 16 | 129160 17 | 143118 18 | 98762 19 | 103907 20 | 115389 21 | 127835 22 | 57917 23 | 72980 24 | 88747 25 | 86595 26 | 130407 27 | 116862 28 | 84652 29 | 112817 30 | 136922 31 | 51900 32 | 76677 33 | 146244 34 | 121897 35 | 99310 36 | 136486 37 | 84665 38 | 117344 39 | 88992 40 | 83929 41 | 74820 42 | 56651 43 | 74001 44 | 88636 45 | 51232 46 | 57878 47 | 114559 48 | 58879 49 | 145519 50 | 83727 51 | 111774 52 | 146256 53 | 123479 54 | 86955 55 | 64027 56 | 59812 57 | 59211 58 | 85835 59 | 58084 60 | 113676 61 | 119161 62 | 106368 63 | 137358 64 | 85290 65 | 81131 66 | 124857 67 | 51759 68 | 82977 69 | 138957 70 | 146216 71 | 147807 72 | 72265 73 | 60332 74 | 136741 75 | 110215 76 | 89293 77 | 148703 78 | 73152 79 | 93080 80 | 140220 81 | 68511 82 | 77397 83 | 51934 84 | 100243 85 | 92442 86 | 135254 87 | 98873 88 | 51105 89 | 118755 90 | 79155 91 | 89249 92 | 137430 93 | 142807 94 | 86334 95 | 117266 96 | 149484 97 | 89284 98 | 63361 99 | 52269 100 | 111666 101 | -------------------------------------------------------------------------------- /src/main/resources/2019/day22_1.txt: -------------------------------------------------------------------------------- 1 | deal with increment 55 2 | cut -6791 3 | deal with increment 9 4 | cut -5412 5 | deal with increment 21 6 | deal into new stack 7 | deal with increment 72 8 | cut -362 9 | deal with increment 24 10 | cut -5369 11 | deal with increment 22 12 | cut 731 13 | deal with increment 72 14 | cut 412 15 | deal into new stack 16 | deal with increment 22 17 | cut -5253 18 | deal with increment 73 19 | deal into new stack 20 | cut -6041 21 | deal into new stack 22 | cut 6605 23 | deal with increment 6 24 | cut 9897 25 | deal with increment 59 26 | cut -9855 27 | deal into new stack 28 | cut -7284 29 | deal with increment 7 30 | cut 332 31 | deal with increment 37 32 | deal into new stack 33 | deal with increment 43 34 | deal into new stack 35 | deal with increment 59 36 | cut 1940 37 | deal with increment 16 38 | cut 3464 39 | deal with increment 24 40 | cut -7766 41 | deal with increment 36 42 | cut -156 43 | deal with increment 18 44 | cut 8207 45 | deal with increment 33 46 | cut -393 47 | deal with increment 4 48 | deal into new stack 49 | cut -4002 50 | deal into new stack 51 | cut -8343 52 | deal into new stack 53 | deal with increment 70 54 | deal into new stack 55 | cut 995 56 | deal with increment 22 57 | cut 1267 58 | deal with increment 47 59 | cut -3161 60 | deal into new stack 61 | deal with increment 34 62 | cut -6221 63 | deal with increment 26 64 | cut 4956 65 | deal with increment 57 66 | deal into new stack 67 | cut -4983 68 | deal with increment 36 69 | cut -1101 70 | deal into new stack 71 | deal with increment 2 72 | cut 4225 73 | deal with increment 35 74 | cut -721 75 | deal with increment 17 76 | cut 5866 77 | deal with increment 40 78 | cut -531 79 | deal into new stack 80 | deal with increment 63 81 | cut -5839 82 | deal with increment 30 83 | cut 5812 84 | deal with increment 35 85 | deal into new stack 86 | deal with increment 46 87 | cut -5638 88 | deal with increment 60 89 | deal into new stack 90 | deal with increment 33 91 | cut -4690 92 | deal with increment 7 93 | cut 6264 94 | deal into new stack 95 | cut 8949 96 | deal into new stack 97 | cut -4329 98 | deal with increment 52 99 | cut 3461 100 | deal with increment 47 101 | -------------------------------------------------------------------------------- /src/main/resources/2019/day24_1.txt: -------------------------------------------------------------------------------- 1 | ##.#. 2 | .#.## 3 | .#... 4 | #..#. 5 | .##.. 6 | -------------------------------------------------------------------------------- /src/main/resources/2019/day24_a.txt: -------------------------------------------------------------------------------- 1 | ....# 2 | #..#. 3 | #.?## 4 | ..#.. 5 | #.... 6 | -------------------------------------------------------------------------------- /src/main/resources/2019/day5_1.txt: -------------------------------------------------------------------------------- 1 | 3,225,1,225,6,6,1100,1,238,225,104,0,1101,61,45,225,102,94,66,224,101,-3854,224,224,4,224,102,8,223,223,1001,224,7,224,1,223,224,223,1101,31,30,225,1102,39,44,224,1001,224,-1716,224,4,224,102,8,223,223,1001,224,7,224,1,224,223,223,1101,92,41,225,101,90,40,224,1001,224,-120,224,4,224,102,8,223,223,1001,224,1,224,1,223,224,223,1101,51,78,224,101,-129,224,224,4,224,1002,223,8,223,1001,224,6,224,1,224,223,223,1,170,13,224,101,-140,224,224,4,224,102,8,223,223,1001,224,4,224,1,223,224,223,1101,14,58,225,1102,58,29,225,1102,68,70,225,1002,217,87,224,101,-783,224,224,4,224,102,8,223,223,101,2,224,224,1,224,223,223,1101,19,79,225,1001,135,42,224,1001,224,-56,224,4,224,102,8,223,223,1001,224,6,224,1,224,223,223,2,139,144,224,1001,224,-4060,224,4,224,102,8,223,223,101,1,224,224,1,223,224,223,1102,9,51,225,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,1008,677,226,224,102,2,223,223,1006,224,329,101,1,223,223,108,677,677,224,102,2,223,223,1005,224,344,101,1,223,223,107,677,677,224,1002,223,2,223,1005,224,359,101,1,223,223,1107,226,677,224,1002,223,2,223,1005,224,374,1001,223,1,223,1008,677,677,224,102,2,223,223,1006,224,389,1001,223,1,223,1007,677,677,224,1002,223,2,223,1006,224,404,1001,223,1,223,8,677,226,224,102,2,223,223,1005,224,419,1001,223,1,223,8,226,226,224,102,2,223,223,1006,224,434,101,1,223,223,1107,226,226,224,1002,223,2,223,1006,224,449,101,1,223,223,1107,677,226,224,102,2,223,223,1005,224,464,101,1,223,223,1108,226,226,224,102,2,223,223,1006,224,479,1001,223,1,223,7,677,677,224,1002,223,2,223,1006,224,494,101,1,223,223,7,677,226,224,102,2,223,223,1005,224,509,101,1,223,223,1108,226,677,224,1002,223,2,223,1006,224,524,101,1,223,223,8,226,677,224,1002,223,2,223,1005,224,539,101,1,223,223,1007,226,226,224,102,2,223,223,1006,224,554,1001,223,1,223,108,226,226,224,1002,223,2,223,1006,224,569,1001,223,1,223,1108,677,226,224,102,2,223,223,1005,224,584,101,1,223,223,108,226,677,224,102,2,223,223,1005,224,599,101,1,223,223,1007,226,677,224,102,2,223,223,1006,224,614,1001,223,1,223,1008,226,226,224,1002,223,2,223,1006,224,629,1001,223,1,223,107,226,226,224,1002,223,2,223,1006,224,644,101,1,223,223,7,226,677,224,102,2,223,223,1005,224,659,1001,223,1,223,107,677,226,224,102,2,223,223,1005,224,674,1001,223,1,223,4,223,99,226 2 | -------------------------------------------------------------------------------- /src/main/resources/2019/day7_1.txt: -------------------------------------------------------------------------------- 1 | 3,8,1001,8,10,8,105,1,0,0,21,46,55,68,89,110,191,272,353,434,99999,3,9,1002,9,3,9,1001,9,3,9,102,4,9,9,101,4,9,9,1002,9,5,9,4,9,99,3,9,102,3,9,9,4,9,99,3,9,1001,9,5,9,102,4,9,9,4,9,99,3,9,1001,9,5,9,1002,9,2,9,1001,9,5,9,1002,9,3,9,4,9,99,3,9,101,3,9,9,102,3,9,9,101,3,9,9,1002,9,4,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,99,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,99 2 | -------------------------------------------------------------------------------- /src/main/resources/2022/day10.txt: -------------------------------------------------------------------------------- 1 | addx 1 2 | addx 4 3 | noop 4 | noop 5 | noop 6 | addx 5 7 | addx 3 8 | noop 9 | addx 2 10 | noop 11 | noop 12 | noop 13 | noop 14 | addx 3 15 | addx 5 16 | addx 2 17 | addx 1 18 | noop 19 | addx 5 20 | addx -1 21 | addx 5 22 | noop 23 | addx 3 24 | noop 25 | addx -40 26 | noop 27 | addx 38 28 | addx -31 29 | addx 3 30 | noop 31 | addx 2 32 | addx -7 33 | addx 8 34 | addx 2 35 | addx 5 36 | addx 2 37 | addx 3 38 | addx -2 39 | noop 40 | noop 41 | noop 42 | addx 5 43 | addx 2 44 | noop 45 | addx 3 46 | addx 2 47 | noop 48 | addx 3 49 | addx -36 50 | noop 51 | noop 52 | addx 5 53 | noop 54 | noop 55 | addx 8 56 | addx -5 57 | addx 5 58 | addx 2 59 | addx -15 60 | addx 16 61 | addx 4 62 | noop 63 | addx 1 64 | noop 65 | noop 66 | addx 4 67 | addx 5 68 | addx -30 69 | addx 35 70 | addx -1 71 | addx 2 72 | addx -36 73 | addx 5 74 | noop 75 | noop 76 | addx -2 77 | addx 5 78 | addx 2 79 | addx 3 80 | noop 81 | addx 2 82 | noop 83 | noop 84 | addx 5 85 | noop 86 | addx 14 87 | addx -13 88 | addx 5 89 | addx -14 90 | addx 18 91 | addx 3 92 | addx 2 93 | addx -2 94 | addx 5 95 | addx -40 96 | noop 97 | addx 32 98 | addx -25 99 | addx 3 100 | noop 101 | addx 2 102 | addx 3 103 | addx -2 104 | addx 2 105 | addx 2 106 | noop 107 | addx 3 108 | addx 5 109 | addx 2 110 | addx 9 111 | addx -36 112 | addx 30 113 | addx 5 114 | addx 2 115 | addx -25 116 | addx 26 117 | addx -38 118 | addx 10 119 | addx -3 120 | noop 121 | noop 122 | addx 22 123 | addx -16 124 | addx -1 125 | addx 5 126 | addx 3 127 | noop 128 | addx 2 129 | addx -20 130 | addx 21 131 | addx 3 132 | addx 2 133 | addx -24 134 | addx 28 135 | noop 136 | addx 5 137 | addx 3 138 | noop 139 | addx -24 140 | noop -------------------------------------------------------------------------------- /src/main/resources/2022/day10_test.txt: -------------------------------------------------------------------------------- 1 | addx 15 2 | addx -11 3 | addx 6 4 | addx -3 5 | addx 5 6 | addx -1 7 | addx -8 8 | addx 13 9 | addx 4 10 | noop 11 | addx -1 12 | addx 5 13 | addx -1 14 | addx 5 15 | addx -1 16 | addx 5 17 | addx -1 18 | addx 5 19 | addx -1 20 | addx -35 21 | addx 1 22 | addx 24 23 | addx -19 24 | addx 1 25 | addx 16 26 | addx -11 27 | noop 28 | noop 29 | addx 21 30 | addx -15 31 | noop 32 | noop 33 | addx -3 34 | addx 9 35 | addx 1 36 | addx -3 37 | addx 8 38 | addx 1 39 | addx 5 40 | noop 41 | noop 42 | noop 43 | noop 44 | noop 45 | addx -36 46 | noop 47 | addx 1 48 | addx 7 49 | noop 50 | noop 51 | noop 52 | addx 2 53 | addx 6 54 | noop 55 | noop 56 | noop 57 | noop 58 | noop 59 | addx 1 60 | noop 61 | noop 62 | addx 7 63 | addx 1 64 | noop 65 | addx -13 66 | addx 13 67 | addx 7 68 | noop 69 | addx 1 70 | addx -33 71 | noop 72 | noop 73 | noop 74 | addx 2 75 | noop 76 | noop 77 | noop 78 | addx 8 79 | noop 80 | addx -1 81 | addx 2 82 | addx 1 83 | noop 84 | addx 17 85 | addx -9 86 | addx 1 87 | addx 1 88 | addx -3 89 | addx 11 90 | noop 91 | noop 92 | addx 1 93 | noop 94 | addx 1 95 | noop 96 | noop 97 | addx -13 98 | addx -19 99 | addx 1 100 | addx 3 101 | addx 26 102 | addx -30 103 | addx 12 104 | addx -1 105 | addx 3 106 | addx 1 107 | noop 108 | noop 109 | noop 110 | addx -9 111 | addx 18 112 | addx 1 113 | addx 2 114 | noop 115 | noop 116 | addx 9 117 | noop 118 | noop 119 | noop 120 | addx -1 121 | addx 2 122 | addx -37 123 | addx 1 124 | addx 3 125 | noop 126 | addx 15 127 | addx -21 128 | addx 22 129 | addx -6 130 | addx 1 131 | noop 132 | addx 2 133 | addx 1 134 | noop 135 | addx -10 136 | noop 137 | noop 138 | addx 20 139 | addx 1 140 | addx 2 141 | addx 2 142 | addx -6 143 | addx -11 144 | noop 145 | noop 146 | noop -------------------------------------------------------------------------------- /src/main/resources/2022/day11.txt: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 63, 57 3 | Operation: new = old * 11 4 | Test: divisible by 7 5 | If true: throw to monkey 6 6 | If false: throw to monkey 2 7 | 8 | Monkey 1: 9 | Starting items: 82, 66, 87, 78, 77, 92, 83 10 | Operation: new = old + 1 11 | Test: divisible by 11 12 | If true: throw to monkey 5 13 | If false: throw to monkey 0 14 | 15 | Monkey 2: 16 | Starting items: 97, 53, 53, 85, 58, 54 17 | Operation: new = old * 7 18 | Test: divisible by 13 19 | If true: throw to monkey 4 20 | If false: throw to monkey 3 21 | 22 | Monkey 3: 23 | Starting items: 50 24 | Operation: new = old + 3 25 | Test: divisible by 3 26 | If true: throw to monkey 1 27 | If false: throw to monkey 7 28 | 29 | Monkey 4: 30 | Starting items: 64, 69, 52, 65, 73 31 | Operation: new = old + 6 32 | Test: divisible by 17 33 | If true: throw to monkey 3 34 | If false: throw to monkey 7 35 | 36 | Monkey 5: 37 | Starting items: 57, 91, 65 38 | Operation: new = old + 5 39 | Test: divisible by 2 40 | If true: throw to monkey 0 41 | If false: throw to monkey 6 42 | 43 | Monkey 6: 44 | Starting items: 67, 91, 84, 78, 60, 69, 99, 83 45 | Operation: new = old * old 46 | Test: divisible by 5 47 | If true: throw to monkey 2 48 | If false: throw to monkey 4 49 | 50 | Monkey 7: 51 | Starting items: 58, 78, 69, 65 52 | Operation: new = old + 7 53 | Test: divisible by 19 54 | If true: throw to monkey 5 55 | If false: throw to monkey 1 -------------------------------------------------------------------------------- /src/main/resources/2022/day11_test.txt: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 79, 98 3 | Operation: new = old * 19 4 | Test: divisible by 23 5 | If true: throw to monkey 2 6 | If false: throw to monkey 3 7 | 8 | Monkey 1: 9 | Starting items: 54, 65, 75, 74 10 | Operation: new = old + 6 11 | Test: divisible by 19 12 | If true: throw to monkey 2 13 | If false: throw to monkey 0 14 | 15 | Monkey 2: 16 | Starting items: 79, 60, 97 17 | Operation: new = old * old 18 | Test: divisible by 13 19 | If true: throw to monkey 1 20 | If false: throw to monkey 3 21 | 22 | Monkey 3: 23 | Starting items: 74 24 | Operation: new = old + 3 25 | Test: divisible by 17 26 | If true: throw to monkey 0 27 | If false: throw to monkey 1 -------------------------------------------------------------------------------- /src/main/resources/2022/day12_test.txt: -------------------------------------------------------------------------------- 1 | Sabqponm 2 | abcryxxl 3 | accszExk 4 | acctuvwj 5 | abdefghi 6 | -------------------------------------------------------------------------------- /src/main/resources/2022/day13_test.txt: -------------------------------------------------------------------------------- 1 | [1,1,3,1,1] 2 | [1,1,5,1,1] 3 | 4 | [[1],[2,3,4]] 5 | [[1],4] 6 | 7 | [9] 8 | [[8,7,6]] 9 | 10 | [[4,4],4,4] 11 | [[4,4],4,4,4] 12 | 13 | [7,7,7,7] 14 | [7,7,7] 15 | 16 | [] 17 | [3] 18 | 19 | [[[]]] 20 | [[]] 21 | 22 | [1,[2,[3,[4,[5,6,7]]]],8,9] 23 | [1,[2,[3,[4,[5,6,0]]]],8,9] 24 | -------------------------------------------------------------------------------- /src/main/resources/2022/day14_test.txt: -------------------------------------------------------------------------------- 1 | 498,4 -> 498,6 -> 496,6 2 | 503,4 -> 502,4 -> 502,9 -> 494,9 3 | -------------------------------------------------------------------------------- /src/main/resources/2022/day15.txt: -------------------------------------------------------------------------------- 1 | Sensor at x=3859432, y=2304903: closest beacon is at x=3677247, y=3140958 2 | Sensor at x=2488890, y=2695345: closest beacon is at x=1934788, y=2667279 3 | Sensor at x=3901948, y=701878: closest beacon is at x=4095477, y=368031 4 | Sensor at x=2422190, y=1775708: closest beacon is at x=1765036, y=2000000 5 | Sensor at x=2703846, y=3282799: closest beacon is at x=2121069, y=3230302 6 | Sensor at x=172003, y=2579074: closest beacon is at x=-77667, y=3197309 7 | Sensor at x=1813149, y=1311283: closest beacon is at x=1765036, y=2000000 8 | Sensor at x=1704453, y=2468117: closest beacon is at x=1934788, y=2667279 9 | Sensor at x=1927725, y=2976002: closest beacon is at x=1934788, y=2667279 10 | Sensor at x=3176646, y=1254463: closest beacon is at x=2946873, y=2167634 11 | Sensor at x=2149510, y=3722117: closest beacon is at x=2121069, y=3230302 12 | Sensor at x=3804434, y=251015: closest beacon is at x=4095477, y=368031 13 | Sensor at x=2613561, y=3932220: closest beacon is at x=2121069, y=3230302 14 | Sensor at x=3997794, y=3291220: closest beacon is at x=3677247, y=3140958 15 | Sensor at x=98328, y=3675176: closest beacon is at x=-77667, y=3197309 16 | Sensor at x=2006541, y=2259601: closest beacon is at x=1934788, y=2667279 17 | Sensor at x=663904, y=122919: closest beacon is at x=1618552, y=-433244 18 | Sensor at x=1116472, y=3349728: closest beacon is at x=2121069, y=3230302 19 | Sensor at x=2810797, y=2300748: closest beacon is at x=2946873, y=2167634 20 | Sensor at x=1760767, y=2024355: closest beacon is at x=1765036, y=2000000 21 | Sensor at x=3098487, y=2529092: closest beacon is at x=2946873, y=2167634 22 | Sensor at x=1716839, y=634872: closest beacon is at x=1618552, y=-433244 23 | Sensor at x=9323, y=979154: closest beacon is at x=-245599, y=778791 24 | Sensor at x=1737623, y=2032367: closest beacon is at x=1765036, y=2000000 25 | Sensor at x=26695, y=3049071: closest beacon is at x=-77667, y=3197309 26 | Sensor at x=3691492, y=3766350: closest beacon is at x=3677247, y=3140958 27 | Sensor at x=730556, y=1657010: closest beacon is at x=1765036, y=2000000 28 | Sensor at x=506169, y=3958647: closest beacon is at x=-77667, y=3197309 29 | Sensor at x=2728744, y=23398: closest beacon is at x=1618552, y=-433244 30 | Sensor at x=3215227, y=3077078: closest beacon is at x=3677247, y=3140958 31 | Sensor at x=2209379, y=3030851: closest beacon is at x=2121069, y=3230302 32 | -------------------------------------------------------------------------------- /src/main/resources/2022/day15_test.txt: -------------------------------------------------------------------------------- 1 | Sensor at x=2, y=18: closest beacon is at x=-2, y=15 2 | Sensor at x=9, y=16: closest beacon is at x=10, y=16 3 | Sensor at x=13, y=2: closest beacon is at x=15, y=3 4 | Sensor at x=12, y=14: closest beacon is at x=10, y=16 5 | Sensor at x=10, y=20: closest beacon is at x=10, y=16 6 | Sensor at x=14, y=17: closest beacon is at x=10, y=16 7 | Sensor at x=8, y=7: closest beacon is at x=2, y=10 8 | Sensor at x=2, y=0: closest beacon is at x=2, y=10 9 | Sensor at x=0, y=11: closest beacon is at x=2, y=10 10 | Sensor at x=20, y=14: closest beacon is at x=25, y=17 11 | Sensor at x=17, y=20: closest beacon is at x=21, y=22 12 | Sensor at x=16, y=7: closest beacon is at x=15, y=3 13 | Sensor at x=14, y=3: closest beacon is at x=15, y=3 14 | Sensor at x=20, y=1: closest beacon is at x=15, y=3 15 | -------------------------------------------------------------------------------- /src/main/resources/2022/day16_test.txt: -------------------------------------------------------------------------------- 1 | Valve AA has flow rate=0; tunnels lead to valves DD, II, BB 2 | Valve BB has flow rate=13; tunnels lead to valves CC, AA 3 | Valve CC has flow rate=2; tunnels lead to valves DD, BB 4 | Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE 5 | Valve EE has flow rate=3; tunnels lead to valves FF, DD 6 | Valve FF has flow rate=0; tunnels lead to valves EE, GG 7 | Valve GG has flow rate=0; tunnels lead to valves FF, HH 8 | Valve HH has flow rate=22; tunnel leads to valve GG 9 | Valve II has flow rate=0; tunnels lead to valves AA, JJ 10 | Valve JJ has flow rate=21; tunnel leads to valve II 11 | -------------------------------------------------------------------------------- /src/main/resources/2022/day17_test.txt: -------------------------------------------------------------------------------- 1 | >>><<><>><<<>><>>><<<>>><<<><<<>><>><<>> 2 | -------------------------------------------------------------------------------- /src/main/resources/2022/day18_test.txt: -------------------------------------------------------------------------------- 1 | 2,2,2 2 | 1,2,2 3 | 3,2,2 4 | 2,1,2 5 | 2,3,2 6 | 2,2,1 7 | 2,2,3 8 | 2,2,4 9 | 2,2,6 10 | 1,2,5 11 | 3,2,5 12 | 2,1,5 13 | 2,3,5 14 | -------------------------------------------------------------------------------- /src/main/resources/2022/day19_test.txt: -------------------------------------------------------------------------------- 1 | Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 2 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 2 ore and 7 obsidian. 2 | Blueprint 2: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 8 clay. Each geode robot costs 3 ore and 12 obsidian. 3 | -------------------------------------------------------------------------------- /src/main/resources/2022/day1_test.txt: -------------------------------------------------------------------------------- 1 | 1000 2 | 2000 3 | 3000 4 | 5 | 4000 6 | 7 | 5000 8 | 6000 9 | 10 | 7000 11 | 8000 12 | 9000 13 | 14 | 10000 -------------------------------------------------------------------------------- /src/main/resources/2022/day20_test.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -3 4 | 3 5 | -2 6 | 0 7 | 4 8 | -------------------------------------------------------------------------------- /src/main/resources/2022/day21_test.txt: -------------------------------------------------------------------------------- 1 | root: pppw + sjmn 2 | dbpl: 5 3 | cczh: sllz + lgvd 4 | zczc: 2 5 | ptdq: humn - dvpt 6 | dvpt: 3 7 | lfqf: 4 8 | humn: 5 9 | ljgn: 2 10 | sjmn: drzm * dbpl 11 | sllz: 4 12 | pppw: cczh / lfqf 13 | lgvd: ljgn * ptdq 14 | drzm: hmdt - zczc 15 | hmdt: 32 16 | -------------------------------------------------------------------------------- /src/main/resources/2022/day22_test.txt: -------------------------------------------------------------------------------- 1 | ...# 2 | .#.. 3 | #... 4 | .... 5 | ...#.......# 6 | ........#... 7 | ..#....#.... 8 | ..........#. 9 | ...#.... 10 | .....#.. 11 | .#...... 12 | ......#. 13 | 14 | 10R5L5R10L4R5L5 15 | -------------------------------------------------------------------------------- /src/main/resources/2022/day23_test.txt: -------------------------------------------------------------------------------- 1 | ..... 2 | ..##. 3 | ..#.. 4 | ..... 5 | ..##. 6 | ..... 7 | -------------------------------------------------------------------------------- /src/main/resources/2022/day23_test2.txt: -------------------------------------------------------------------------------- 1 | .............. 2 | .............. 3 | .......#...... 4 | .....###.#.... 5 | ...#...#.#.... 6 | ....#...##.... 7 | ...#.###...... 8 | ...##.#.##.... 9 | ....#..#...... 10 | .............. 11 | .............. 12 | .............. 13 | -------------------------------------------------------------------------------- /src/main/resources/2022/day24_test.txt: -------------------------------------------------------------------------------- 1 | #.###### 2 | #>>.<^<# 3 | #.<..<<# 4 | #>v.><># 5 | #<^v^^># 6 | ######.# 7 | -------------------------------------------------------------------------------- /src/main/resources/2022/day25.txt: -------------------------------------------------------------------------------- 1 | 10110-02-=2=2021-= 2 | 1212001= 3 | 1==2=22-222=010100- 4 | 1-12-2020 5 | 1=1210 6 | 2--2=1=-00== 7 | 2=11=0=2-=0=0 8 | 1211 9 | 1-212 10 | 11200---2 11 | 2-1120=0--102-0 12 | 21==12=12 13 | 2-=011 14 | 1=21-00=-=2121- 15 | 1=-0==020-==21=- 16 | 1==022-=-101220 17 | 2-20-220 18 | 1-1- 19 | 1-0-0-=1-0-02= 20 | 10-1=00=0=01=01= 21 | 1=12==--1=1=11 22 | 1=-==22=110=-2 23 | 2101=2 24 | 21=0=0-1=--2--11= 25 | 10-00=2-2=000-10 26 | 2-02-11-=-1 27 | 222002-- 28 | 2=21-2=-20-1211=0= 29 | 2201=121-2=-1 30 | 1=-2--00 31 | 1=-1 32 | 2-0 33 | 10221120220 34 | 1-22 35 | 1=00011220-1==0- 36 | 12112--1=-20 37 | 2-==00200=--=-00 38 | 210-=-=1==1=2 39 | 1=122=110-10=- 40 | 20221101=120 41 | 12-=220==002100010 42 | 121--0=21--=11-2 43 | 10110-=012=10 44 | 120021=-1-2-1=12=-- 45 | 2-001=210= 46 | 22112-=-0 47 | 110---1-=0-11=2= 48 | 1=-20110222-==-00-- 49 | 2-2--0-=---0=-11 50 | 10-2-=-0-1- 51 | 1=1112=21-==00-- 52 | 2=1-22-000=00=0= 53 | 2=-2=1==2 54 | 10 55 | 2=22200-==1-0= 56 | 2=222002= 57 | 2-=1=-=--0- 58 | 210-=2=--2 59 | 12=2-1- 60 | 2-=2110-01=2 61 | 2=011--2-0=1= 62 | 1===-=202 63 | 1002-2-11= 64 | 2201- 65 | 1-21--022-1101=1 66 | 1=121=202 67 | 1=0--121=- 68 | 1-21 69 | 1-=- 70 | 20 71 | 21= 72 | 1-2-121 73 | 21=2-102-1 74 | 2=100=211211120 75 | 1=1010=1--==2-21=2-2 76 | 111200012--0= 77 | 12=0= 78 | 2=--1=22 79 | 1-02-1012 80 | 2211-=0-- 81 | 2---=2=1 82 | 2-00--000-2112 83 | 1021=1 84 | 12-20=-01000==1 85 | 1==-0-1-1-212 86 | 1-0--=01-0=11012== 87 | 1=2010-022 88 | 1== 89 | 1010-=-==0==20 90 | 1=020=0 91 | 1-00- 92 | 12=0=2=20-11 93 | 11-1=- 94 | 2=-=--1==01===2-- 95 | 2-00212 96 | 1-=0-1 97 | 10022 98 | 1-2010--1- 99 | 1=2 100 | 1=220--=01 101 | 100=1-0=---1--221== 102 | 110=2-22200-10- 103 | 20=1 104 | 1- 105 | 2122-=10001102 106 | 1-022-1212210==-2 107 | 10001222--112 108 | 22 109 | 2-=0 110 | 111=00 111 | 1102021-== 112 | -------------------------------------------------------------------------------- /src/main/resources/2022/day25_test.txt: -------------------------------------------------------------------------------- 1 | 1=-0-2 2 | 12111 3 | 2=0= 4 | 21 5 | 2=01 6 | 111 7 | 20012 8 | 112 9 | 1=-1= 10 | 1-12 11 | 12 12 | 1= 13 | 122 14 | -------------------------------------------------------------------------------- /src/main/resources/2022/day2_test.txt: -------------------------------------------------------------------------------- 1 | A Y 2 | B X 3 | C Z -------------------------------------------------------------------------------- /src/main/resources/2022/day3_test.txt: -------------------------------------------------------------------------------- 1 | vJrwpWtwJgWrhcsFMMfFFhFp 2 | jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL 3 | PmmdzqPrVvPwwTWBwg 4 | wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn 5 | ttgJtRGJQctTZtZT 6 | CrZsJsPPZsGzwwsLwLmpwMDw -------------------------------------------------------------------------------- /src/main/resources/2022/day5_test.txt: -------------------------------------------------------------------------------- 1 | [D] 2 | [N] [C] 3 | [Z] [M] [P] 4 | 1 2 3 5 | 6 | move 1 from 2 to 1 7 | move 3 from 1 to 3 8 | move 2 from 2 to 1 9 | move 1 from 1 to 2 -------------------------------------------------------------------------------- /src/main/resources/2022/day7_test.txt: -------------------------------------------------------------------------------- 1 | $ cd / 2 | $ ls 3 | dir a 4 | 14848514 b.txt 5 | 8504156 c.dat 6 | dir d 7 | $ cd a 8 | $ ls 9 | dir e 10 | 29116 f 11 | 2557 g 12 | 62596 h.lst 13 | $ cd e 14 | $ ls 15 | 584 i 16 | $ cd .. 17 | $ cd .. 18 | $ cd d 19 | $ ls 20 | 4060174 j 21 | 8033020 d.log 22 | 5626152 d.ext 23 | 7214296 k -------------------------------------------------------------------------------- /src/main/resources/2022/day8_test.txt: -------------------------------------------------------------------------------- 1 | 30373 2 | 25512 3 | 65332 4 | 33549 5 | 35390 -------------------------------------------------------------------------------- /src/main/resources/2022/day9_test.txt: -------------------------------------------------------------------------------- 1 | R 4 2 | U 4 3 | L 3 4 | D 1 5 | R 4 6 | D 1 7 | L 5 8 | R 2 -------------------------------------------------------------------------------- /src/main/resources/2022/day9_test2.txt: -------------------------------------------------------------------------------- 1 | R 5 2 | U 8 3 | L 8 4 | D 3 5 | R 17 6 | D 10 7 | L 25 8 | U 20 -------------------------------------------------------------------------------- /src/main/resources/2023/day10_test.txt: -------------------------------------------------------------------------------- 1 | ..... 2 | .S-7. 3 | .|.|. 4 | .L-J. 5 | ..... 6 | -------------------------------------------------------------------------------- /src/main/resources/2023/day10_test2.txt: -------------------------------------------------------------------------------- 1 | ..F7. 2 | .FJ|. 3 | SJ.L7 4 | |F--J 5 | LJ... 6 | -------------------------------------------------------------------------------- /src/main/resources/2023/day10_test3.txt: -------------------------------------------------------------------------------- 1 | FF7FSF7F7F7F7F7F---7 2 | L|LJ||||||||||||F--J 3 | FL-7LJLJ||||||LJL-77 4 | F--JF--7||LJLJIF7FJ- 5 | L---JF-JLJIIIIFJLJJ7 6 | |F|F-JF---7IIIL7L|7| 7 | |FFJF7L7F-JF7IIL---7 8 | 7-L-JL7||F7|L7F-7F7| 9 | L.L7LFJ|||||FJL7||LJ 10 | L7JLJL-JLJLJL--JLJ.L 11 | -------------------------------------------------------------------------------- /src/main/resources/2023/day10_test4.txt: -------------------------------------------------------------------------------- 1 | ........... 2 | .S-------7. 3 | .|F-----7|. 4 | .||.....||. 5 | .||.....||. 6 | .|L-7.F-J|. 7 | .|..|.|..|. 8 | .L--J.L--J. 9 | ........... 10 | -------------------------------------------------------------------------------- /src/main/resources/2023/day11_test.txt: -------------------------------------------------------------------------------- 1 | ...#...... 2 | .......#.. 3 | #......... 4 | .......... 5 | ......#... 6 | .#........ 7 | .........# 8 | .......... 9 | .......#.. 10 | #...#..... 11 | -------------------------------------------------------------------------------- /src/main/resources/2023/day12_test.txt: -------------------------------------------------------------------------------- 1 | ???.### 1,1,3 2 | .??..??...?##. 1,1,3 3 | ?#?#?#?#?#?#?#? 1,3,1,6 4 | ????.#...#... 4,1,1 5 | ????.######..#####. 1,6,5 6 | ?###???????? 3,2,1 7 | -------------------------------------------------------------------------------- /src/main/resources/2023/day13_test.txt: -------------------------------------------------------------------------------- 1 | #.##..##. 2 | ..#.##.#. 3 | ##......# 4 | ##......# 5 | ..#.##.#. 6 | ..##..##. 7 | #.#.##.#. 8 | 9 | #...##..# 10 | #....#..# 11 | ..##..### 12 | #####.##. 13 | #####.##. 14 | ..##..### 15 | #....#..# -------------------------------------------------------------------------------- /src/main/resources/2023/day14_test.txt: -------------------------------------------------------------------------------- 1 | O....#.... 2 | O.OO#....# 3 | .....##... 4 | OO.#O....O 5 | .O.....O#. 6 | O.#..O.#.# 7 | ..O..#O..O 8 | .......O.. 9 | #....###.. 10 | #OO..#.... -------------------------------------------------------------------------------- /src/main/resources/2023/day15_test.txt: -------------------------------------------------------------------------------- 1 | rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7 2 | -------------------------------------------------------------------------------- /src/main/resources/2023/day16_test.txt: -------------------------------------------------------------------------------- 1 | .|...\.... 2 | |.-.\..... 3 | .....|-... 4 | ........|. 5 | .......... 6 | .........\ 7 | ..../.\\.. 8 | .-.-/..|.. 9 | .|....-|.\ 10 | ..//.|.... -------------------------------------------------------------------------------- /src/main/resources/2023/day17_test.txt: -------------------------------------------------------------------------------- 1 | 2413432311323 2 | 3215453535623 3 | 3255245654254 4 | 3446585845452 5 | 4546657867536 6 | 1438598798454 7 | 4457876987766 8 | 3637877979653 9 | 4654967986887 10 | 4564679986453 11 | 1224686865563 12 | 2546548887735 13 | 4322674655533 -------------------------------------------------------------------------------- /src/main/resources/2023/day17_test2.txt: -------------------------------------------------------------------------------- 1 | 111111111111 2 | 999999999991 3 | 999999999991 4 | 999999999991 5 | 999999999991 6 | -------------------------------------------------------------------------------- /src/main/resources/2023/day18_test.txt: -------------------------------------------------------------------------------- 1 | R 6 (#70c710) 2 | D 5 (#0dc571) 3 | L 2 (#5713f0) 4 | D 2 (#d2c081) 5 | R 2 (#59c680) 6 | D 2 (#411b91) 7 | L 5 (#8ceee2) 8 | U 2 (#caa173) 9 | L 1 (#1b58a2) 10 | U 2 (#caa171) 11 | R 2 (#7807d2) 12 | U 3 (#a77fa3) 13 | L 2 (#015232) 14 | U 2 (#7a21e3) 15 | -------------------------------------------------------------------------------- /src/main/resources/2023/day19_test.txt: -------------------------------------------------------------------------------- 1 | px{a<2006:qkq,m>2090:A,rfg} 2 | pv{a>1716:R,A} 3 | lnx{m>1548:A,A} 4 | rfg{s<537:gd,x>2440:R,A} 5 | qs{s>3448:A,lnx} 6 | qkq{x<1416:A,crn} 7 | crn{x>2662:A,R} 8 | in{s<1351:px,qqz} 9 | qqz{s>2770:qs,m<1801:hdj,R} 10 | gd{a>3333:R,R} 11 | hdj{m>838:A,pv} 12 | 13 | {x=787,m=2655,a=1222,s=2876} 14 | {x=1679,m=44,a=2067,s=496} 15 | {x=2036,m=264,a=79,s=2244} 16 | {x=2461,m=1339,a=466,s=291} 17 | {x=2127,m=1623,a=2188,s=1013} 18 | -------------------------------------------------------------------------------- /src/main/resources/2023/day1_test.txt: -------------------------------------------------------------------------------- 1 | two1nine 2 | eightwothree 3 | abcone2threexyz 4 | xtwone3four 5 | 4nineeightseven2 6 | zoneight234 7 | 7pqrstsixteen -------------------------------------------------------------------------------- /src/main/resources/2023/day1_test2.txt: -------------------------------------------------------------------------------- 1 | two1nine 2 | eightwothree 3 | abcone2threexyz 4 | xtwone3four 5 | 4nineeightseven2 6 | zoneight234 7 | 7pqrstsixteen -------------------------------------------------------------------------------- /src/main/resources/2023/day20.txt: -------------------------------------------------------------------------------- 1 | %jb -> ps 2 | %cm -> ps, tm 3 | %sl -> ml, cp 4 | %qr -> ml 5 | %hf -> kh, jg 6 | %jg -> kk 7 | %jt -> pq 8 | %qv -> kv 9 | %rj -> mm, kh 10 | %kf -> xt 11 | %kx -> vk, mk 12 | %dq -> qn 13 | &ps -> xc, mq, jt, zs, sr, nt, pq 14 | %jk -> hh, ps 15 | %rr -> mk, nh 16 | %hs -> kh, mb 17 | %mg -> mk, kf 18 | %xt -> dq, mk 19 | &xc -> zh 20 | %mq -> nt 21 | %nh -> bm 22 | &ml -> bp, gd, qv, kq 23 | %md -> hs 24 | %vk -> mk, vl 25 | %mm -> kh 26 | &th -> zh 27 | &zh -> rx 28 | %kc -> ps, jk 29 | %kk -> dm 30 | %jn -> ll, ml 31 | &pd -> zh 32 | &kh -> jg, qx, md, th, hf, dm, kk 33 | %pp -> kh, md 34 | %zf -> ml, bd 35 | %qx -> pp 36 | &mk -> kf, qn, nh, pd, dq, mg, bm 37 | %qn -> rr 38 | %mb -> qb, kh 39 | %nt -> jt 40 | %vl -> zk, mk 41 | %gd -> ml, rm 42 | %hh -> ps, jb 43 | %tm -> ps, mq 44 | %kv -> jn, ml 45 | %zs -> kc 46 | %ll -> ml, kq 47 | %cp -> qv, ml 48 | %rm -> sl, ml 49 | %bd -> qr, ml 50 | %dm -> qx 51 | %qb -> rj, kh 52 | %pq -> zs 53 | %bm -> kx 54 | %sr -> cm, ps 55 | %zk -> mk 56 | broadcaster -> sr, gd, mg, hf 57 | %kq -> zf 58 | &bp -> zh 59 | -------------------------------------------------------------------------------- /src/main/resources/2023/day21_test.txt: -------------------------------------------------------------------------------- 1 | ........... 2 | .....###.#. 3 | .###.##..#. 4 | ..#.#...#.. 5 | ....#.#.... 6 | .##..S####. 7 | .##..#...#. 8 | .......##.. 9 | .##.#.####. 10 | .##..##.##. 11 | ........... 12 | -------------------------------------------------------------------------------- /src/main/resources/2023/day2_test.txt: -------------------------------------------------------------------------------- 1 | Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green 2 | Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue 3 | Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red 4 | Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red 5 | Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green -------------------------------------------------------------------------------- /src/main/resources/2023/day3_test.txt: -------------------------------------------------------------------------------- 1 | 467..114.. 2 | ...*...... 3 | ..35..633. 4 | ......#... 5 | 617*...... 6 | .....+.58. 7 | ..592..... 8 | ......755. 9 | ...$.*.... 10 | .664.598.. -------------------------------------------------------------------------------- /src/main/resources/2023/day4_test.txt: -------------------------------------------------------------------------------- 1 | Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 2 | Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 3 | Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 4 | Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 5 | Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 6 | Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11 7 | -------------------------------------------------------------------------------- /src/main/resources/2023/day5_test.txt: -------------------------------------------------------------------------------- 1 | seeds: 79 14 55 13 2 | 3 | seed-to-soil map: 4 | 50 98 2 5 | 52 50 48 6 | 7 | soil-to-fertilizer map: 8 | 0 15 37 9 | 37 52 2 10 | 39 0 15 11 | 12 | fertilizer-to-water map: 13 | 49 53 8 14 | 0 11 42 15 | 42 0 7 16 | 57 7 4 17 | 18 | water-to-light map: 19 | 88 18 7 20 | 18 25 70 21 | 22 | light-to-temperature map: 23 | 45 77 23 24 | 81 45 19 25 | 68 64 13 26 | 27 | temperature-to-humidity map: 28 | 0 69 1 29 | 1 0 69 30 | 31 | humidity-to-location map: 32 | 60 56 37 33 | 56 93 4 34 | -------------------------------------------------------------------------------- /src/main/resources/2023/day6.txt: -------------------------------------------------------------------------------- 1 | Time: 49 87 78 95 2 | Distance: 356 1378 1502 1882 3 | -------------------------------------------------------------------------------- /src/main/resources/2023/day6_test.txt: -------------------------------------------------------------------------------- 1 | Time: 7 15 30 2 | Distance: 9 40 200 3 | -------------------------------------------------------------------------------- /src/main/resources/2023/day7_test.txt: -------------------------------------------------------------------------------- 1 | 32T3K 765 2 | T55J5 684 3 | KK677 28 4 | KTJJT 220 5 | QQQJA 483 6 | -------------------------------------------------------------------------------- /src/main/resources/2023/day8_test.txt: -------------------------------------------------------------------------------- 1 | RL 2 | 3 | AAA = (BBB, CCC) 4 | BBB = (DDD, EEE) 5 | CCC = (ZZZ, GGG) 6 | DDD = (DDD, DDD) 7 | EEE = (EEE, EEE) 8 | GGG = (GGG, GGG) 9 | ZZZ = (ZZZ, ZZZ) 10 | -------------------------------------------------------------------------------- /src/main/resources/2023/day8_test2.txt: -------------------------------------------------------------------------------- 1 | LR 2 | 3 | 11A = (11B, XXX) 4 | 11B = (XXX, 11Z) 5 | 11Z = (11B, XXX) 6 | 22A = (22B, XXX) 7 | 22B = (22C, 22C) 8 | 22C = (22Z, 22Z) 9 | 22Z = (22B, 22B) 10 | XXX = (XXX, XXX) 11 | -------------------------------------------------------------------------------- /src/main/resources/2023/day9_test.txt: -------------------------------------------------------------------------------- 1 | 0 3 6 9 12 15 2 | 1 3 6 10 15 21 3 | 10 13 16 21 30 45 4 | -------------------------------------------------------------------------------- /src/main/resources/2024/day17.txt: -------------------------------------------------------------------------------- 1 | Register A: 28066687 2 | Register B: 0 3 | Register C: 0 4 | 5 | Program: 2,4,1,1,7,5,4,6,0,3,1,4,5,5,3,0 6 | --------------------------------------------------------------------------------