Skip to content

xenoteo/Advent-of-Code-2020

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 

Repository files navigation

Advent of Code 2020

Advent of Code 2020.

Project structure

xenoteo.com.github
└── dayN
|   ├── input
|   |   └── input.txt
|   ├── part1
|   │   ├── Main.java
|   │   └── Solution.java
|   ├── part2
|   │   ├── Main.java
|   │   └── Solution.java
|   └── README.md
└── InputReader.java

In day packages the one general structure is kept.

In the input folder there always is the main input.txt file, but there could be more input samples in other files.

In part1 and part2 folders there are Main.java and Solution.java files. The Main class is always responsible for displaying the problem’s solution. In Solution class the only public method is the main method implemented to solve the problem, the other methods (if there are) are helpers.

There also provided a README file to each of the days.

If some special input is provided, in the day package can be located the InputReader.java class responsible for reading data from the input file of the certain day.

Additionally in the day package (or part of the day package, depending on problem) some helpers classes can also be found.

There is one general InputReader class, which reads simple input data and is used for many days.

Problems

Short descriptions of problems. Complete problem contents can be found in README files of day packages.

  • [day 1]
    • [part 1] - finding the two entries that sum to x and then multiply those two numbers together.
    • [part 2] - finding the three entries that sum to x and then multiply those three numbers together.
  • [day 2] - each line gives the password policy and then the password. Counting how many passwords are valid according to the policies.
    • [part 1] - the password policy indicates the lowest and highest number of times a given letter must appear for the password to be valid.
    • [part 2] - each policy describes two positions in the password, where 1 means the first character. Exactly one of these positions must contain the given letter.
  • [day 3] - having a map of the open squares (.) and trees (#). These aren't the only trees, though; the same pattern repeats to the right many times.
    • [part 1] - counting how many trees can be encountered starting at the top-left corner of the map and following a slope of right 3 and down 1.
    • [part 2] - counting how many trees can be encountered starting at the top-left corner of the map and following given slopes, and then multiplying founded results together.
  • [day 4] - having a list of passport data counting how many from them are valid.
    • [part 1] - passport is valid when all eight fields are present or when the only missing field is cid.
    • [part 2] - passport is valid when all eight fields are present or when the only missing field is cid,and each field has strict rules about what values are valid for automatic validation
  • [day 5] - decoding airplane pass. Instead of zones or groups, the airline uses binary space partitioning to seat people. A seat might be specified like FBFBBFFRLR, where F means "front", B means "back", L means "left", and R means "right".
    • [part 1] - finding the maximum pass ID from given passes.
    • [part 2] - finding the only one free pass ID from given passes (not at the very front or back).
  • [day 6] - the form asks a series of 26 yes-or-no questions marked a through z. Identifying the questions for which people from a group answered "yes".
    • [part 1] - finding a sum of group's counts of questions for which anyone in a group answered "yes".
    • [part 2] - finding a sum of group's counts of questions for which everyone in a group answered "yes".
  • [day 7] - given rules specifying the required contents of colored bags (bags must be color-coded and must contain specific quantities of other color-coded bags).
    • [part 1] - counting how many bag colors can eventually contain at least one shiny gold bag.
    • [part 2] - counting how many individual bags are required inside a single shiny gold bag.
  • [day 8] - the boot code is represented as a text file with one instruction per line of text. Each instruction consists of an operation (acc, jmp, or nop) and an argument (a signed number like +4 or -20). Program contains infinite loop.
    • [part 1] - finding what value is in the accumulator immediately before infinite loop starts.
    • [part 2] - fixing a program and finding what the value of the accumulator is after the program terminates.
  • [day 9] - XMAS (eXchange-Masking Addition System) starts by transmitting a preamble of 25 numbers. After that, each number should be the sum of any two of the 25 immediately previous numbers.
    • [part 1] - finding the first invalid number, that is number that cannot be made by sum of any two of the 25 immediately previous numbers.
    • [part 2] - finding encryption weakness, that is a sum of the smallest and largest number in a contiguous set of at least two numbers in a list which sum to the invalid number.
  • [day 10] - given a list of all of the joltage adapters in a bag. Each of joltage adapters is rated for a specific output joltage. Any given adapter can take an input 1, 2, or 3 jolts lower than its rating and still produce its rated output joltage. In addition, the device has a built-in joltage adapter rated for 3 jolts higher than the highest-rated adapter in the bag. The charging outlet has an effective joltage rating of 0.
    • [part 1] - finds the number of 1-jolt differences multiplied by the number of 3-jolt differences.
    • [part 2] - counts the total number of distinct ways of adapter arrangements.
  • [day 11] - the seat layout fits neatly on a grid. Each position is either floor (.), an empty seat (L), or an occupied seat (#). Running seats rearrangements according to required rules. Simulating the seating area by applying the seating rules repeatedly until no seats change state.
    • [part 1] - all decisions are based on the number of occupied seats adjacent to a given seat.
    • [part 2] - all decisions are based on the number of the first seats seen in each of eight directions.
  • [day 12] - the navigation instructions consists of a sequence of single-character actions paired with integer input values. Finding the Manhattan distance between the final location and the ship's starting position.
    • [part 1] - moving a ship according to provided list of actions.
    • [part 2] - moving a ship with its waypoint according to provided list of actions.
  • [day 13] - each bus has an ID number that also indicates how often the bus leaves for the airport.
    • [part 1] - having the earliest timestamp you could depart on a bus, finding the ID of the earliest bus you can take to the airport multiplied by the number of minutes you'll need to wait for that bus.
    • [part 2] - finding the earliest timestamp such that all of the listed bus IDs depart at offsets matching their positions in the list.
  • [day 14] - the bitmask is always given as a string of 36 bits, written with the most significant bit on the left and the least significant bit on the right. A bitmask act as a decoder.
    • [part 1] - the current bitmask is applied to values immediately before they are written to memory.
    • [part 2] - immediately before a value is written to memory, each bit in the bitmask modifies the corresponding bit of the destination memory address.
  • [day 15] - in the game, the players take turns saying numbers. Each turn consists of considering the most recently spoken number. Each turn results in that player speaking aloud either 0 (if the last number is new) or an age (if the last number is a repeat).
    • [part 1] - finding what number will be the 2020th number spoken.
    • [part 2] - finding what number will be the 30000000th number spoken.
  • [day 16] - the rules for ticket fields specify a list of fields that exist somewhere on the ticket and the valid ranges of values for each field. Each ticket is represented by a single line of comma-separated values.
    • [part 1] - determining which tickets are completely invalid; these are tickets that contain values which aren't valid for any field. Adding together all of the invalid values.
    • [part 2] - determining which field is which and finding a multiplication of 6 departure values.
  • [day 17]
  • [day 18] - expressions consist of addition (+), multiplication (*), and parentheses ((...)). Just like normal math, parentheses indicate that the expression inside must be evaluated before it can be used by the surrounding expression. The rules of operator precedence have changed.
    • [part 1] - the operators have the same precedence, and are evaluated left-to-right regardless of the order in which they appear.
    • [part 2] - rather than evaluating multiplication before addition, addition is evaluated before multiplication.
  • [day 19] - the rules for valid messages are numbered and build upon each other. Determining the number of messages that completely match rule 0.
    • [part 1] - there are no loops in the rules.
    • [part 2] - some of the rules do contain loops.
  • [day 20] - the camera array consists of many cameras; rather than produce a single square image, they produce many smaller square image tiles that need to be reassembled back into a single image.
    • [part 1] - multiplying together the IDs of the four corner tiles.
    • [part 2] - reassembling the original image and then removing the samples of the sea monster to determine how rough the waters are in the sea monsters' habitat.
  • [day 21] - given the list of ingredients in unknown language and the list of allergens contained by the ingredients in English.
    • [part 1] - counting the occurrences of ingredients that cannot possibly contain any of the allergens in the english list of allergens.
    • [part 2] - arranging the ingredients alphabetically by their allergen and separating them by commas to produce the canonical dangerous ingredient list.
  • [day 22]
    • [part 1] - playing a game of Combat.
    • [part 2] - playing a game of Recursive Combat.
  • [day 23] - playing a game of Crab's mixing cups.
    • [part 1] - there are only 9 cups and 100 moves.
    • [part 2] - there are 1000000 cups and 10000000 moves.
  • [day 24]
    • [part 1] - flipping hexagonal tiles.
    • [part 2] - hexagonal Game of Life.
  • [day 25]
    • [part 1] - finding the encryption key having the door's and the card's public keys.