Skip to main content


Advent of Code 2020 | Day 4 | List<String>.contains()

Difficulty is increasing as the challenge is continuing and a bit more of thinking will be needed, it's time to start! Im pretty sure theres no way to compare the passports with validity requirements without using List String or array - we need to change the spaces to newlines or any other way as well, because there's no chance of splitting() we could use.  As usual for first ' splitting ' of the String, we use our line scanner , reformatting the passport file is necessary in order to get all the values correctly, there was no order or rule of sorting, now we have it. So if the line is blank we know that the passport we were checking right now is over and we can proceed to another one. Next we check if the  list has all the required values and if it has, valids will increase, don't forget to clear() the array for next passport. At the end we can print out the result, also keep in mind that the scanner must be closed to avoid memory leaks! I actually hadn'

Advent of Code 2020 | Day 3 | char[index] = value;

 While travel by toboggan might be easy, it's certainly not safe: there's very minimal steering and the area is covered in trees. You'll need to see which angles will take you near the fewest trees.

Due to the local geology, trees in this area only grow on exact integer coordinates in a grid. You make a map (your puzzle input) of the open squares (.) and trees (#) you can see.

Looks way harder then the first 2 puzzles, finally something, that could take a bit more time...lets check it out!

As usual some variable declaration for the beginning. Position integer that is required to move the virtual 'vehicle' forward, we don't need the vertical value because it's always moving by one (for now).

To track all the results we need much larger map. (Sorry for not being creative here, yikes.)

Only thing remains is printing and saving our results, lets do this!
You can check the text file with result afterwards.

This seems to be a problem, we have never worked with more lines before.

After skipping first line we can proceed to the solution itself, what's easier than using replacement? Nothing, of course. String ->  char_array[] -> char_array[index] = final_char;

Just to be clear, we check if we skipped the first line and if the line number is even because we need to skip a line and two lines in the beginning (even in the first part you had to skip one line at the beginning). Now we can apply the same code and it should work...

..and yeah, it did...
Multiply the values and boom! You have an answer.


Popular Posts


Crypto prices