13 "['Sue 1: goldfish: 9, cars: 0, samoyeds: 9',\n",
14 " 'Sue 2: perfumes: 5, trees: 8, goldfish: 8',\n",
15 " 'Sue 3: pomeranians: 2, akitas: 1, trees: 5',\n",
16 " 'Sue 4: goldfish: 10, akitas: 2, perfumes: 9',\n",
17 " 'Sue 5: cars: 5, perfumes: 6, akitas: 9']"
22 "output_type": "execute_result"
26 "pi16 = [l.strip() for l in open('advent16.txt').readlines()]\n",
40 "{'cats': 3, 'goldfish': 6, 'pomeranians': 8}"
45 "output_type": "execute_result"
51 " ll = l.split(': ', 1)\n",
52 " n = int(ll[0].split(' ')[1])\n",
53 " items = ll[1].split(', ')\n",
54 " aunts[n] = {i.split(': ')[0].strip(): int(i.split(': ')[1]) for i in items}\n",
66 "target = {'children': 3,\n",
69 "'pomeranians': 3,\n",
86 "def possible(aunt):\n",
87 " return all(aunts[aunt][item] == target[item] for item in aunts[aunt])"
103 "execution_count": 6,
105 "output_type": "execute_result"
109 "list(aunt for aunt in aunts if possible(aunt))"
114 "execution_count": 7,
120 "def possible2(aunt):\n",
121 " possible = True\n",
122 " for item in aunts[aunt]:\n",
123 " if item == 'cats' or item == 'trees':\n",
124 " if aunts[aunt][item] <= target[item]:\n",
125 " possible = False\n",
126 " elif item == 'pomeranians' or item == 'goldfish':\n",
127 " if aunts[aunt][item] >= target[item]:\n",
128 " possible = False\n",
130 " if aunts[aunt][item] != target[item]:\n",
131 " possible = False\n",
137 "execution_count": 8,
148 "execution_count": 8,
150 "output_type": "execute_result"
159 "execution_count": 9,
170 "execution_count": 9,
172 "output_type": "execute_result"
176 "list(aunt for aunt in aunts if possible2(aunt))"
181 "execution_count": null,
191 "display_name": "Python 3",
192 "language": "python",
200 "file_extension": ".py",
201 "mimetype": "text/x-python",
203 "nbconvert_exporter": "python",
204 "pygments_lexer": "ipython3",