Advent of Code 2020 - Day 7

preview_player
Показать описание
We solve todays challange at the advent of code 2020. Come join and have some fun.

00:00:00 Intro
00:04:00 The struggle
00:42:50 The solution of part 1
00:45:34 Part 2
00:56:06 The solution of part 2

Git repository:

Unlock unlimited opportunities with 50% off your first month of Coursera Plus

Get on the fast track to a career in cybersecurity. In this certificate program, you'll learn in-demand skills, and get AI training from Google experts. Learn at your own pace, no degree or experience required.

Join the channel to get access to more perks:

Or visit my blog at:

Outro music: Sanaas Scylla

#aoc2020 #adventofcode #java
Рекомендации по теме
Комментарии
Автор

This one, particularly Part 2, took me a while to figure out, especially with limited time to work on it. I did use a regular expression to parse the input, you were on the right track, but you had a typo: you had "bags contains" but the input has "bags contain". Here's the regex I used:

^(?P<outer_colour>.+?) bags contain(?: (?:(?P<inner_size>\d+|no) )?(?P<inner_colour>.+?) bags?[, \.])+$

(I recently learned about the ability to name a matching group --- ?P<name> --- which makes referencing the groups a lot easier)

I used recursion to count all the bags in part 2. The trouble I had was that I kept ending up with 0 total bags, even though my debug statements were showing non-zero in-progress values. Turned out I had a starting value of 0, which doesn't help when there's multiplication involved. :facepalm:

aaronperl