Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Advent of Code 2020 Help

Hi there!

I'm currently working through day 2 of the 2020 advent of code using Python. In the Beginning Python track, I've completed the Python Basics through Introducing Dictionaries courses, but I still don't feel like I have enough knowledge to solve this puzzle. I have found some folks who have posted their solutions online, but I want to make sure I've taken the courses I need to solve this myself. Any suggestions of additional courses I should take?

Here is the question being asked. For each question, we're given a custom data set to solve for:

Your flight departs in a few days from the coastal airport; the easiest way down to the coast from here is via toboggan.

The shopkeeper at the North Pole Toboggan Rental Shop is having a bad day. "Something's wrong with our computers; we can't log in!" You ask if you can take a look.

Their password database seems to be a little corrupted: some of the passwords wouldn't have been allowed by the Official Toboggan Corporate Policy that was in effect when they were chosen.

To try to debug the problem, they have created a list (your puzzle input) of passwords (according to the corrupted database) and the corporate policy when that password was set.

For example, suppose you have the following list:

1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc

Each line gives the password policy and then the password. The password policy indicates the lowest and highest number of times a given letter must appear for the password to be valid. For example, 1-3 a means that the password must contain a at least 1 time and at most 3 times.

In the above example, 2 passwords are valid. The middle password, cdefg, is not; it contains no instances of b, but needs at least 1. The first and third passwords are valid: they contain one a or nine c, both within the limits of their respective policies.

How many passwords are valid according to their policies?

The data set we received does look like this, but just with a lot more lines:

1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc

Thank you!!

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Hey Taylor Balding, Good for you to work through the www.adventofcode.com challenges. (I've done all 300 days!)

In the case of y2020 day02, you basically, need to parse a string into characters, count them, and see if it meets the spec.

I like to use regex when parsing the input lines, but cleaver split() usage may work. There is a regex course.

The rest is just brute force string manipulation. One shortcut is to use the Collecctions module. The Counter is especially useful.

Post back if you wish more specific details. Always happy to discuss AOC! Good luck!!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

I should add, courses here won't necessarily teach you how to solve these problems. The planning out of a solution is mostly a thought experiment of how to go about breaking the problem down and solving each part.

The courses here, being language-based, teach you how to implement your solution. The key takeaway is the algorithm or process used, not the specific implementation. Knowing the process, you can translate to any implementation language.

That said, you may find the courses on Algorithms and Algorithms: Sorting and Searching helpful. There will be AOC problems where Dijkstra's Algorithm for optimized search (an advanced topic not on Treehouse) will definitely come in handy.

A new area I'm exploring is using a linear array to implement a stack instead of using recursion. (ignore this if not understood).

There is always more to learn! Keep at it!! Good luck!!

Thank you so much Chris Freeman !!! It's been a while since I've been in this kind of learning environment, so I feel like part of the issue is just getting my brain to get back into that mode of thinking about problems, haha. Thanks so much for the recommendations, I'm going to check them out! :)