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 2 | split() string

 After solving the first day of this adventure my thirst for challenges wasn't safisfied yet, it was pretty easy, but I guess it was intended to. 

Lets check todays one and see...

This might be a tiny problem for some lower level languages since they have no split() built it method, I think even c/c++ doesn't have this feature, but that means more fun for the programmer then.

Beginning of the code stays the same as on yesterdays challenge and it's kinda the same thing, because we have to work with values that are separated by a new line (and other stuff too :).
Anyways I think it would be best to use split() function since we need integers and strings that are separated with some additional stuff, not just by line. We can see some ':', ' ' and '-'.

                                And now comes the main algorithm 
You can see a loop through the char array and then a simple check for the requirements, I think I'll be able to explain it a bit better on the second part.

And a small block of code just to make all things clear, it can remind you some kind of checker ;)...
The part 2 is actually a bit different, but we can add these two lines and it's working fine. If you look closely we convert input string to char array and compare it to our character, if it suceeds then our 'goods' count arises. There's XOR operator between the conditions which means only one statement can be true, check the guide below.

By the way if you're curious about the two conditions in one statement 'trick', here's a tiny "cheat sheet" for logical operators I borrowed from

That's all for today, happy coding!


Popular Posts


Crypto prices