Skip to content

Commit c7be54b

Browse files
committed
Day 5.
1 parent e76c929 commit c7be54b

File tree

2 files changed

+874
-0
lines changed

2 files changed

+874
-0
lines changed

aoc2020.ipynb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,73 @@
365365
"print(valid)"
366366
]
367367
},
368+
{
369+
"cell_type": "markdown",
370+
"metadata": {},
371+
"source": [
372+
"## Day 5\n",
373+
"\n",
374+
"What is the highest seat ID on a boarding pass?"
375+
]
376+
},
377+
{
378+
"cell_type": "code",
379+
"execution_count": 128,
380+
"metadata": {},
381+
"outputs": [
382+
{
383+
"name": "stdout",
384+
"output_type": "stream",
385+
"text": [
386+
"813\n"
387+
]
388+
}
389+
],
390+
"source": [
391+
"seats = []\n",
392+
"\n",
393+
"# Assign seat IDs.\n",
394+
"with open('day05-input.txt') as input_file_05:\n",
395+
" for line in input_file_05:\n",
396+
" # They're just binary numbers.\n",
397+
" row_s = line[0:7]\n",
398+
" row_i = int(row_s.replace('F', '0').replace('B', '1'), base=2)\n",
399+
" col_s = line[7:10]\n",
400+
" col_i = int(col_s.replace('L', '0').replace('R', '1'), base=2)\n",
401+
" seats.append(row_i * 8 + col_i)\n",
402+
"\n",
403+
"# Find the highest seat ID.\n",
404+
"print(max(seats))"
405+
]
406+
},
407+
{
408+
"cell_type": "markdown",
409+
"metadata": {},
410+
"source": [
411+
"Find the missing seat ID."
412+
]
413+
},
414+
{
415+
"cell_type": "code",
416+
"execution_count": 137,
417+
"metadata": {},
418+
"outputs": [
419+
{
420+
"name": "stdout",
421+
"output_type": "stream",
422+
"text": [
423+
"611 613\n"
424+
]
425+
}
426+
],
427+
"source": [
428+
"seats.sort()\n",
429+
"for i in seats:\n",
430+
" if seats[i+1] > seats[i] + 1:\n",
431+
" print(seats[i], seats[i+1])\n",
432+
" break"
433+
]
434+
},
368435
{
369436
"cell_type": "code",
370437
"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