Categories
Programming What I’m Up To

My solution to Advent of Code 2020’s Day 7 challenge, in Python

Welcome to another installment in my Advent of Code 2020 series, where I present my solutions to this year’s Advent of Code challenges!

In this installment, I share my Python solution to Day 7 of Advent of Code, titled Handy Haversacks.

The Day 7 challenge, part one

The challenge

Here’s the text from part one of the challenge:

You land at the regional airport in time for your next flight. In fact, it looks like you’ll even have time to grab some food: all flights are currently delayed due to issues in luggage processing.

Due to recent aviation regulations, many rules (your puzzle input) are being enforced about bags and their contents; bags must be color-coded and must contain specific quantities of other color-coded bags. Apparently, nobody responsible for these regulations considered how long they would take to enforce!

For example, consider the following rules:

light red bags contain 1 bright white bag, 2 muted yellow bags.
dark orange bags contain 3 bright white bags, 4 muted yellow bags.
bright white bags contain 1 shiny gold bag.
muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.
shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.
dark olive bags contain 3 faded blue bags, 4 dotted black bags.
vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.
faded blue bags contain no other bags.
dotted black bags contain no other bags.

These rules specify the required contents for 9 bag types. In this example, every faded blue bag is empty, every vibrant plum bag contains 11 bags (5 faded blue and 6 dotted black), and so on.

You have a shiny gold bag. If you wanted to carry it in at least one other bag, how many different bag colors would be valid for the outermost bag? (In other words: how many colors can, eventually, contain at least one shiny gold bag?)

In the above rules, the following options would be available to you:

  • bright white bag, which can hold your shiny gold bag directly.
  • muted yellow bag, which can hold your shiny gold bag directly, plus some other bags.
  • dark orange bag, which can hold bright white and muted yellow bags, either of which could then hold your shiny gold bag.
  • light red bag, which can hold bright white and muted yellow bags, either of which could then hold your shiny gold bag.

So, in this example, the number of bag colors that can eventually contain at least one shiny gold bag is 4.

How many bag colors can eventually contain at least one shiny gold bag? (The list of rules is quite long; make sure you get all of it.)

Spoiler alert!

Please be warned: If you want to try solving the challenge on your own and without any help, stop reading now! The remainder of this post will be all about my solution to both parts of the Day 7 challenge.

Importing the data

Every Advent of Code participant gets their own set of data. I copied my data and went through my usual process of bringing it into a Jupyter Notebook running a Python kernel.

This involves pasting it into a triple-quoted string and then using Python’s splitlines() method to break it up into a list of strings. The result is main_raw_input:

main_raw_input = """light plum bags contain 1 faded blue bag.
muted salmon bags contain 4 faded lavender bags, 4 posh magenta bags.
wavy gray bags contain 2 dotted teal bags.
wavy tan bags contain 2 plaid aqua bags.
wavy purple bags contain 1 drab white bag, 4 muted yellow bags, 2 wavy aqua bags.
dull fuchsia bags contain 2 bright indigo bags, 3 plaid cyan bags, 1 light gold bag.
striped plum bags contain 1 dull coral bag, 2 drab salmon bags.
mirrored gold bags contain 2 faded tan bags, 1 dull aqua bag.
dim blue bags contain 3 dotted gray bags, 2 mirrored turquoise bags.
dark olive bags contain 2 bright cyan bags.
dotted orange bags contain 2 pale lime bags.
vibrant aqua bags contain 5 posh plum bags, 5 faded tomato bags, 5 shiny tomato bags, 1 mirrored orange bag.
striped gray bags contain 5 drab tomato bags.
light beige bags contain 1 drab aqua bag, 5 striped yellow bags, 5 bright indigo bags.
dotted brown bags contain 5 dim tan bags, 1 dim violet bag, 2 dull turquoise bags, 3 dark olive bags.
dark turquoise bags contain 1 light bronze bag.
vibrant beige bags contain 3 wavy indigo bags, 5 striped gray bags.
dotted plum bags contain 2 mirrored green bags, 2 dull crimson bags, 2 drab tan bags, 1 vibrant coral bag.
dull indigo bags contain 2 vibrant gold bags, 1 dim chartreuse bag, 3 bright brown bags, 2 dim turquoise bags.
wavy olive bags contain 2 dotted indigo bags, 4 vibrant beige bags, 1 dotted gray bag.
posh olive bags contain 4 muted magenta bags, 5 dim cyan bags, 3 drab bronze bags, 2 pale lime bags.
dotted silver bags contain 3 light brown bags.
dim purple bags contain 5 clear lavender bags, 4 drab aqua bags, 1 mirrored bronze bag.
wavy green bags contain 4 plaid white bags, 3 clear cyan bags, 1 striped gray bag, 4 clear coral bags.
dark brown bags contain 4 light brown bags, 2 light magenta bags, 3 dotted gold bags.
dark aqua bags contain 1 dull coral bag, 4 shiny coral bags, 3 vibrant crimson bags, 2 muted black bags.
shiny gray bags contain 1 dark gray bag, 4 pale purple bags.
posh brown bags contain 1 posh magenta bag, 5 wavy bronze bags, 5 posh yellow bags.
clear turquoise bags contain 1 shiny tan bag, 1 muted salmon bag.
dotted teal bags contain 5 bright tan bags, 5 vibrant crimson bags.
drab coral bags contain 1 striped brown bag, 1 light lime bag, 1 faded green bag.
dull plum bags contain 5 vibrant silver bags.
bright orange bags contain 2 dark yellow bags, 4 mirrored silver bags, 4 mirrored cyan bags, 2 striped tomato bags.
drab bronze bags contain 2 drab violet bags, 2 striped bronze bags.
dim tan bags contain 1 shiny black bag, 5 posh aqua bags.
clear indigo bags contain 4 clear tan bags, 5 vibrant silver bags, 2 striped orange bags, 2 dotted lavender bags.
muted violet bags contain 4 mirrored white bags, 1 dim blue bag, 4 faded beige bags.
posh aqua bags contain 4 striped fuchsia bags, 4 pale red bags, 5 muted coral bags.
mirrored purple bags contain 5 dim beige bags, 5 shiny brown bags, 5 posh indigo bags, 3 clear turquoise bags.
vibrant orange bags contain 1 dark turquoise bag, 1 dotted olive bag, 3 dull coral bags, 3 dark chartreuse bags.
light tomato bags contain 4 mirrored lime bags, 3 pale beige bags, 4 clear magenta bags.
drab indigo bags contain 5 mirrored blue bags, 1 dull salmon bag.
bright red bags contain 3 pale gold bags, 5 dim fuchsia bags, 5 mirrored aqua bags, 4 shiny gold bags.
clear silver bags contain 3 dotted brown bags, 3 dull olive bags.
vibrant salmon bags contain 3 shiny tan bags, 4 dotted gray bags, 3 wavy violet bags, 5 light gray bags.
vibrant tan bags contain 1 wavy purple bag, 2 bright plum bags, 3 dim turquoise bags.
wavy maroon bags contain 4 striped fuchsia bags.
mirrored red bags contain 3 vibrant coral bags, 2 dotted crimson bags, 3 striped orange bags, 2 clear olive bags.
shiny tan bags contain 5 striped fuchsia bags, 4 drab chartreuse bags, 2 drab tomato bags, 5 muted crimson bags.
dull black bags contain 2 shiny teal bags.
shiny coral bags contain 4 posh blue bags, 1 dotted coral bag.
mirrored blue bags contain 4 posh chartreuse bags.
striped fuchsia bags contain 4 muted lime bags, 2 shiny crimson bags.
shiny lavender bags contain 1 vibrant yellow bag, 1 clear turquoise bag.
dark tomato bags contain 5 clear brown bags.
shiny indigo bags contain 3 pale orange bags.
posh fuchsia bags contain 2 vibrant blue bags, 5 striped black bags, 3 dim turquoise bags, 5 pale black bags.
muted plum bags contain 5 dim turquoise bags, 1 posh fuchsia bag.
posh tomato bags contain 1 faded yellow bag, 1 vibrant blue bag, 1 clear coral bag.
dotted gold bags contain 3 dull tomato bags, 5 striped tomato bags, 5 wavy purple bags.
striped lime bags contain 3 faded salmon bags, 1 plaid gold bag, 4 wavy aqua bags, 3 bright beige bags.
posh violet bags contain 5 dim purple bags.
mirrored chartreuse bags contain 1 dark bronze bag.
posh purple bags contain 4 posh fuchsia bags, 4 posh magenta bags, 2 mirrored cyan bags.
bright indigo bags contain 5 drab white bags, 1 posh tan bag.
dark indigo bags contain 1 clear tan bag, 2 wavy teal bags.
dark beige bags contain 1 bright olive bag, 5 posh purple bags.
clear crimson bags contain 4 muted black bags, 4 posh purple bags, 1 striped black bag, 5 bright black bags.
shiny green bags contain 2 dark orange bags, 2 bright silver bags, 3 dim orange bags.
plaid crimson bags contain 5 muted cyan bags, 3 striped orange bags, 4 dull lavender bags, 5 wavy magenta bags.
clear tomato bags contain 2 posh fuchsia bags, 2 dark orange bags, 3 pale black bags, 2 dull aqua bags.
vibrant gold bags contain 1 faded brown bag.
pale salmon bags contain 4 dull coral bags, 2 posh fuchsia bags, 2 plaid tan bags.
light cyan bags contain 4 plaid magenta bags.
dim teal bags contain 1 posh bronze bag, 4 mirrored green bags, 5 dull black bags, 1 clear gray bag.
plaid lime bags contain 3 wavy orange bags, 5 pale blue bags, 1 plaid gold bag.
light tan bags contain 4 faded crimson bags, 1 plaid fuchsia bag, 1 bright aqua bag, 2 dotted blue bags.
shiny brown bags contain 3 mirrored bronze bags, 3 light coral bags.
bright plum bags contain 3 posh gray bags, 3 faded brown bags, 3 plaid magenta bags.
bright beige bags contain 5 dotted coral bags.
drab tomato bags contain no other bags.
pale beige bags contain 3 drab bronze bags.
dotted aqua bags contain 5 plaid yellow bags.
striped yellow bags contain 2 dull tan bags, 2 posh violet bags, 2 pale violet bags, 2 clear lavender bags.
vibrant maroon bags contain 4 muted green bags, 1 muted cyan bag, 1 mirrored tomato bag.
plaid green bags contain 2 dotted black bags.
dotted indigo bags contain 5 mirrored tan bags, 3 dim yellow bags.
vibrant coral bags contain 3 drab blue bags, 3 striped gray bags, 1 clear plum bag, 2 faded tomato bags.
pale maroon bags contain 5 shiny black bags.
posh black bags contain 2 posh green bags, 1 posh tomato bag, 4 dim gold bags, 5 wavy olive bags.
wavy aqua bags contain 5 faded green bags, 4 pale lavender bags, 5 plaid aqua bags, 3 mirrored brown bags.
clear green bags contain 3 pale lime bags.
dim beige bags contain 4 vibrant beige bags, 3 dull aqua bags, 1 mirrored orange bag, 2 dim yellow bags.
dim chartreuse bags contain 5 dark maroon bags, 1 dark crimson bag, 5 wavy teal bags, 3 clear aqua bags.
bright turquoise bags contain 1 dim turquoise bag, 3 dull turquoise bags.
bright magenta bags contain 2 striped fuchsia bags, 5 dim brown bags.
light fuchsia bags contain 2 drab tomato bags, 5 dim chartreuse bags.
vibrant magenta bags contain 2 pale red bags, 4 dim turquoise bags, 4 drab blue bags, 3 drab aqua bags.
muted gold bags contain 3 pale gray bags, 4 dim salmon bags.
vibrant violet bags contain 4 mirrored gray bags, 2 wavy aqua bags, 3 drab tan bags.
wavy cyan bags contain 3 pale fuchsia bags, 1 mirrored tan bag, 2 dull blue bags, 2 dull cyan bags.
light silver bags contain 2 faded brown bags, 3 mirrored white bags, 5 plaid maroon bags, 3 plaid plum bags.
mirrored lavender bags contain 1 shiny tan bag, 2 dim turquoise bags, 1 shiny coral bag, 1 striped brown bag.
dull teal bags contain 2 striped purple bags, 5 dark plum bags, 5 bright purple bags, 4 light bronze bags.
light indigo bags contain no other bags.
shiny silver bags contain 2 dim maroon bags.
wavy brown bags contain 1 posh lavender bag, 2 dark bronze bags, 4 mirrored chartreuse bags.
dull lavender bags contain 3 dull cyan bags, 1 drab lavender bag.
posh gold bags contain 1 mirrored cyan bag, 5 bright salmon bags, 4 dotted orange bags.
dim yellow bags contain no other bags.
vibrant crimson bags contain 1 drab lavender bag, 4 wavy purple bags, 5 clear red bags, 4 posh gray bags.
plaid gold bags contain 4 striped fuchsia bags, 5 drab tomato bags, 3 light indigo bags, 3 mirrored bronze bags.
vibrant indigo bags contain 4 faded yellow bags, 4 clear salmon bags, 4 plaid lavender bags.
dark crimson bags contain 1 posh fuchsia bag, 2 drab silver bags, 5 shiny coral bags.
vibrant white bags contain 3 dim orange bags, 2 shiny tomato bags, 5 dark teal bags, 5 faded aqua bags.
pale chartreuse bags contain 2 dim cyan bags, 2 faded red bags, 3 light yellow bags, 4 wavy yellow bags.
drab chartreuse bags contain 2 pale black bags.
drab gray bags contain 4 posh indigo bags, 3 muted maroon bags, 5 striped teal bags, 5 striped lime bags.
dim tomato bags contain 4 plaid tan bags, 4 vibrant turquoise bags, 2 mirrored salmon bags, 2 dull magenta bags.
plaid purple bags contain 3 posh blue bags.
dark lavender bags contain 4 muted green bags, 2 dim crimson bags, 5 dull gray bags.
bright maroon bags contain 5 drab tomato bags, 4 vibrant red bags, 5 light lime bags.
striped chartreuse bags contain 5 striped black bags.
dull salmon bags contain 3 drab lime bags, 5 wavy crimson bags.
clear beige bags contain 4 dim orange bags.
light orange bags contain 1 plaid gold bag, 5 shiny coral bags.
faded red bags contain 3 bright tan bags.
wavy violet bags contain 5 plaid chartreuse bags.
dim violet bags contain 1 pale lavender bag.
posh indigo bags contain 4 muted plum bags, 1 plaid cyan bag, 2 mirrored turquoise bags, 2 light teal bags.
muted aqua bags contain 5 striped black bags, 4 wavy purple bags, 4 mirrored silver bags, 4 wavy bronze bags.
faded gold bags contain 5 wavy indigo bags, 2 dark olive bags, 5 mirrored orange bags.
bright teal bags contain 5 dotted coral bags, 4 clear lavender bags, 1 pale black bag, 5 light indigo bags.
dotted green bags contain 3 dotted brown bags, 1 mirrored chartreuse bag, 5 vibrant gray bags, 2 mirrored tan bags.
drab yellow bags contain 1 wavy maroon bag, 4 posh chartreuse bags.
dull maroon bags contain 1 dotted blue bag, 4 pale chartreuse bags, 5 drab teal bags.
clear black bags contain 3 pale magenta bags, 5 vibrant silver bags.
dull orange bags contain 4 vibrant lime bags, 4 shiny gold bags, 4 light coral bags, 4 striped brown bags.
clear violet bags contain 3 muted plum bags, 3 dim teal bags.
muted bronze bags contain 5 mirrored salmon bags, 5 dim tan bags.
plaid lavender bags contain 3 posh violet bags.
muted brown bags contain 5 striped brown bags, 5 mirrored green bags, 2 light orange bags.
clear chartreuse bags contain 2 muted lime bags.
shiny chartreuse bags contain 1 wavy coral bag, 4 light salmon bags, 5 plaid cyan bags.
clear tan bags contain 4 dotted black bags.
dull tan bags contain 1 posh maroon bag, 1 dotted coral bag.
wavy black bags contain 1 dull chartreuse bag, 3 drab plum bags.
faded fuchsia bags contain 4 mirrored violet bags, 2 dim lavender bags.
pale brown bags contain 1 dotted olive bag, 2 bright fuchsia bags.
faded green bags contain 5 dim turquoise bags, 2 mirrored blue bags, 1 mirrored tan bag, 5 mirrored silver bags.
clear brown bags contain 3 vibrant lime bags, 2 muted maroon bags, 3 dull coral bags, 3 faded plum bags.
vibrant silver bags contain 2 clear coral bags, 1 muted yellow bag, 2 drab cyan bags, 4 mirrored orange bags.
bright crimson bags contain 1 posh olive bag, 3 faded beige bags, 1 dim black bag, 1 shiny silver bag.
dim gold bags contain 2 posh beige bags, 1 dull coral bag, 1 plaid aqua bag.
drab white bags contain 1 dim yellow bag, 2 posh gray bags.
dim indigo bags contain 3 shiny brown bags, 1 drab red bag, 2 pale aqua bags, 4 plaid lime bags.
dull blue bags contain 2 pale fuchsia bags, 1 faded tomato bag, 4 plaid aqua bags.
mirrored bronze bags contain 5 bright tan bags, 2 plaid magenta bags.
vibrant turquoise bags contain 5 shiny brown bags, 2 vibrant beige bags, 2 dotted magenta bags, 3 dull lavender bags.
dull turquoise bags contain 4 clear lavender bags, 3 striped gray bags, 3 posh gray bags.
dim lavender bags contain 3 plaid lime bags, 4 mirrored red bags, 3 pale orange bags.
clear lime bags contain 3 drab fuchsia bags, 3 plaid gray bags, 1 light beige bag, 3 muted violet bags.
wavy fuchsia bags contain 3 bright gray bags, 1 faded purple bag, 4 posh purple bags, 4 light tan bags.
plaid beige bags contain 2 drab bronze bags.
faded beige bags contain 1 posh bronze bag, 3 mirrored bronze bags, 3 shiny black bags.
posh blue bags contain 3 shiny gold bags, 2 shiny black bags.
dull silver bags contain 2 wavy crimson bags, 5 faded black bags.
pale fuchsia bags contain 5 dull black bags.
bright green bags contain 3 bright black bags, 4 drab tan bags.
mirrored violet bags contain 4 pale teal bags, 3 dotted crimson bags, 2 posh violet bags, 2 shiny silver bags.
pale violet bags contain 4 posh magenta bags, 5 wavy crimson bags, 3 drab aqua bags.
faded white bags contain 1 drab purple bag, 5 shiny chartreuse bags.
faded tomato bags contain 2 bright teal bags.
faded violet bags contain 2 plaid salmon bags.
drab turquoise bags contain 1 mirrored green bag.
mirrored silver bags contain 5 dull aqua bags, 1 dark orange bag, 3 pale red bags, 4 dim yellow bags.
dotted violet bags contain 5 plaid chartreuse bags, 1 mirrored tan bag, 5 dotted lavender bags.
plaid olive bags contain 1 mirrored cyan bag, 2 muted orange bags, 2 posh maroon bags.
pale silver bags contain 3 dull lavender bags, 4 mirrored olive bags, 4 muted coral bags.
mirrored coral bags contain 1 pale fuchsia bag, 1 dull turquoise bag.
drab crimson bags contain 1 wavy purple bag, 1 wavy violet bag, 2 vibrant gold bags, 3 bright salmon bags.
dull chartreuse bags contain 4 faded salmon bags, 3 light lime bags, 1 mirrored brown bag.
bright purple bags contain 2 light cyan bags.
dull brown bags contain 3 bright white bags.
muted magenta bags contain 3 shiny gold bags, 4 muted plum bags, 5 pale lime bags, 2 light cyan bags.
pale aqua bags contain 4 drab blue bags, 1 bright lavender bag.
drab purple bags contain 2 mirrored bronze bags, 1 drab violet bag.
dotted chartreuse bags contain 2 pale chartreuse bags, 5 clear beige bags.
shiny purple bags contain 5 clear black bags.
muted blue bags contain 4 dotted indigo bags.
striped blue bags contain 4 vibrant beige bags, 3 plaid lime bags.
dull gold bags contain 4 drab violet bags, 3 pale aqua bags, 3 mirrored cyan bags.
plaid tan bags contain 5 shiny gold bags.
mirrored brown bags contain 3 pale lime bags, 2 dull coral bags.
mirrored white bags contain 5 muted black bags, 1 dark yellow bag, 4 drab blue bags, 4 clear bronze bags.
pale yellow bags contain 4 clear tomato bags, 1 drab salmon bag, 1 plaid crimson bag.
faded silver bags contain 5 dotted indigo bags, 3 posh chartreuse bags.
mirrored orange bags contain 4 drab tomato bags.
dotted lime bags contain 3 faded tomato bags, 4 vibrant beige bags, 5 posh chartreuse bags.
muted coral bags contain 1 muted plum bag.
bright tomato bags contain 1 posh red bag, 4 light red bags, 1 dotted fuchsia bag, 4 dull turquoise bags.
plaid orange bags contain 4 shiny salmon bags, 4 muted tomato bags, 4 dull gold bags, 3 clear green bags.
plaid teal bags contain 1 shiny black bag, 4 wavy purple bags, 3 dark plum bags, 4 pale silver bags.
muted tan bags contain 5 faded salmon bags, 4 dotted magenta bags, 3 clear gold bags, 3 dotted tan bags.
faded olive bags contain 1 clear lavender bag.
muted olive bags contain 4 drab coral bags, 5 light yellow bags.
posh salmon bags contain 3 dim turquoise bags, 1 vibrant purple bag, 2 bright maroon bags, 2 drab lime bags.
dim crimson bags contain 5 dull white bags, 1 dim yellow bag, 5 dark green bags.
light brown bags contain 1 drab tan bag.
light bronze bags contain 2 vibrant silver bags, 1 muted plum bag, 3 drab blue bags, 5 dull yellow bags.
faded lime bags contain 3 bright teal bags, 2 light aqua bags.
clear gold bags contain 1 dim cyan bag, 3 striped brown bags.
clear coral bags contain 4 mirrored bronze bags, 5 posh magenta bags, 5 striped purple bags.
striped cyan bags contain 1 wavy violet bag, 4 drab yellow bags.
bright coral bags contain 4 dotted lime bags, 3 striped chartreuse bags.
faded bronze bags contain 1 vibrant beige bag, 4 dotted green bags, 4 dotted gold bags, 1 shiny turquoise bag.
dark red bags contain 3 pale salmon bags, 5 bright green bags.
posh cyan bags contain 3 plaid fuchsia bags.
clear teal bags contain 5 plaid aqua bags, 1 posh tomato bag, 2 shiny olive bags, 4 shiny turquoise bags.
dotted turquoise bags contain 5 dim blue bags, 5 bright teal bags, 2 dull coral bags.
wavy silver bags contain 5 posh aqua bags.
shiny cyan bags contain 5 clear crimson bags, 4 vibrant purple bags, 3 mirrored turquoise bags, 5 plaid aqua bags.
mirrored beige bags contain 2 dim green bags, 1 dull teal bag.
plaid turquoise bags contain 1 dark yellow bag.
dim white bags contain 5 posh indigo bags, 4 bright cyan bags, 5 dim orange bags, 2 dim teal bags.
faded tan bags contain 4 dim salmon bags, 2 plaid blue bags.
faded yellow bags contain 1 posh gray bag, 4 dim beige bags.
dull tomato bags contain 2 pale indigo bags, 2 striped bronze bags, 1 wavy maroon bag, 5 posh tomato bags.
posh lavender bags contain 4 faded blue bags, 4 striped teal bags, 5 plaid chartreuse bags.
mirrored magenta bags contain 2 dim magenta bags.
drab violet bags contain 3 shiny black bags, 1 mirrored silver bag.
pale coral bags contain 5 dim gold bags.
clear red bags contain 4 muted maroon bags.
dark yellow bags contain 5 striped black bags, 2 clear plum bags.
dull coral bags contain 5 bright teal bags, 2 shiny black bags, 3 drab tomato bags, 4 dotted coral bags.
dotted bronze bags contain 3 bright black bags, 3 dull orange bags, 3 mirrored indigo bags.
dull green bags contain 4 clear teal bags, 5 muted silver bags, 2 pale blue bags, 2 light plum bags.
wavy gold bags contain 5 pale red bags, 3 dim salmon bags, 2 striped orange bags, 4 bright beige bags.
plaid aqua bags contain 4 pale black bags, 2 clear tomato bags, 1 faded beige bag.
wavy tomato bags contain 5 posh turquoise bags.
wavy white bags contain 2 dim maroon bags.
dull beige bags contain 3 wavy brown bags.
light olive bags contain 5 dim white bags, 4 dark fuchsia bags, 4 dull magenta bags, 5 light lavender bags.
mirrored lime bags contain 5 vibrant coral bags.
light black bags contain 2 dark salmon bags.
bright gold bags contain 3 dark orange bags, 5 shiny black bags, 2 bright silver bags, 3 pale black bags.
dull lime bags contain 2 posh bronze bags, 2 mirrored blue bags.
posh chartreuse bags contain 3 light lime bags, 3 bright lavender bags, 3 posh fuchsia bags.
clear orange bags contain 1 dull maroon bag, 1 faded yellow bag.
striped red bags contain 2 dotted cyan bags, 3 dull silver bags, 2 light blue bags.
pale turquoise bags contain 4 wavy silver bags, 3 dotted teal bags, 4 light green bags.
wavy crimson bags contain 1 light cyan bag, 2 posh beige bags.
light turquoise bags contain 1 dull orange bag.
dotted coral bags contain 1 drab tomato bag, 5 dim yellow bags, 5 bright lavender bags.
dotted tan bags contain 4 light coral bags, 4 dim cyan bags, 3 vibrant beige bags.
drab blue bags contain 1 dim turquoise bag.
pale white bags contain 3 clear olive bags, 2 clear coral bags, 5 dark olive bags, 2 wavy white bags.
muted orange bags contain 2 dim gold bags.
faded black bags contain 2 wavy aqua bags, 5 vibrant bronze bags, 5 mirrored blue bags.
posh lime bags contain 2 dim salmon bags, 2 pale orange bags, 4 wavy maroon bags, 1 dim coral bag.
wavy indigo bags contain 2 muted lime bags.
faded orange bags contain 1 light green bag, 5 plaid turquoise bags, 4 posh turquoise bags.
light blue bags contain 1 plaid fuchsia bag, 4 mirrored salmon bags, 1 muted chartreuse bag.
light violet bags contain 3 dotted black bags, 3 posh black bags.
posh bronze bags contain 3 striped purple bags, 5 posh purple bags, 2 plaid magenta bags, 3 dull aqua bags.
shiny fuchsia bags contain 5 dim olive bags, 2 plaid silver bags, 1 dark cyan bag, 1 pale red bag.
vibrant gray bags contain 2 drab blue bags.
faded salmon bags contain 1 drab aqua bag, 1 mirrored blue bag.
dark white bags contain 4 dim orange bags, 4 plaid magenta bags, 2 clear tomato bags.
muted indigo bags contain 4 dotted violet bags.
dull white bags contain 2 shiny cyan bags, 3 shiny orange bags.
faded plum bags contain 3 dim cyan bags, 2 dark yellow bags.
muted silver bags contain 2 drab red bags, 3 dark gray bags, 4 striped teal bags.
wavy lavender bags contain 1 drab turquoise bag.
striped beige bags contain 2 dim turquoise bags, 1 muted plum bag, 4 posh violet bags.
dark gray bags contain 3 posh fuchsia bags, 2 striped brown bags.
plaid yellow bags contain 3 vibrant red bags, 5 dark gold bags.
dark violet bags contain 2 mirrored orange bags, 2 muted crimson bags, 1 pale white bag, 1 pale chartreuse bag.
shiny maroon bags contain 4 dim tan bags.
dotted fuchsia bags contain 4 bright lime bags, 3 dotted lime bags, 2 bright maroon bags, 5 drab yellow bags.
light yellow bags contain 1 dotted coral bag, 1 bright lavender bag, 3 pale violet bags.
shiny blue bags contain 1 shiny crimson bag.
dotted black bags contain 4 muted aqua bags, 2 light lime bags, 3 posh turquoise bags, 1 light silver bag.
pale purple bags contain 2 striped violet bags, 5 clear lavender bags.
pale red bags contain 4 bright tan bags, 4 pale black bags, 4 mirrored cyan bags, 3 dotted coral bags.
dim gray bags contain 3 dull cyan bags, 3 dotted purple bags, 2 shiny brown bags, 2 plaid tan bags.
posh tan bags contain 2 light coral bags, 2 bright black bags, 2 dim yellow bags.
vibrant black bags contain 4 pale crimson bags, 2 mirrored brown bags, 4 plaid violet bags, 3 muted yellow bags.
dark salmon bags contain 2 mirrored brown bags, 5 clear salmon bags, 5 drab yellow bags.
dim green bags contain 5 pale indigo bags, 5 pale coral bags, 5 plaid lavender bags.
plaid fuchsia bags contain 2 muted maroon bags, 3 muted crimson bags, 3 dim black bags.
faded maroon bags contain 3 mirrored purple bags, 5 faded tan bags.
dark maroon bags contain 5 dull lavender bags, 4 clear plum bags, 3 shiny silver bags.
pale magenta bags contain 1 light indigo bag.
dim salmon bags contain 2 vibrant red bags, 1 light lime bag.
dotted lavender bags contain 4 drab tan bags, 1 mirrored olive bag, 5 plaid gold bags.
faded aqua bags contain 5 dim purple bags.
plaid brown bags contain 2 shiny green bags, 3 faded tomato bags, 4 wavy orange bags.
striped purple bags contain 4 posh gray bags, 1 light lime bag.
muted yellow bags contain 2 pale indigo bags, 3 vibrant blue bags, 2 muted coral bags.
dark gold bags contain 4 striped teal bags, 4 bright maroon bags.
mirrored indigo bags contain 5 dim white bags, 4 wavy white bags, 4 bright purple bags.
mirrored tomato bags contain 1 drab turquoise bag, 1 drab cyan bag, 1 dotted teal bag.
striped white bags contain 1 shiny silver bag, 1 faded gold bag.
pale plum bags contain 2 shiny brown bags, 1 posh fuchsia bag.
bright gray bags contain 4 posh chartreuse bags, 4 dull turquoise bags.
shiny olive bags contain 3 plaid yellow bags, 4 dotted fuchsia bags, 2 bright beige bags.
faded crimson bags contain 4 faded blue bags, 5 faded gray bags, 1 dotted lime bag, 1 wavy magenta bag.
striped coral bags contain 1 dull fuchsia bag, 4 striped fuchsia bags, 1 dull gold bag, 5 posh lime bags.
posh orange bags contain 4 dim yellow bags, 2 posh tan bags.
striped tan bags contain 5 vibrant coral bags, 5 posh violet bags, 4 plaid aqua bags, 4 dark crimson bags.
shiny yellow bags contain 3 dull silver bags, 3 dim purple bags, 3 vibrant violet bags.
shiny black bags contain 3 mirrored cyan bags, 1 clear gray bag, 2 light cyan bags.
posh silver bags contain 1 posh blue bag.
mirrored cyan bags contain 5 pale lime bags, 1 drab aqua bag, 4 muted lime bags.
dark plum bags contain 3 muted green bags.
clear white bags contain 5 wavy crimson bags, 3 plaid salmon bags, 4 plaid silver bags, 3 faded beige bags.
plaid plum bags contain 2 dim salmon bags, 1 faded black bag, 2 plaid purple bags, 5 dull lavender bags.
dim turquoise bags contain 2 pale indigo bags, 4 striped black bags.
vibrant green bags contain 5 clear purple bags, 4 pale brown bags, 2 drab olive bags, 3 dotted brown bags.
dark lime bags contain 4 dull blue bags, 4 wavy chartreuse bags, 1 bright olive bag.
shiny white bags contain 2 muted magenta bags, 4 clear gray bags, 1 mirrored bronze bag, 3 mirrored green bags.
dark orange bags contain 5 clear gray bags, 1 posh maroon bag, 1 vibrant blue bag.
light crimson bags contain 2 drab tomato bags, 5 bright tan bags, 5 striped gray bags.
clear yellow bags contain 2 muted salmon bags, 1 mirrored magenta bag.
plaid salmon bags contain 3 drab tan bags, 4 dark yellow bags, 5 dim yellow bags.
faded chartreuse bags contain 1 dull black bag, 5 pale lime bags, 2 wavy olive bags, 4 shiny green bags.
plaid bronze bags contain 2 vibrant maroon bags.
striped crimson bags contain 1 shiny beige bag.
clear magenta bags contain 3 muted olive bags, 4 bright olive bags, 5 pale purple bags, 3 dark aqua bags.
muted lime bags contain no other bags.
dull yellow bags contain 3 dark black bags, 1 wavy orange bag, 5 posh fuchsia bags.
shiny teal bags contain 5 posh bronze bags, 1 striped tomato bag, 2 dim gold bags, 2 posh chartreuse bags.
plaid violet bags contain 5 mirrored bronze bags, 5 shiny crimson bags, 5 vibrant blue bags.
posh coral bags contain 5 bright silver bags, 2 bright lime bags.
dim magenta bags contain 5 drab white bags, 1 faded blue bag, 1 drab red bag, 5 light brown bags.
muted turquoise bags contain 4 shiny beige bags.
posh maroon bags contain 2 light lime bags.
posh crimson bags contain 5 wavy lavender bags, 3 pale orange bags, 3 plaid magenta bags.
striped black bags contain no other bags.
drab teal bags contain 5 light olive bags, 3 clear teal bags, 2 posh magenta bags.
plaid white bags contain 1 shiny tan bag, 3 dotted lavender bags, 5 wavy olive bags, 4 clear black bags.
pale olive bags contain 4 vibrant beige bags.
shiny tomato bags contain 5 pale lavender bags, 3 muted fuchsia bags, 5 drab white bags.
dim coral bags contain 3 dotted fuchsia bags.
faded blue bags contain 4 dim maroon bags, 3 vibrant blue bags, 4 clear gray bags.
plaid maroon bags contain 3 dotted indigo bags, 1 mirrored olive bag.
mirrored teal bags contain 3 dim olive bags, 5 posh white bags, 4 faded plum bags.
mirrored olive bags contain 5 light indigo bags, 5 muted lime bags, 4 wavy indigo bags.
drab aqua bags contain 4 drab tan bags, 2 striped gray bags, 1 pale lime bag.
posh plum bags contain 5 dim magenta bags, 5 clear gray bags.
dull olive bags contain 1 clear black bag, 3 dim brown bags.
bright chartreuse bags contain 5 vibrant violet bags, 4 posh green bags, 5 pale coral bags.
dull bronze bags contain 3 dark green bags.
plaid silver bags contain 4 striped lavender bags, 3 mirrored orange bags, 5 muted coral bags.
mirrored fuchsia bags contain 1 vibrant crimson bag.
drab beige bags contain 4 light indigo bags, 1 shiny green bag.
plaid chartreuse bags contain 2 dark bronze bags, 5 drab chartreuse bags.
drab magenta bags contain 3 plaid chartreuse bags.
pale black bags contain no other bags.
dark fuchsia bags contain 1 dim yellow bag, 5 dim salmon bags.
clear gray bags contain 3 bright tan bags.
dark purple bags contain 4 plaid purple bags, 1 dark gold bag.
bright tan bags contain no other bags.
clear plum bags contain 1 posh blue bag, 4 bright teal bags.
striped brown bags contain 5 clear tomato bags, 1 dotted indigo bag, 2 clear coral bags.
drab silver bags contain 3 clear lavender bags, 3 shiny gold bags, 5 dotted coral bags, 5 wavy indigo bags.
dotted purple bags contain 2 mirrored bronze bags, 4 light red bags, 4 dim teal bags, 3 muted indigo bags.
dotted red bags contain 2 shiny brown bags, 2 dull tan bags, 3 wavy coral bags, 2 pale lime bags.
posh magenta bags contain 3 clear gray bags.
dim olive bags contain 4 muted cyan bags, 2 mirrored brown bags, 3 dim orange bags.
dotted tomato bags contain 2 bright fuchsia bags, 5 dull silver bags, 2 dim lime bags.
striped magenta bags contain 3 mirrored red bags, 1 muted magenta bag, 3 wavy white bags.
posh red bags contain 3 bright orange bags, 4 clear olive bags, 5 faded violet bags, 3 plaid coral bags.
muted crimson bags contain 5 light indigo bags.
drab fuchsia bags contain 3 shiny coral bags.
light lime bags contain 4 bright lavender bags, 2 light crimson bags, 5 vibrant blue bags.
dotted yellow bags contain 4 pale fuchsia bags.
bright lavender bags contain no other bags.
dull aqua bags contain 4 posh gray bags, 2 light indigo bags, 5 light crimson bags.
shiny aqua bags contain 2 pale orange bags, 3 drab gray bags.
drab red bags contain 5 striped tomato bags.
bright salmon bags contain 3 light indigo bags.
faded turquoise bags contain 5 clear beige bags.
shiny gold bags contain 1 mirrored bronze bag, 4 dull aqua bags, 2 dotted indigo bags, 1 light indigo bag.
clear fuchsia bags contain 5 dotted indigo bags.
dark bronze bags contain 4 shiny black bags.
dotted olive bags contain 4 bright cyan bags.
vibrant purple bags contain 3 striped gray bags.
dull purple bags contain 5 wavy orange bags, 5 faded black bags, 2 plaid violet bags, 2 vibrant lavender bags.
shiny lime bags contain 1 light purple bag.
pale cyan bags contain 3 vibrant red bags, 5 dark white bags, 4 mirrored red bags, 3 vibrant brown bags.
dark cyan bags contain 5 clear olive bags, 4 plaid purple bags, 5 striped teal bags, 3 bright magenta bags.
dim lime bags contain 3 muted tomato bags.
drab olive bags contain 1 dotted blue bag, 2 dull lavender bags.
faded gray bags contain 5 mirrored tan bags, 1 muted orange bag, 3 posh purple bags.
muted gray bags contain 5 pale white bags.
mirrored yellow bags contain 5 bright black bags, 1 plaid turquoise bag.
wavy lime bags contain 5 plaid bronze bags, 4 mirrored green bags, 5 pale lavender bags, 3 wavy tan bags.
wavy orange bags contain 3 dotted lime bags, 1 dull crimson bag, 2 mirrored turquoise bags.
dotted cyan bags contain 4 dotted lime bags, 2 striped teal bags.
light green bags contain 3 muted indigo bags, 3 pale fuchsia bags.
drab cyan bags contain 3 posh bronze bags, 5 drab white bags, 3 drab tomato bags, 1 light indigo bag.
faded brown bags contain 3 bright tan bags, 4 striped gray bags, 5 drab cyan bags, 3 mirrored tan bags.
light purple bags contain 3 pale aqua bags, 1 dim olive bag, 2 dim tan bags.
vibrant lavender bags contain 2 faded lavender bags.
vibrant brown bags contain 4 striped black bags, 1 faded yellow bag.
dull crimson bags contain 2 mirrored white bags, 2 clear tomato bags.
drab green bags contain 2 drab beige bags, 1 vibrant crimson bag, 2 vibrant purple bags, 1 faded black bag.
shiny bronze bags contain 3 dark fuchsia bags, 3 dark bronze bags, 2 striped brown bags, 4 shiny brown bags.
plaid blue bags contain 5 faded green bags.
light white bags contain 3 wavy brown bags, 3 dark violet bags, 2 muted coral bags, 5 plaid chartreuse bags.
bright violet bags contain 1 faded violet bag, 2 muted maroon bags, 3 posh gray bags, 2 dark salmon bags.
striped turquoise bags contain 5 bright salmon bags, 1 bright lavender bag, 1 wavy maroon bag, 4 light turquoise bags.
clear cyan bags contain 5 posh magenta bags, 4 striped plum bags, 5 light turquoise bags.
bright silver bags contain 4 dotted indigo bags, 1 drab tomato bag, 1 muted salmon bag.
mirrored plum bags contain 5 bright white bags, 1 vibrant brown bag.
mirrored aqua bags contain 5 drab bronze bags, 3 mirrored salmon bags, 3 posh lavender bags, 3 bright crimson bags.
muted lavender bags contain 4 posh bronze bags, 3 striped lime bags, 5 striped chartreuse bags, 5 plaid plum bags.
dim orange bags contain 3 muted magenta bags, 2 pale magenta bags.
faded teal bags contain 5 wavy coral bags, 3 posh blue bags.
dotted magenta bags contain 5 faded purple bags, 5 posh fuchsia bags, 1 drab white bag.
drab brown bags contain 4 light red bags, 4 muted chartreuse bags.
striped indigo bags contain 3 light maroon bags, 2 pale gray bags, 2 faded magenta bags, 1 vibrant teal bag.
dull gray bags contain 3 clear olive bags.
clear blue bags contain 2 clear tomato bags, 4 faded purple bags, 1 wavy lavender bag.
posh green bags contain 5 clear aqua bags, 4 bright orange bags, 2 bright cyan bags, 4 dim fuchsia bags.
muted fuchsia bags contain 5 dull lavender bags, 2 drab violet bags, 4 dotted magenta bags, 2 wavy yellow bags.
posh turquoise bags contain 2 dotted lavender bags.
bright blue bags contain 1 pale lavender bag, 5 dark yellow bags, 5 bright beige bags.
bright bronze bags contain 2 bright gold bags, 4 shiny turquoise bags.
muted chartreuse bags contain 1 vibrant tomato bag, 1 bright lavender bag, 1 vibrant blue bag, 1 dim black bag.
dim bronze bags contain 2 light lavender bags, 2 striped plum bags, 3 dotted gold bags.
pale crimson bags contain 5 dotted lavender bags, 2 clear crimson bags, 4 bright lime bags.
clear bronze bags contain 2 drab tomato bags, 3 vibrant red bags.
pale lime bags contain 4 pale indigo bags, 3 striped black bags.
light red bags contain 4 bright salmon bags, 1 bright gold bag.
pale orange bags contain 5 drab blue bags.
shiny crimson bags contain 3 light crimson bags.
dotted beige bags contain 5 bright turquoise bags, 3 dotted turquoise bags, 4 muted green bags, 4 light black bags.
light gray bags contain 4 faded green bags, 5 wavy gold bags, 4 dim olive bags.
light coral bags contain 2 muted plum bags.
light magenta bags contain 1 dim maroon bag, 5 clear chartreuse bags, 1 vibrant lavender bag, 2 plaid beige bags.
striped violet bags contain 1 vibrant beige bag.
bright aqua bags contain 1 dark crimson bag, 4 dark bronze bags.
dotted maroon bags contain 5 light silver bags, 5 dark maroon bags.
drab plum bags contain 1 dotted yellow bag, 1 bright green bag, 4 vibrant brown bags.
posh gray bags contain 2 light crimson bags.
dotted blue bags contain 2 posh tan bags.
vibrant olive bags contain 3 faded yellow bags.
posh white bags contain 1 faded tomato bag, 2 dim violet bags.
drab lavender bags contain 3 light brown bags.
dark blue bags contain 5 vibrant lavender bags, 4 posh plum bags, 5 pale violet bags, 1 pale beige bag.
muted beige bags contain 1 striped lime bag, 2 clear purple bags, 1 vibrant brown bag, 2 mirrored bronze bags.
dim maroon bags contain 5 dim beige bags, 1 dull coral bag.
wavy teal bags contain 1 drab yellow bag, 2 muted magenta bags, 4 wavy gold bags, 2 vibrant cyan bags.
shiny salmon bags contain 2 light red bags, 3 bright fuchsia bags.
light salmon bags contain 3 vibrant purple bags, 3 drab blue bags, 3 faded black bags, 2 bright white bags.
shiny magenta bags contain 5 light fuchsia bags, 3 drab indigo bags, 3 mirrored yellow bags, 4 dim purple bags.
plaid black bags contain 3 light bronze bags, 4 mirrored tan bags, 4 muted lime bags, 5 mirrored white bags.
wavy red bags contain 4 clear lavender bags, 4 dull chartreuse bags.
posh beige bags contain 4 wavy maroon bags, 4 clear plum bags.
wavy bronze bags contain 1 wavy purple bag.
dotted gray bags contain 3 striped black bags, 1 wavy maroon bag, 5 pale indigo bags.
bright white bags contain 3 pale indigo bags, 2 drab white bags.
mirrored black bags contain 2 striped plum bags, 5 wavy brown bags, 1 wavy crimson bag.
light gold bags contain 3 posh plum bags, 1 vibrant crimson bag.
bright fuchsia bags contain 3 light cyan bags, 1 drab turquoise bag, 3 dim orange bags, 1 dull chartreuse bag.
striped gold bags contain 3 muted violet bags, 2 clear teal bags, 2 posh brown bags, 3 dim tan bags.
striped orange bags contain 1 pale fuchsia bag.
drab gold bags contain 4 shiny teal bags, 5 muted aqua bags, 3 wavy lavender bags.
light chartreuse bags contain 2 bright gold bags, 5 striped turquoise bags, 5 light gray bags, 3 wavy aqua bags.
vibrant chartreuse bags contain 2 dotted yellow bags, 5 bright fuchsia bags, 1 striped chartreuse bag, 1 dim salmon bag.
pale indigo bags contain no other bags.
drab lime bags contain 2 mirrored turquoise bags.
vibrant plum bags contain 3 dotted turquoise bags.
pale teal bags contain 5 striped lime bags, 3 faded salmon bags, 4 bright indigo bags.
dark tan bags contain 2 drab lavender bags.
faded lavender bags contain 1 vibrant blue bag.
drab orange bags contain 1 muted turquoise bag, 3 pale indigo bags.
dim fuchsia bags contain 1 drab silver bag.
vibrant lime bags contain 1 posh purple bag, 3 light coral bags, 3 light lime bags, 4 light indigo bags.
clear salmon bags contain 2 light indigo bags, 2 striped plum bags.
dark black bags contain 2 striped fuchsia bags, 4 wavy white bags, 2 wavy maroon bags.
muted white bags contain 2 pale indigo bags, 5 light plum bags.
pale gray bags contain 4 light yellow bags, 2 striped olive bags, 4 clear black bags.
dull cyan bags contain 2 vibrant red bags, 3 drab tan bags.
striped silver bags contain 3 mirrored green bags, 2 wavy purple bags, 3 posh aqua bags.
wavy magenta bags contain 4 dim purple bags, 2 dark aqua bags.
drab black bags contain 2 light plum bags.
drab maroon bags contain 2 vibrant lime bags, 4 dull purple bags, 2 mirrored salmon bags, 3 vibrant aqua bags.
shiny orange bags contain 5 wavy coral bags, 1 pale violet bag.
plaid coral bags contain 2 mirrored cyan bags.
plaid cyan bags contain 4 pale indigo bags.
dotted crimson bags contain 2 dim teal bags.
mirrored tan bags contain 1 pale red bag, 1 light cyan bag, 1 clear gray bag, 3 striped gray bags.
light maroon bags contain 2 vibrant bronze bags.
bright brown bags contain 2 wavy yellow bags.
muted tomato bags contain 5 clear gold bags, 5 plaid coral bags.
dotted white bags contain 4 dotted purple bags, 1 posh chartreuse bag, 5 dark gold bags, 1 vibrant gold bag.
muted red bags contain 4 clear crimson bags, 4 posh magenta bags, 3 plaid cyan bags, 5 pale crimson bags.
wavy yellow bags contain 3 muted magenta bags.
muted purple bags contain 1 dull chartreuse bag.
striped olive bags contain 5 faded tomato bags.
light aqua bags contain 1 vibrant tomato bag, 4 posh lavender bags.
vibrant blue bags contain 2 muted lime bags.
pale lavender bags contain 4 shiny coral bags, 5 muted crimson bags.
mirrored turquoise bags contain 5 posh blue bags.
pale gold bags contain 3 plaid chartreuse bags, 2 pale red bags, 5 clear aqua bags.
wavy salmon bags contain 4 dotted yellow bags.
shiny beige bags contain 1 bright magenta bag, 1 muted fuchsia bag.
striped bronze bags contain 5 bright turquoise bags, 5 dull black bags.
dark magenta bags contain 5 drab lime bags.
dark coral bags contain 3 plaid bronze bags, 3 posh green bags, 4 muted violet bags, 3 plaid purple bags.
mirrored green bags contain 4 posh purple bags, 2 dotted blue bags, 1 dull turquoise bag, 2 plaid purple bags.
striped tomato bags contain 5 drab white bags.
muted teal bags contain 5 shiny lime bags.
vibrant bronze bags contain 3 shiny gold bags, 5 striped fuchsia bags, 5 mirrored orange bags, 2 bright green bags.
clear olive bags contain 3 posh violet bags, 1 bright beige bag.
clear maroon bags contain 1 vibrant lime bag, 2 muted coral bags.
faded coral bags contain 4 dim beige bags, 4 bright magenta bags, 3 vibrant magenta bags, 1 bright silver bag.
pale bronze bags contain 1 dark teal bag, 4 dotted aqua bags.
striped aqua bags contain 3 faded aqua bags.
vibrant cyan bags contain 2 mirrored blue bags, 4 striped black bags, 4 clear black bags.
wavy coral bags contain 4 drab salmon bags, 3 light orange bags, 3 posh aqua bags.
mirrored salmon bags contain 4 pale lime bags.
plaid magenta bags contain 1 dim yellow bag, 1 light indigo bag.
dim brown bags contain 3 vibrant purple bags, 2 striped gray bags, 4 mirrored salmon bags, 2 muted maroon bags.
dull magenta bags contain 1 mirrored green bag, 4 dull coral bags.
dark silver bags contain 5 dotted gray bags.
pale tomato bags contain 1 vibrant blue bag, 4 shiny green bags.
plaid tomato bags contain 4 mirrored chartreuse bags, 1 plaid white bag, 4 wavy magenta bags.
faded magenta bags contain 4 dull yellow bags, 3 wavy silver bags.
mirrored crimson bags contain 3 muted tan bags, 5 posh beige bags.
muted green bags contain 4 dim black bags.
wavy chartreuse bags contain 1 plaid tan bag, 5 bright tan bags, 2 posh beige bags.
wavy plum bags contain 2 clear purple bags, 5 dotted violet bags.
plaid indigo bags contain 1 dull brown bag, 3 clear chartreuse bags, 5 posh gold bags, 1 pale teal bag.
posh teal bags contain 3 light magenta bags, 3 muted white bags, 3 dim blue bags.
striped salmon bags contain 4 shiny coral bags.
pale green bags contain 4 dark gold bags, 4 striped teal bags.
vibrant yellow bags contain 4 faded salmon bags, 1 drab beige bag, 1 muted black bag, 5 clear lavender bags.
dim cyan bags contain 2 mirrored turquoise bags.
wavy turquoise bags contain 4 dark turquoise bags, 3 bright tan bags, 4 muted tomato bags.
bright cyan bags contain 5 wavy indigo bags.
plaid red bags contain 1 mirrored coral bag, 2 dull plum bags, 4 vibrant coral bags, 4 vibrant lavender bags.
dark chartreuse bags contain 5 mirrored salmon bags, 5 posh salmon bags, 2 faded turquoise bags.
plaid gray bags contain 1 dim gold bag, 4 faded olive bags.
vibrant tomato bags contain 5 wavy maroon bags, 1 pale red bag.
faded purple bags contain 1 faded tomato bag, 1 striped black bag, 5 vibrant purple bags.
dotted salmon bags contain 3 bright gold bags, 5 dull gray bags, 3 dim blue bags.
drab salmon bags contain 3 mirrored green bags, 1 mirrored tan bag.
pale blue bags contain 4 dotted fuchsia bags.
faded cyan bags contain 2 striped orange bags, 1 vibrant gold bag, 2 bright orange bags, 1 muted gray bag.
dull red bags contain 2 drab teal bags, 2 light bronze bags.
wavy beige bags contain 1 plaid tan bag, 5 dotted indigo bags, 2 dotted gold bags.
dim red bags contain 5 pale magenta bags.
dark green bags contain 5 muted cyan bags, 3 faded brown bags.
muted cyan bags contain 3 drab tomato bags, 4 drab white bags.
mirrored maroon bags contain 5 wavy tomato bags, 2 vibrant white bags.
faded indigo bags contain 5 dim olive bags, 5 drab tan bags, 3 light orange bags.
light lavender bags contain 1 faded salmon bag, 5 pale lime bags, 4 dark maroon bags.
dim aqua bags contain 4 faded gold bags, 1 striped fuchsia bag.
shiny violet bags contain 1 pale yellow bag, 4 mirrored aqua bags.
wavy blue bags contain 1 dim fuchsia bag, 3 clear gold bags, 1 faded aqua bag, 1 light red bag.
striped teal bags contain 3 mirrored silver bags.
striped green bags contain 1 muted teal bag.
vibrant teal bags contain 3 muted indigo bags.
shiny turquoise bags contain 3 dull chartreuse bags.
bright lime bags contain 5 bright magenta bags, 1 dull orange bag.
shiny red bags contain 4 drab tan bags, 4 posh turquoise bags.
dull violet bags contain 4 shiny silver bags, 3 striped crimson bags, 1 mirrored plum bag.
dim black bags contain 1 posh magenta bag, 3 mirrored turquoise bags, 2 faded tomato bags, 4 dim turquoise bags.
muted maroon bags contain 2 mirrored tan bags, 3 clear coral bags.
posh yellow bags contain 1 bright tan bag, 5 mirrored bronze bags.
clear purple bags contain 5 shiny black bags.
dim silver bags contain 4 clear brown bags.
bright black bags contain 4 posh fuchsia bags.
shiny plum bags contain 1 mirrored cyan bag.
striped lavender bags contain 3 pale lavender bags, 4 muted cyan bags.
drab tan bags contain no other bags.
bright olive bags contain 3 muted coral bags.
dim plum bags contain 3 drab tan bags, 5 pale indigo bags.
light teal bags contain 2 dotted blue bags, 5 muted salmon bags, 2 bright purple bags.
clear lavender bags contain 2 muted lime bags, 5 plaid magenta bags, 3 pale lime bags, 1 drab aqua bag.
muted black bags contain 3 light crimson bags, 4 mirrored blue bags.
clear aqua bags contain 5 plaid gold bags.
dark teal bags contain 1 bright purple bag, 1 dotted coral bag, 5 plaid aqua bags, 5 posh maroon bags.
mirrored gray bags contain 3 dim turquoise bags, 4 bright black bags, 1 drab lavender bag.
vibrant fuchsia bags contain 1 vibrant magenta bag.
bright yellow bags contain 1 mirrored cyan bag, 1 clear olive bag.
vibrant red bags contain 1 dotted indigo bag, 2 faded beige bags, 1 drab tomato bag.
striped maroon bags contain 3 plaid aqua bags, 2 dim maroon bags, 4 plaid chartreuse bags.
pale tan bags contain 5 posh gray bags, 3 wavy violet bags."""

main_raw_input = main_raw_input.splitlines()

Creating the data structure

I feel that I can never stress this enough: A key part of coming up with solutions to Advent of Code challenges is to come up with good structures for the input data.

Here’s my function that takes the initial, somewhat-massaged input data, currently living in main_raw_input, and turns it into a data structure that I could do some problem-solving with:

import re

def create_data_structure(initial_data):
    result = {}
    
    for item in initial_data:
        bag_and_contents_regex = r"^(\w+ \w+) bags contain (.*)"
        bag_and_contents = re.search(bag_and_contents_regex, item)
        bag_type = bag_and_contents[1]
        
        contents_string = bag_and_contents[2][:-1] # [:-1] removes trailing period
        contents_regex = r"([0-9] )*(\w+ \w+) bag"
        contents_tuples = re.findall(contents_regex, contents_string)
        
        bag_contents = []
        for contents_tuple in contents_tuples:
            if contents_tuple[1] != "no other":
                bag_contents.append({
                    "count": int(contents_tuple[0]),
                    "type": contents_tuple[1]
                })
                
        result[bag_type] = bag_contents
        
    return result

The create_data_structure() function creates a table that makes it easy to look up a given bag and see what bags it contains.

It takes each line in the input, which follows this general form:

[adjective and color] bags contain [one or more of
([number][adjective and color]bag(s)).

It first makes use of this regular expression…

^(\w+ \w+) bags contain (.*)

…to separate the line into two parts:

  • The containing bag, which is captured by the (\w+ \w+) group, and
  • The contained bag(s), which are captured by the (.*) group.

The contained bag(s) are further parsed using this regular expression…

([0-9] )*(\w+ \w+) bag

…to create a list of tuples of the form:

(number, adjective_and_color)

Here’s how I used create_data_structure() to create the data structure:

bags = create_data_structure(main_raw_input)

Here’s a sample of the what the structure looked like for my data:

{
    "light plum":[
        {
            "count":1,
            "type":"faded blue"
        }
    ],
    "muted salmon":[
        {
            "count":4,
            "type":"faded lavender"
        },
        {
            "count":4,
            "type":"posh magenta"
        }
    ],
    "wavy gray":[
        {
            "count":2,
            "type":"dotted teal"
        }
    ],
    "wavy tan":[
        {
            "count":2,
            "type":"plaid aqua"
        }
    ],
    "wavy purple":[
        {
            "count":1,
            "type":"drab white"
        },
        {
            "count":4,
            "type":"muted yellow"
        },
        {
            "count":2,
            "type":"wavy aqua"
        }
    ],
    "dull fuchsia":[
        {
            "count":2,
            "type":"bright indigo"
        },
        {
            "count":3,
            "type":"plaid cyan"
        },
        {
            "count":1,
            "type":"light gold"
        }
    ]

# ... and the rest of it is here ...

}

With the data structure built, it was now possible to write a function to determine how many shiny gold bags a given bag would contain:

def shiny_gold_bag_count(bag_collection, bag_name):
    count = 0
    bag = bag_collection[bag_name]
    
    if len(bag) == 0:
        return count
    else:
        for sub_bag in bag:
            if sub_bag["type"] == "shiny gold":
                count += 1
            count += shiny_gold_bag_count(bag_collection, sub_bag["type"])
        
    return count

It’s the return of our friend:

This function checks the contents of the given bag. If there are bags in the given bag, it checks the contents of those bags and counts the shiny gold ones. If there are bags in those bags, it checks the contents of those bags and counts the shiny gold ones. And so on…

Now that I had the shiny_gold_bag_count() function, I could write another function — bags_containing_at_least_one_shiny_gold_bag() — that would apply the shiny_gold_bag_count() function to all the bags in the collection, giving me the answer to the part one:

def bags_containing_at_least_one_shiny_gold_bag(bag_collection):
    count = 0
    
    for bag_name in bag_collection.keys():
        if shiny_gold_bag_count(bag_collection, bag_name) > 0:
            print(f"{bag_name} bags contain at least one shiny gold bag!")
            count += 1

    return count

In my case, the count was 326.

The Day 7 challenge, part two

Creative Commons photo by “Sunnya343”. Tap to view the source.

The challenge

Here’s the text of part two:

It’s getting pretty expensive to fly these days – not because of ticket prices, but because of the ridiculous number of bags you need to buy!

Consider again your shiny gold bag and the rules from the above example:

  • faded blue bags contain 0 other bags.
  • dotted black bags contain 0 other bags.
  • vibrant plum bags contain 11 other bags: 5 faded blue bags and 6 dotted black bags.
  • dark olive bags contain 7 other bags: 3 faded blue bags and 4 dotted black bags.

So, a single shiny gold bag must contain 1 dark olive bag (and the 7 bags within it) plus 2 vibrant plum bags (and the 11 bags within each of those): 1 + 1*7 + 2 + 2*11 = 32 bags!

Of course, the actual rules have a small chance of going several levels deeper than this example; be sure to count all of the bags, even if the nesting becomes topologically impractical!

Here’s another example:

shiny gold bags contain 2 dark red bags.
dark red bags contain 2 dark orange bags.
dark orange bags contain 2 dark yellow bags.
dark yellow bags contain 2 dark green bags.
dark green bags contain 2 dark blue bags.
dark blue bags contain 2 dark violet bags.
dark violet bags contain no other bags.

In this example, a single shiny gold bag must contain 126 other bags.

How many individual bags are required inside your single shiny gold bag?

My solution was the following function:

def bag_count(bag_collection, bag_name):
    count = 0
    top_level_bag = bag_collection[bag_name]
    print(f"Currently counting bags inside {bag_name}.")
    
    if len(top_level_bag) == 0:
        return count
    else:
        for current_bag in top_level_bag:
            print(f"There are {current_bag['count']} of {current_bag['type']} inside {bag_name}.")
            # Add the number of bags of the current type
            # to the count.
            current_bag_type_count = current_bag['count']
            count += current_bag_type_count
            # Count the bags inside each bag of the current type,
            # multiply it by the number of the current type,
            # then add it to the count.
            bags_inside_current_bag_type_count = bag_count(bag_collection, current_bag["type"])
            count += bags_inside_current_bag_type_count * current_bag_type_count
        
    return count

Once again, my solution was a recursive one. This function checks the contents of the given bag. If there are bags in the given bag, it counts them and then checks their contents. If there are bags in those bags, it counts them and checks their contents. And so on…

Getting the solution was a matter of calling the function:

bag_count(bags, "shiny gold")

And for my data, the answer was 5635.

Solutions for previous days in Advent of Code 2020

Leave a Reply

Your email address will not be published. Required fields are marked *