Skip to content

Commit a0a2880

Browse files
committed
Day 6.
1 parent c7be54b commit a0a2880

File tree

2 files changed

+2252
-0
lines changed

2 files changed

+2252
-0
lines changed

aoc2020.ipynb

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,80 @@
432432
" break"
433433
]
434434
},
435+
{
436+
"cell_type": "markdown",
437+
"metadata": {},
438+
"source": [
439+
"## Day 6\n",
440+
"\n",
441+
"Sum of count of unique answers in each group."
442+
]
443+
},
444+
{
445+
"cell_type": "code",
446+
"execution_count": 63,
447+
"metadata": {},
448+
"outputs": [
449+
{
450+
"name": "stdout",
451+
"output_type": "stream",
452+
"text": [
453+
"6703\n"
454+
]
455+
}
456+
],
457+
"source": [
458+
"import string\n",
459+
"\n",
460+
"counts = 0\n",
461+
"\n",
462+
"with open('day06-input.txt') as input_file_06:\n",
463+
" input_06 = input_file_06.read()\n",
464+
" groups = input_06.split('\\n\\n')\n",
465+
" \n",
466+
" for group in groups:\n",
467+
" i = 0\n",
468+
" for l in string.ascii_lowercase:\n",
469+
" if l in group:\n",
470+
" i = i + 1\n",
471+
" counts = counts + i\n",
472+
" \n",
473+
"print(counts)"
474+
]
475+
},
476+
{
477+
"cell_type": "markdown",
478+
"metadata": {},
479+
"source": [
480+
"Sum of count of questions in each group to which everyone answered yes."
481+
]
482+
},
483+
{
484+
"cell_type": "code",
485+
"execution_count": 66,
486+
"metadata": {},
487+
"outputs": [
488+
{
489+
"name": "stdout",
490+
"output_type": "stream",
491+
"text": [
492+
"3430\n"
493+
]
494+
}
495+
],
496+
"source": [
497+
"countt = 0\n",
498+
"\n",
499+
"for group in groups:\n",
500+
" allyes = set(string.ascii_lowercase)\n",
501+
" answers = group.split('\\n')\n",
502+
" for a in answers:\n",
503+
" allyes.intersection_update(set(a))\n",
504+
" countt = countt + len(allyes)\n",
505+
"\n",
506+
"print(countt)"
507+
]
508+
},
435509
{
436510
"cell_type": "code",
437511
"execution_count": null,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy