Advent 2017 through Day 12

This commit is contained in:
Peter Norvig 2017-12-12 14:49:56 -05:00 committed by GitHub
parent 548c1e21da
commit d76d3b42ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1917,7 +1917,7 @@
"\n",
"# [Day 12](https://adventofcode.com/2017/day/12): Digital Plumber\n",
"\n",
"First I'll parse the data, creating a dict of `{program: direct_group_of_proggrams}`:"
"First I'll parse the data, creating a dict of `{program: direct_group_of_programs}`:"
]
},
{
@ -2004,12 +2004,12 @@
"\n",
"**Part Two**\n",
"\n",
"I did almost all the work; I just need to count the unique groups. The minimum value in a group uniquely identifies it, so:"
"I did almost all the work; I just need to count the number of distinct groups. That's a set of sets, so I have to use my `Set` class (because regular `set`s are not hashable):"
]
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 56,
"metadata": {
"collapsed": false
},
@ -2020,13 +2020,13 @@
"221"
]
},
"execution_count": 53,
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len({min(G[i]) for i in G})"
"len({Set(G[i]) for i in G})"
]
}
],