Not everything done
This commit is contained in:
commit
2773df212e
16 changed files with 8761 additions and 0 deletions
93
aoc1.ipynb
Normal file
93
aoc1.ipynb
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "335e32f0-2c5a-4f77-84dd-66c2266e6312",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Part 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"id": "42055a53-b495-4615-bdb4-eaddd9380e92",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"72602"
|
||||
]
|
||||
},
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc1_input.txt\", \"r\") as f:\n",
|
||||
" elves_raw = f.read().split(\"\\n\\n\")\n",
|
||||
" elves = map(lambda x: sum(map(int, x.split(\"\\n\"))), elves_raw)\n",
|
||||
" most_calories = max(elves)\n",
|
||||
"\n",
|
||||
"most_calories"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4523a59c-06bb-4214-a9ce-143885257bb4",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Part 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"id": "614216a4-bbe9-40e9-a4b1-108e85946186",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"207410"
|
||||
]
|
||||
},
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc1_input.txt\", \"r\") as f:\n",
|
||||
" elves_raw = f.read().split(\"\\n\\n\")\n",
|
||||
" elves = map(lambda x: sum(map(int, x.split(\"\\n\"))), elves_raw)\n",
|
||||
" top_3_calories = sum(sorted(elves)[-3:])\n",
|
||||
"\n",
|
||||
"top_3_calories"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
2237
aoc1_input.txt
Normal file
2237
aoc1_input.txt
Normal file
File diff suppressed because it is too large
Load diff
149
aoc2.ipynb
Normal file
149
aoc2.ipynb
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "6da7f724-829d-4ce7-ba59-42ac322d072b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Part 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "6b0efa14-33f7-48fe-bed9-1079fdaca7b5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"score_from_shape = {\n",
|
||||
" \"X\": 1, # Rock\n",
|
||||
" \"Y\": 2, # Paper\n",
|
||||
" \"Z\": 3, # Scissors\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"id": "b9d1cb75-2a68-4593-8967-b757dbf28ff3",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"13446"
|
||||
]
|
||||
},
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc2_input.txt\") as f:\n",
|
||||
" score = 0\n",
|
||||
" for game in f:\n",
|
||||
" score += score_from_shape[game.split()[1]]\n",
|
||||
" match game.strip():\n",
|
||||
" case \"A Y\" | \"B Z\" | \"C X\":\n",
|
||||
" score += 6\n",
|
||||
" case \"A X\" | \"B Y\" | \"C Z\":\n",
|
||||
" score += 3\n",
|
||||
" case _:\n",
|
||||
" score += 0\n",
|
||||
" \n",
|
||||
"score"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "910b30ba-03e9-41cb-af02-281623ef50ce",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Part 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"id": "4893b160-0d7e-4833-b629-99f54ba07abf",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"highest_loose = {\n",
|
||||
" \"A\": 3, # Rock -> Scissors\n",
|
||||
" \"B\": 1, # Paper -> Rock\n",
|
||||
" \"C\": 2, # Scissors -> Paper\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"opponent_matching = {\n",
|
||||
" \"A\": 1, # Rock\n",
|
||||
" \"B\": 2, # Paper\n",
|
||||
" \"C\": 3, # Scissors\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"highest_win = {\n",
|
||||
" \"A\": 2, # Rock -> Paper\n",
|
||||
" \"B\": 3, # Paper -> Scissors\n",
|
||||
" \"C\": 1, # Scissors -> Rock\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"id": "cb35d20f-987e-4d40-86bc-38e5504eb7ae",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"13509"
|
||||
]
|
||||
},
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc2_input.txt\") as f:\n",
|
||||
" score = 0\n",
|
||||
" for game in f:\n",
|
||||
" opponent, strategy = game.split()\n",
|
||||
" match strategy:\n",
|
||||
" case \"X\":\n",
|
||||
" score += 0 + highest_loose[opponent]\n",
|
||||
" case \"Y\":\n",
|
||||
" score += 3 + opponent_matching[opponent]\n",
|
||||
" case \"Z\":\n",
|
||||
" score += 6 + highest_win[opponent]\n",
|
||||
" case _:\n",
|
||||
" score += 0\n",
|
||||
" \n",
|
||||
"score"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
2500
aoc2_input.txt
Normal file
2500
aoc2_input.txt
Normal file
File diff suppressed because it is too large
Load diff
117
aoc3.ipynb
Normal file
117
aoc3.ipynb
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "297093bf-b2ad-4645-935b-b2adea775c55",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Part 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "129613b8-f732-4f41-a745-edf2c979b213",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def item_priority(item: str) -> int:\n",
|
||||
" if item.isupper():\n",
|
||||
" return ord(item) - 38\n",
|
||||
" else:\n",
|
||||
" return ord(item) - 96\n",
|
||||
"\n",
|
||||
"def string_halves(string: str) -> [str, str]:\n",
|
||||
" length = int(len(string) / 2)\n",
|
||||
" first_part = string[:length]\n",
|
||||
" second_part = string[length:]\n",
|
||||
" return first_part, second_part"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"id": "069cad24-9cd2-4d1a-bfa5-f265fa578909",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"7795"
|
||||
]
|
||||
},
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc3_input.txt\", \"r\") as f:\n",
|
||||
" sum_priority = 0\n",
|
||||
" for rucksack in f:\n",
|
||||
" comp1, comp2 = map(set, string_halves(rucksack.strip()))\n",
|
||||
" intrsct = comp1.intersection(comp2)\n",
|
||||
" sum_priority += sum(map(item_priority, intrsct))\n",
|
||||
"\n",
|
||||
"sum_priority"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "86d642f4-2504-42c0-a703-2dc063810a2c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Part 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"id": "921090d1-2d2b-4161-aad2-23af1b358645",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"2703"
|
||||
]
|
||||
},
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc3_input.txt\", \"r\") as f:\n",
|
||||
" sum_badge_priority = 0\n",
|
||||
" for r1 in f:\n",
|
||||
" r1 = set(r1.strip())\n",
|
||||
" r2, r3 = set(next(f).strip()), set(next(f).strip())\n",
|
||||
" sum_badge_priority += sum(map(item_priority, r1.intersection(r2).intersection(r3)))\n",
|
||||
"\n",
|
||||
"sum_badge_priority"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
300
aoc3_input.txt
Normal file
300
aoc3_input.txt
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
vJrrdQlGBQWPTBTF
|
||||
fcpTMnMqMfTnZpgMfPbFBWzHPpBPzbCPPH
|
||||
mcVMfcsqZgmgVcmfgcmZmqZNJhrlrdhNhDdrRRJSvDTRhJlD
|
||||
pMFRmLwHMbRPmMbPPddvqqrrNSTFVttdrN
|
||||
hgfpgCGZcjpcgfvNtdrtjvrdtSrd
|
||||
gZgsBBBlZggBGhsfhpzlzLDLmLRDRMLDPw
|
||||
hChhMFCvqtTMwbSSHgTZWHZd
|
||||
jjBNPjJJNfsNjVnVJJNcNfPwGbSbDZnZZgHrddwHrrgWGb
|
||||
mBBRRmBBQBmNJWhCzqllzhRCCv
|
||||
lQgpngNgQvHdSgWwjMRmDjmMDHmm
|
||||
zCLVzfzzbbCzsZZPbZPLfFJJMDWWRcDsmJRcjmwTmlRj
|
||||
BblftzBtlFznptSQQQppNG
|
||||
wJJwqCtCGRcVlqlM
|
||||
BQpppjBQLczTrvHRjH
|
||||
QQQ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QZrZStRdlnnFdlRzVVVWlnpzR
|
||||
bBMwwjzhbjhssvsGZBSZLr
|
||||
JFtnDtRzJtffJHWNtHncRRrvGZvSnllZZZsgvlnvVvlv
|
||||
RRPHPHFPHHdcHtzNfMQhdCwbqCmbMChhqq
|
||||
pWGdFSWwwjLdvgNNvggl
|
||||
mTNbmRPHmmVNmvZhnhBssBlhnb
|
||||
HPTzRPffJJNzjCFpDWDz
|
||||
MHlgzsqHlbmzgsHzlsbcRWPdPtjZFqhGGdrPrjPJGrVP
|
||||
vpwwvQwCnhNQpSnLdVtrrZGZtZjdVSdJ
|
||||
hfffwvTpvLwDpCLvDnQDHbmRRTcWRHMWWHWMmWMW
|
||||
WHlNHWWldjpwntnWBPpPQFZFBFhZBZCZ
|
||||
TqqvgvmgfmvDVLLfqqLsrFBRhrrBFJQBGPgPZGCR
|
||||
mcDbcDmzLcmDDzfVzTQNjNzNztdzjNdwSHlH
|
||||
123
aoc4.ipynb
Normal file
123
aoc4.ipynb
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "298d175e-fe20-4d97-8d3c-5b77b045a33a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Part 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"id": "aed8a1d4-93f0-4bb8-9810-a20b1113ff1f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def range_contains_range(range1, range2):\n",
|
||||
" return range1.start in range2 and range1.stop in range2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"id": "2385899f-2a65-467e-8abf-2d7fa90aba84",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"532"
|
||||
]
|
||||
},
|
||||
"execution_count": 29,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc4_input.txt\", \"r\") as f:\n",
|
||||
" fully_contains_count = 0\n",
|
||||
" for assignment_pair in f:\n",
|
||||
" match list(map(lambda x: list(map(int, x.split(\"-\"))), assignment_pair.strip().split(\",\"))):\n",
|
||||
" case [[fa1, fa2], [sa1, sa2]]:\n",
|
||||
" r1, r2 = range(fa1, fa2), range(sa1, sa2)\n",
|
||||
" c = int(range_contains_range(r1, range(sa1, sa2+1)) or range_contains_range(r2, range(fa1, fa2+1)))\n",
|
||||
" fully_contains_count += c\n",
|
||||
"\n",
|
||||
"fully_contains_count"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5886c69c-229a-45f6-b31e-556b55b1bbec",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Part 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"id": "c567162f-8ef0-47c1-ba17-84bf667b3496",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def range_overlap_range(range1, range2):\n",
|
||||
" return range1.start in range2 or range1.stop in range2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"id": "f3142767-65a1-4bf0-a64d-83ef53711e20",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"854"
|
||||
]
|
||||
},
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc4_input.txt\", \"r\") as f:\n",
|
||||
" overlapping_ranges_count = 0\n",
|
||||
" for assignment_pair in f:\n",
|
||||
" match list(map(lambda x: list(map(int, x.split(\"-\"))), assignment_pair.strip().split(\",\"))):\n",
|
||||
" case [[fa1, fa2], [sa1, sa2]]:\n",
|
||||
" r1, r2 = range(fa1, fa2), range(sa1, sa2)\n",
|
||||
" c = int(range_overlap_range(r1, range(sa1, sa2+1)) or range_overlap_range(r2, range(fa1, fa2+1)))\n",
|
||||
" overlapping_ranges_count += c\n",
|
||||
"\n",
|
||||
"overlapping_ranges_count"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
1000
aoc4_input.txt
Normal file
1000
aoc4_input.txt
Normal file
File diff suppressed because it is too large
Load diff
133
aoc5.ipynb
Normal file
133
aoc5.ipynb
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a19b0da1-9ac5-4d7f-9957-6268d3536564",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Part 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 36,
|
||||
"id": "dc5032e6-5ad2-4b32-8a58-29679cfba227",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def split_def_in_sectors(line):\n",
|
||||
" for i in range(0, len(line), 4):\n",
|
||||
" yield line[i:i+3].strip()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 60,
|
||||
"id": "cdccaa3e-0aaf-4e0a-8171-179f90c65bb6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'VQZNJMWTR'"
|
||||
]
|
||||
},
|
||||
"execution_count": 60,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc5_input.txt\", \"r\") as f:\n",
|
||||
" line = next(f).rstrip(\"\\n\")\n",
|
||||
" stacks = [[] for _ in range((len(line) + 1) // 4)]\n",
|
||||
" while \"[\" in line:\n",
|
||||
" for i, e in enumerate(split_def_in_sectors(line)):\n",
|
||||
" if e:\n",
|
||||
" stacks[i].append(e[1])\n",
|
||||
" line = next(f).rstrip(\"\\n\")\n",
|
||||
" next(f)\n",
|
||||
" for stack in stacks:\n",
|
||||
" stack.reverse()\n",
|
||||
" for cmd in f:\n",
|
||||
" match cmd.split():\n",
|
||||
" case [\"move\", amount, \"from\", pos, \"to\", newpos]:\n",
|
||||
" amount, pos, newpos = int(amount), int(pos)-1, int(newpos)-1\n",
|
||||
" stack_left, stack_right = stacks[pos][:-amount], reversed(stacks[pos][-amount:])\n",
|
||||
" stacks[pos] = stack_left\n",
|
||||
" stacks[newpos] += stack_right\n",
|
||||
"\n",
|
||||
"\"\".join(stack[-1] for stack in stacks)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b9df4a1d-f7ec-406c-870d-e5a7269ccf0c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Part 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 61,
|
||||
"id": "55ade032-7a23-4e6e-a984-71f0e452b224",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'NLCDCLVMQ'"
|
||||
]
|
||||
},
|
||||
"execution_count": 61,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc5_input.txt\", \"r\") as f:\n",
|
||||
" line = next(f).rstrip(\"\\n\")\n",
|
||||
" stacks = [[] for _ in range((len(line) + 1) // 4)]\n",
|
||||
" while \"[\" in line:\n",
|
||||
" for i, e in enumerate(split_def_in_sectors(line)):\n",
|
||||
" if e:\n",
|
||||
" stacks[i].append(e[1])\n",
|
||||
" line = next(f).rstrip(\"\\n\")\n",
|
||||
" next(f)\n",
|
||||
" for stack in stacks:\n",
|
||||
" stack.reverse()\n",
|
||||
" for cmd in f:\n",
|
||||
" match cmd.split():\n",
|
||||
" case [\"move\", amount, \"from\", pos, \"to\", newpos]:\n",
|
||||
" amount, pos, newpos = int(amount), int(pos)-1, int(newpos)-1\n",
|
||||
" stack_left, stack_right = stacks[pos][:-amount], stacks[pos][-amount:]\n",
|
||||
" stacks[pos] = stack_left\n",
|
||||
" stacks[newpos] += stack_right\n",
|
||||
"\n",
|
||||
"\"\".join(stack[-1] for stack in stacks)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
511
aoc5_input.txt
Normal file
511
aoc5_input.txt
Normal file
|
|
@ -0,0 +1,511 @@
|
|||
[L] [M] [M]
|
||||
[D] [R] [Z] [C] [L]
|
||||
[C] [S] [T] [G] [V] [M]
|
||||
[R] [L] [Q] [B] [B] [D] [F]
|
||||
[H] [B] [G] [D] [Q] [Z] [T] [J]
|
||||
[M] [J] [H] [M] [P] [S] [V] [L] [N]
|
||||
[P] [C] [N] [T] [S] [F] [R] [G] [Q]
|
||||
[Z] [P] [S] [F] [F] [T] [N] [P] [W]
|
||||
1 2 3 4 5 6 7 8 9
|
||||
|
||||
move 7 from 3 to 9
|
||||
move 5 from 8 to 9
|
||||
move 3 from 9 to 5
|
||||
move 6 from 9 to 2
|
||||
move 9 from 9 to 3
|
||||
move 3 from 7 to 3
|
||||
move 8 from 2 to 3
|
||||
move 9 from 3 to 1
|
||||
move 11 from 3 to 8
|
||||
move 5 from 6 to 9
|
||||
move 1 from 6 to 3
|
||||
move 1 from 2 to 7
|
||||
move 1 from 4 to 8
|
||||
move 1 from 3 to 9
|
||||
move 4 from 4 to 3
|
||||
move 6 from 8 to 3
|
||||
move 2 from 8 to 2
|
||||
move 4 from 9 to 3
|
||||
move 3 from 2 to 5
|
||||
move 2 from 5 to 4
|
||||
move 5 from 3 to 4
|
||||
move 11 from 1 to 4
|
||||
move 1 from 7 to 6
|
||||
move 1 from 3 to 5
|
||||
move 2 from 1 to 9
|
||||
move 1 from 1 to 4
|
||||
move 7 from 5 to 8
|
||||
move 21 from 4 to 6
|
||||
move 6 from 6 to 2
|
||||
move 6 from 8 to 9
|
||||
move 5 from 8 to 5
|
||||
move 2 from 2 to 7
|
||||
move 4 from 3 to 7
|
||||
move 1 from 2 to 6
|
||||
move 1 from 2 to 5
|
||||
move 2 from 2 to 7
|
||||
move 4 from 3 to 7
|
||||
move 1 from 4 to 6
|
||||
move 9 from 5 to 3
|
||||
move 7 from 3 to 4
|
||||
move 7 from 7 to 3
|
||||
move 7 from 4 to 1
|
||||
move 8 from 3 to 5
|
||||
move 1 from 3 to 5
|
||||
move 3 from 8 to 2
|
||||
move 2 from 2 to 9
|
||||
move 13 from 9 to 4
|
||||
move 5 from 5 to 3
|
||||
move 4 from 7 to 6
|
||||
move 1 from 7 to 4
|
||||
move 2 from 4 to 2
|
||||
move 3 from 3 to 4
|
||||
move 2 from 5 to 2
|
||||
move 6 from 1 to 7
|
||||
move 1 from 2 to 8
|
||||
move 1 from 3 to 8
|
||||
move 1 from 1 to 6
|
||||
move 1 from 3 to 4
|
||||
move 1 from 2 to 6
|
||||
move 24 from 6 to 1
|
||||
move 3 from 2 to 3
|
||||
move 3 from 3 to 5
|
||||
move 2 from 8 to 6
|
||||
move 2 from 5 to 4
|
||||
move 3 from 5 to 1
|
||||
move 7 from 4 to 8
|
||||
move 3 from 8 to 9
|
||||
move 2 from 9 to 5
|
||||
move 2 from 6 to 3
|
||||
move 1 from 9 to 8
|
||||
move 5 from 7 to 5
|
||||
move 2 from 3 to 1
|
||||
move 1 from 7 to 1
|
||||
move 7 from 4 to 7
|
||||
move 2 from 4 to 8
|
||||
move 6 from 8 to 6
|
||||
move 3 from 6 to 9
|
||||
move 10 from 5 to 1
|
||||
move 7 from 7 to 1
|
||||
move 1 from 4 to 9
|
||||
move 1 from 6 to 3
|
||||
move 2 from 9 to 7
|
||||
move 1 from 4 to 2
|
||||
move 1 from 9 to 5
|
||||
move 1 from 8 to 5
|
||||
move 39 from 1 to 8
|
||||
move 1 from 2 to 5
|
||||
move 2 from 6 to 9
|
||||
move 3 from 9 to 5
|
||||
move 3 from 1 to 6
|
||||
move 1 from 7 to 2
|
||||
move 1 from 3 to 2
|
||||
move 2 from 6 to 2
|
||||
move 3 from 2 to 3
|
||||
move 1 from 6 to 2
|
||||
move 1 from 1 to 8
|
||||
move 3 from 1 to 2
|
||||
move 3 from 2 to 4
|
||||
move 2 from 4 to 5
|
||||
move 2 from 3 to 8
|
||||
move 8 from 5 to 2
|
||||
move 8 from 8 to 2
|
||||
move 15 from 2 to 7
|
||||
move 1 from 1 to 5
|
||||
move 25 from 8 to 7
|
||||
move 2 from 2 to 4
|
||||
move 2 from 4 to 3
|
||||
move 1 from 8 to 4
|
||||
move 2 from 4 to 6
|
||||
move 1 from 2 to 1
|
||||
move 26 from 7 to 2
|
||||
move 15 from 2 to 1
|
||||
move 7 from 8 to 9
|
||||
move 10 from 1 to 6
|
||||
move 10 from 7 to 2
|
||||
move 1 from 8 to 1
|
||||
move 5 from 9 to 8
|
||||
move 1 from 8 to 9
|
||||
move 2 from 6 to 9
|
||||
move 3 from 7 to 1
|
||||
move 1 from 7 to 1
|
||||
move 5 from 9 to 2
|
||||
move 1 from 3 to 1
|
||||
move 9 from 6 to 3
|
||||
move 1 from 6 to 1
|
||||
move 4 from 2 to 4
|
||||
move 3 from 4 to 8
|
||||
move 1 from 4 to 1
|
||||
move 9 from 3 to 1
|
||||
move 1 from 7 to 6
|
||||
move 9 from 2 to 5
|
||||
move 14 from 1 to 6
|
||||
move 1 from 3 to 8
|
||||
move 5 from 2 to 6
|
||||
move 8 from 1 to 8
|
||||
move 6 from 6 to 8
|
||||
move 14 from 6 to 7
|
||||
move 1 from 1 to 7
|
||||
move 10 from 5 to 4
|
||||
move 11 from 8 to 5
|
||||
move 15 from 7 to 1
|
||||
move 4 from 5 to 6
|
||||
move 4 from 8 to 9
|
||||
move 6 from 5 to 3
|
||||
move 1 from 6 to 9
|
||||
move 1 from 1 to 6
|
||||
move 1 from 5 to 8
|
||||
move 2 from 6 to 2
|
||||
move 6 from 1 to 5
|
||||
move 1 from 5 to 8
|
||||
move 2 from 5 to 4
|
||||
move 9 from 2 to 9
|
||||
move 13 from 9 to 8
|
||||
move 1 from 2 to 1
|
||||
move 1 from 4 to 8
|
||||
move 3 from 3 to 1
|
||||
move 2 from 4 to 5
|
||||
move 2 from 1 to 5
|
||||
move 1 from 9 to 3
|
||||
move 17 from 8 to 1
|
||||
move 3 from 3 to 2
|
||||
move 4 from 5 to 1
|
||||
move 2 from 2 to 4
|
||||
move 1 from 6 to 1
|
||||
move 1 from 2 to 8
|
||||
move 4 from 4 to 6
|
||||
move 1 from 5 to 9
|
||||
move 5 from 6 to 8
|
||||
move 1 from 5 to 4
|
||||
move 1 from 5 to 6
|
||||
move 3 from 8 to 6
|
||||
move 8 from 4 to 5
|
||||
move 32 from 1 to 7
|
||||
move 11 from 7 to 6
|
||||
move 8 from 5 to 3
|
||||
move 3 from 8 to 7
|
||||
move 6 from 3 to 9
|
||||
move 4 from 3 to 8
|
||||
move 5 from 8 to 2
|
||||
move 1 from 8 to 5
|
||||
move 11 from 6 to 3
|
||||
move 1 from 5 to 2
|
||||
move 2 from 8 to 6
|
||||
move 12 from 7 to 8
|
||||
move 2 from 6 to 2
|
||||
move 2 from 6 to 4
|
||||
move 5 from 2 to 5
|
||||
move 8 from 7 to 2
|
||||
move 2 from 7 to 1
|
||||
move 2 from 7 to 6
|
||||
move 5 from 5 to 4
|
||||
move 5 from 4 to 7
|
||||
move 5 from 8 to 2
|
||||
move 2 from 9 to 7
|
||||
move 5 from 8 to 4
|
||||
move 2 from 7 to 3
|
||||
move 2 from 9 to 3
|
||||
move 3 from 7 to 9
|
||||
move 1 from 1 to 8
|
||||
move 2 from 6 to 1
|
||||
move 2 from 9 to 8
|
||||
move 1 from 7 to 8
|
||||
move 1 from 2 to 5
|
||||
move 1 from 7 to 9
|
||||
move 7 from 4 to 3
|
||||
move 3 from 3 to 6
|
||||
move 5 from 8 to 6
|
||||
move 3 from 9 to 5
|
||||
move 16 from 3 to 1
|
||||
move 2 from 9 to 1
|
||||
move 7 from 1 to 8
|
||||
move 1 from 1 to 2
|
||||
move 5 from 8 to 2
|
||||
move 12 from 1 to 4
|
||||
move 1 from 3 to 5
|
||||
move 1 from 2 to 9
|
||||
move 1 from 9 to 4
|
||||
move 4 from 6 to 5
|
||||
move 5 from 6 to 1
|
||||
move 1 from 6 to 5
|
||||
move 1 from 1 to 4
|
||||
move 1 from 4 to 7
|
||||
move 1 from 3 to 7
|
||||
move 9 from 4 to 6
|
||||
move 2 from 7 to 8
|
||||
move 1 from 3 to 4
|
||||
move 2 from 8 to 9
|
||||
move 4 from 8 to 4
|
||||
move 4 from 2 to 8
|
||||
move 2 from 9 to 7
|
||||
move 2 from 7 to 8
|
||||
move 10 from 2 to 4
|
||||
move 1 from 2 to 1
|
||||
move 5 from 4 to 7
|
||||
move 1 from 1 to 3
|
||||
move 3 from 8 to 7
|
||||
move 6 from 7 to 2
|
||||
move 3 from 2 to 7
|
||||
move 1 from 6 to 7
|
||||
move 5 from 5 to 8
|
||||
move 4 from 1 to 3
|
||||
move 4 from 3 to 1
|
||||
move 8 from 4 to 2
|
||||
move 1 from 3 to 2
|
||||
move 2 from 7 to 2
|
||||
move 2 from 6 to 3
|
||||
move 4 from 7 to 2
|
||||
move 4 from 5 to 7
|
||||
move 14 from 2 to 7
|
||||
move 3 from 2 to 1
|
||||
move 3 from 8 to 2
|
||||
move 1 from 5 to 7
|
||||
move 6 from 2 to 4
|
||||
move 2 from 2 to 7
|
||||
move 2 from 3 to 6
|
||||
move 6 from 8 to 2
|
||||
move 4 from 6 to 4
|
||||
move 2 from 6 to 9
|
||||
move 4 from 4 to 2
|
||||
move 2 from 4 to 8
|
||||
move 10 from 7 to 2
|
||||
move 18 from 2 to 6
|
||||
move 2 from 2 to 6
|
||||
move 2 from 9 to 2
|
||||
move 2 from 8 to 5
|
||||
move 1 from 2 to 9
|
||||
move 1 from 2 to 9
|
||||
move 1 from 5 to 7
|
||||
move 1 from 2 to 6
|
||||
move 2 from 9 to 2
|
||||
move 6 from 7 to 3
|
||||
move 7 from 6 to 8
|
||||
move 5 from 7 to 2
|
||||
move 1 from 7 to 4
|
||||
move 1 from 5 to 7
|
||||
move 4 from 8 to 7
|
||||
move 5 from 2 to 3
|
||||
move 1 from 7 to 5
|
||||
move 2 from 2 to 8
|
||||
move 9 from 4 to 3
|
||||
move 13 from 6 to 8
|
||||
move 10 from 3 to 1
|
||||
move 1 from 5 to 2
|
||||
move 3 from 6 to 8
|
||||
move 5 from 1 to 2
|
||||
move 1 from 1 to 8
|
||||
move 2 from 4 to 3
|
||||
move 17 from 8 to 6
|
||||
move 5 from 6 to 3
|
||||
move 3 from 1 to 2
|
||||
move 9 from 6 to 5
|
||||
move 2 from 6 to 8
|
||||
move 5 from 5 to 9
|
||||
move 3 from 9 to 8
|
||||
move 3 from 1 to 3
|
||||
move 3 from 7 to 5
|
||||
move 6 from 5 to 8
|
||||
move 7 from 2 to 4
|
||||
move 1 from 6 to 3
|
||||
move 1 from 1 to 5
|
||||
move 4 from 4 to 5
|
||||
move 2 from 2 to 9
|
||||
move 3 from 1 to 3
|
||||
move 4 from 5 to 8
|
||||
move 1 from 4 to 5
|
||||
move 6 from 8 to 7
|
||||
move 1 from 5 to 2
|
||||
move 4 from 9 to 2
|
||||
move 2 from 5 to 9
|
||||
move 2 from 1 to 8
|
||||
move 2 from 4 to 9
|
||||
move 6 from 7 to 5
|
||||
move 3 from 5 to 2
|
||||
move 3 from 2 to 5
|
||||
move 10 from 8 to 3
|
||||
move 2 from 8 to 5
|
||||
move 3 from 2 to 5
|
||||
move 6 from 5 to 1
|
||||
move 4 from 5 to 6
|
||||
move 1 from 7 to 5
|
||||
move 23 from 3 to 7
|
||||
move 2 from 5 to 9
|
||||
move 2 from 1 to 5
|
||||
move 2 from 6 to 3
|
||||
move 6 from 3 to 1
|
||||
move 1 from 1 to 7
|
||||
move 4 from 3 to 1
|
||||
move 1 from 8 to 5
|
||||
move 2 from 9 to 2
|
||||
move 3 from 3 to 8
|
||||
move 2 from 6 to 8
|
||||
move 12 from 1 to 3
|
||||
move 1 from 9 to 7
|
||||
move 3 from 5 to 9
|
||||
move 9 from 3 to 8
|
||||
move 1 from 1 to 7
|
||||
move 1 from 9 to 4
|
||||
move 3 from 3 to 6
|
||||
move 3 from 2 to 1
|
||||
move 3 from 8 to 6
|
||||
move 1 from 4 to 2
|
||||
move 1 from 2 to 9
|
||||
move 1 from 2 to 7
|
||||
move 20 from 7 to 5
|
||||
move 3 from 7 to 3
|
||||
move 3 from 1 to 3
|
||||
move 5 from 8 to 1
|
||||
move 5 from 1 to 5
|
||||
move 4 from 5 to 2
|
||||
move 3 from 2 to 6
|
||||
move 3 from 8 to 7
|
||||
move 1 from 2 to 6
|
||||
move 2 from 8 to 6
|
||||
move 2 from 7 to 5
|
||||
move 2 from 3 to 6
|
||||
move 12 from 5 to 1
|
||||
move 6 from 5 to 7
|
||||
move 12 from 6 to 8
|
||||
move 4 from 9 to 3
|
||||
move 4 from 5 to 8
|
||||
move 3 from 1 to 5
|
||||
move 4 from 7 to 4
|
||||
move 3 from 5 to 9
|
||||
move 7 from 1 to 6
|
||||
move 1 from 1 to 3
|
||||
move 6 from 7 to 6
|
||||
move 1 from 1 to 3
|
||||
move 10 from 3 to 6
|
||||
move 10 from 6 to 2
|
||||
move 2 from 9 to 5
|
||||
move 4 from 6 to 5
|
||||
move 9 from 6 to 1
|
||||
move 16 from 8 to 7
|
||||
move 3 from 8 to 7
|
||||
move 1 from 8 to 1
|
||||
move 7 from 2 to 1
|
||||
move 1 from 5 to 9
|
||||
move 1 from 6 to 1
|
||||
move 2 from 2 to 1
|
||||
move 3 from 1 to 4
|
||||
move 1 from 6 to 8
|
||||
move 7 from 4 to 1
|
||||
move 1 from 8 to 2
|
||||
move 22 from 1 to 8
|
||||
move 18 from 7 to 9
|
||||
move 6 from 5 to 2
|
||||
move 2 from 2 to 7
|
||||
move 2 from 1 to 5
|
||||
move 4 from 7 to 6
|
||||
move 1 from 5 to 6
|
||||
move 2 from 8 to 2
|
||||
move 3 from 2 to 6
|
||||
move 1 from 5 to 6
|
||||
move 15 from 9 to 6
|
||||
move 6 from 9 to 5
|
||||
move 1 from 9 to 8
|
||||
move 1 from 2 to 9
|
||||
move 5 from 5 to 9
|
||||
move 9 from 8 to 6
|
||||
move 3 from 2 to 7
|
||||
move 12 from 8 to 9
|
||||
move 1 from 7 to 5
|
||||
move 1 from 5 to 7
|
||||
move 3 from 7 to 1
|
||||
move 17 from 6 to 3
|
||||
move 1 from 2 to 6
|
||||
move 2 from 1 to 4
|
||||
move 16 from 6 to 4
|
||||
move 7 from 4 to 6
|
||||
move 1 from 5 to 7
|
||||
move 8 from 4 to 5
|
||||
move 9 from 9 to 8
|
||||
move 16 from 3 to 7
|
||||
move 1 from 1 to 5
|
||||
move 3 from 5 to 1
|
||||
move 5 from 6 to 2
|
||||
move 3 from 1 to 7
|
||||
move 3 from 6 to 7
|
||||
move 3 from 9 to 3
|
||||
move 5 from 8 to 5
|
||||
move 11 from 5 to 7
|
||||
move 2 from 3 to 7
|
||||
move 1 from 2 to 1
|
||||
move 1 from 3 to 6
|
||||
move 17 from 7 to 9
|
||||
move 1 from 3 to 2
|
||||
move 3 from 4 to 6
|
||||
move 1 from 1 to 2
|
||||
move 1 from 6 to 4
|
||||
move 14 from 7 to 6
|
||||
move 15 from 9 to 6
|
||||
move 4 from 8 to 7
|
||||
move 1 from 4 to 7
|
||||
move 7 from 9 to 5
|
||||
move 5 from 2 to 9
|
||||
move 7 from 5 to 1
|
||||
move 3 from 1 to 7
|
||||
move 29 from 6 to 4
|
||||
move 1 from 2 to 4
|
||||
move 18 from 4 to 2
|
||||
move 3 from 1 to 4
|
||||
move 1 from 1 to 7
|
||||
move 18 from 2 to 4
|
||||
move 3 from 6 to 5
|
||||
move 15 from 4 to 1
|
||||
move 1 from 5 to 1
|
||||
move 1 from 5 to 4
|
||||
move 9 from 4 to 1
|
||||
move 5 from 1 to 3
|
||||
move 9 from 1 to 5
|
||||
move 2 from 4 to 3
|
||||
move 5 from 5 to 6
|
||||
move 3 from 7 to 9
|
||||
move 7 from 7 to 5
|
||||
move 6 from 4 to 6
|
||||
move 2 from 3 to 7
|
||||
move 6 from 5 to 8
|
||||
move 2 from 8 to 4
|
||||
move 1 from 8 to 9
|
||||
move 9 from 6 to 2
|
||||
move 3 from 9 to 3
|
||||
move 1 from 2 to 1
|
||||
move 6 from 7 to 4
|
||||
move 2 from 2 to 8
|
||||
move 3 from 9 to 5
|
||||
move 5 from 4 to 8
|
||||
move 1 from 6 to 9
|
||||
move 1 from 3 to 1
|
||||
move 1 from 3 to 4
|
||||
move 1 from 6 to 5
|
||||
move 1 from 9 to 3
|
||||
move 10 from 8 to 7
|
||||
move 3 from 9 to 2
|
||||
move 7 from 2 to 4
|
||||
move 6 from 5 to 7
|
||||
move 4 from 5 to 8
|
||||
move 7 from 3 to 2
|
||||
move 3 from 7 to 1
|
||||
move 9 from 1 to 5
|
||||
move 5 from 7 to 9
|
||||
move 7 from 1 to 4
|
||||
move 11 from 4 to 2
|
||||
move 4 from 8 to 3
|
||||
move 5 from 4 to 7
|
||||
move 4 from 4 to 1
|
||||
move 1 from 3 to 6
|
||||
move 12 from 7 to 4
|
||||
move 2 from 1 to 8
|
||||
move 5 from 9 to 7
|
||||
move 7 from 5 to 6
|
||||
move 1 from 1 to 4
|
||||
move 1 from 9 to 8
|
||||
move 1 from 4 to 7
|
||||
move 1 from 8 to 9
|
||||
move 5 from 7 to 9
|
||||
move 2 from 7 to 5
|
||||
move 2 from 6 to 3
|
||||
move 5 from 2 to 7
|
||||
move 1 from 7 to 8
|
||||
move 1 from 1 to 6
|
||||
move 3 from 5 to 1
|
||||
97
aoc6.ipynb
Normal file
97
aoc6.ipynb
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "14be2365-970d-41a2-bc43-000c718aac46",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Part 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 26,
|
||||
"id": "47f56d42-e07f-4fdc-a3a3-0cd97c09bde9",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1238"
|
||||
]
|
||||
},
|
||||
"execution_count": 26,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc6_input.txt\", \"r\") as f:\n",
|
||||
" read_str_before_packet = f.read(3)\n",
|
||||
" while c := f.read(1):\n",
|
||||
" read_str_before_packet += c\n",
|
||||
" if len(set(read_str_before_packet[-4:])) == 4:\n",
|
||||
" break\n",
|
||||
"\n",
|
||||
"len(read_str_before_packet)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "10e8a318-7517-4212-b619-ad1406f144e3",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Part 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 27,
|
||||
"id": "139b3b21-76a0-49d7-9533-caf170e18cb0",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"3037"
|
||||
]
|
||||
},
|
||||
"execution_count": 27,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc6_input.txt\", \"r\") as f:\n",
|
||||
" read_str_before_marker = f.read(13)\n",
|
||||
" while c := f.read(1):\n",
|
||||
" read_str_before_marker += c\n",
|
||||
" if len(set(read_str_before_marker[-14:])) == 14:\n",
|
||||
" break\n",
|
||||
"\n",
|
||||
"len(read_str_before_marker)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
1
aoc6_input.txt
Normal file
1
aoc6_input.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
dcbcsbblhhgdgssmcmqccdwdvwdvvcfvcfvvpvmmwccdqddshhdppcfpfbbfggfjfvvhzhmmsqswsttcgtctggjllhnnqbnnnldlglplvlbvbzztpzzvpphshwwfhhgssvgsvvpfvfzznbznndqqtsqttnvtvqqqrgqrrgzzlqzzbvzbzmzffnbfnbffcggdcggqhqpqzpqzqbbqvbqbhhtzhhrrrprlrclrcrssqspqpbblggfvvbpvbbssvttsztzpzjjwffnpnfnrrqhqgqrrzqzbzzdpdjpplpclpptltztjtztqthtmmmpsmmpjpqpvvshhsfshhrvrdvdggwssdbbzbttlmlmpprmrmlrrmqrqsshjhjljzjnjllbbvjvnnppqbppqqfffrbfbdfbbqppmtppfttqddtzzwbblqqbddgwgqwqzwwpzwzjjbccdjdwwrggrmrtmrtmrrvpptwwcdcwwsdshhjjhwjwqjwwqsshrrbsblssphspsjpssnsmsqswqwfwjwccdvccrqqnsqnsnwsnsmnmccvcqqfjjfljfljfjgjffjvffvjvhjhfhrfrlrrtpphbhwbbvmmnpndnlljdjfjsffvccnhchwhddrccljllmnnhmnmpnnhtnthnhvnhnwnqqjmmgzzvssphhjljbjwjbwwdnwwdvvzpvvhccvjjlclrrppgjgsshghvvzjvvpvvbjjqhjqqfcqffchcmmvdvtddftdtppfnppcnpnznwwpdpjpnpttlbbmmqfqmffqnfnbffbrbgbwggsmsbbfgbbfbzbtzbbvmmdlmlrlnlwwbswsjjpjhhwqwzqznqzqvvwccwvwwcbbpvvwcvcvzzhzchzccbnccjlljsjbjdbbvqbvvfdfgdfggzfzlzmzrznnqsnncmnnljjtcjcfftrthtrhrgrvvjggzpggrcrpcppggdfggpmmwnmnlmlglvvmjvvddsmsjsnjssqffffctczcjzjjlbbhpbbfdbdzbbsjbjnjbbqqjbqjbjjhwhssmvsschhhwppbjppllprpjrppdpfpgpjptjtptplpnptnptpjjmcmnnnhnjhjlhjlhjlhlwwhwmwjjbhhlfffrbbgvvqwvwswtstmmmfpmfpffmcfcrrqsqzqjjjnpnnztnznddlwdldsdbssstzstswwjtttmmwmsmwssvswszsjzsjjsffmccmfccqzzvpmbbbsqffgzdqbjtzhlqdzhlpwghlstcrcrffrnbwjnqgmbmpgttfmsswdqctlrpdnlsgnlldvbfpwtcptvbwftzcnbbscrrcpnwtmllcvsrmwzzlsdmfctdcwsqdlsnzgfpmzrnswhbqjhstztzzmzpcttsgsggnlhvjmcbbrhgqhsfmglpcbdvmmmnfbtbfrqbpcmttjtnwvznbshwrmznnsvpjqjntlzspljnbwtjcqztsfcqlrggrpzjgjsvqqcrmrjmzwdsshqfhbtfmlwmfvtbcgdmjgtcnphfmfmjlbjzrvjslccftnwcchgdwjnlthlwgldjwqwgdptdjdmzdrrzcdpbfrtdgcspjtqdqvzswwdwrhggdrqjjgwwrbwhhlrpqmszvlvjfqptncjlscvzbgzgmsttlbhbfrctnsphjcrcwlhcgrcrsjbrjvptgfbjgjrvtzmnhpzcgptbmrgvstsltnctjphsjdwpdqblfswzfhgjbpfrptlmhfwcpdlzqccgtdvbzhwngrhlqftmlhjprscflgzpflvvpfsjmlnmbzsrlrshvnsqrhhlqdlzhrcbjjjfrbqcdspwsmltcrtlbdnbnvhbbwgqdcncsztbfwztzdbqgcrnvndmpstpncbwvtctzdpmcpvrgqvjjztfwpvjtdqlvcvdpfzgcghsmbcwtzztmqwdpsprgsmfhphqsqmflrjdqzjscgzlnvcwcrlmpdscnhqpqjfdbdftqgttwntdbpnshdwnmwsrslfgnzlnwwwqgdbfnthhqtvbzsqgzjhhghtmvvfhlmlpbghnsvlttzsjlgndhdqmqqfdlqnbfscsnnqzcdwzdlqcnstcbsffghftqvwrsshgwmlnprhdnnwslwfwtmtfzdjwpmlvvdhjvdwrhvdsmpgrdpnqsjpqmhttrmdwllrmnbznwjwvvpjnnbnfzbdnhjbqqrnzgdqbspbqtwdpgsbwpzfdbpvzfjpsgmztnzrpvvhwlfscfvfpfblvplgdbhvjjpdjtnwrmvpjsphvglpsntvwtqwqvprcgwjltddpjngvmzfzhmqnnwglbzsbrcztpplpsmgmcfgzgpbtgsjrfvdzzcsthznvdpbwvdlcgdhncsjdvpcbbmtrqczctjljdfghsrvrsfjglqqhjttfdhqdqwhzhqrggsjwlldrntwmmbftgqjhpvvctpbtgltnttlhdqbsbwcqmctwlsnhmhncpmnzsllmjhcgnlfgvpcqrwzvsstgwbvjtnrlbblclzdrcwddrwnptqzgwdwtgrfwffpzjmwbqfmmrcfzfzjbwsslbhggtwtcrlhffzgfgrtljgnznnlgzwfmtwwqzhlthvpfclrtmrqfzrggbctzfsmjhrtwzpfrnhwwprnbwmvwvmvnzqpggmzgslctqbqdtvhgzjwzsnblqzmcpnpwllzhvzzmfqzfjlrsrcnjzqdzbpjftljtzvvmrjszvqllnhhgnrnqttnwlvllphjtnmlwqhcvmbsvnwtcdmhsmhdcwqwtvggcqfpdsrsscmhcvfzvdnffrfhdfmgbsghdbpwdwrdmlvsnzwcfchcqvccszdqrbnfvrpbftcwnjmczwgqzmtlmrthlhtjpmchltcmcqwgfgshtvtpmcmpbmlnjmhnpdsljjmjzddnlgtnjqztzsqqlhtqcscjvjncjvfcvsgjhqgzrmtjjcgvvmwswffmlcvlhqhbvrldrvbrfmmqcnqmfzlsghvclrdbsvcbqspgbzmjnlrdhvncnbcfmdlqrssggsmlwwglcjjzmcdwcnrgvvmgjcfbzlncmgqtllgldbdztbtfcjczqtjjlnpqmrgtjsmrbscvqlgqghfbgwccgwrjrzrsbbrqnjcqhllsqmrjtzmjnndwwmdjfhspjpgdcjjpdvwrsgjcfnpllnnnccvnfvqbpddgvbgbsbczmbzrbclczljdmbhpgmhwlqvnjzjwzzfjmsmcchjrqrtmhwlgjsptctlbtdnrqgntcvngcrqdqptfmhbvlhrqchdtwdwbrbqwtswzcrrfndldwmjbczppzrnncvvqsmpvvqcnsvhprhlmrhnjbwdvrbbwwdtmzrqttschrztgjcshlhfbmhmwrrmwgmfshpdhjwgdmcfdvqrmmwgmzbrlgbfltvlzmvqbgvhppdzglqbdlrhjnntnfvtmzjqccmqdbpjqphfggmjqdrndhclcfvqsjrsbcgdhcrbjsdjmwrzvpfpcjwjfdltztfzgmlzqzmztpvbflppgnhdzssznngfjggczdtdmcczjzfsnflpwqrbggmqdbbprfptzcdqvhrvszzjqqjlrlrdpwcnzhvgfhpcdbbgsfmtnszwbhwcdwdghqqctwqlqrlqbdwfvjnhcpmzchqfrwzhzgslzhncmrlrpzcjczvzwcvwcldbmscfqnnqnwwvrpfvjswqmhgmhgnmfzpsjmdhbpvsftccttvdpcdzcnzswqmtrwbctpbgmzrvrrshjjgdqsqrwfpcmsbvqhccvjqpztlttwjjdtbmwslschpqjjllvjcjwtmrtvvwdzglstvtpndmmzcpgqsvqgfdtqdjdctsbsbmqzqhtczhgqgwbdlrhjrwcmtbzfndsbnpnhmsdhtghwwzvtdwtscdnwzmrjrsrjvvbvrpbszchwbltrjbcqmlhqnzcfbhjqnsjghlnlbsrgzrrzfvslwpbqmgfswhgjdsdfrzsdhvdqvqfbcbvmbfhjfpzwlbspcbnvrgpfnmjbwbsnpqpqhjpsnwrlcmfhpdmjbvpnctcfqgdmwzblsnr
|
||||
217
aoc7.ipynb
Normal file
217
aoc7.ipynb
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "34af346b-bcec-4d44-b3d9-4f3fa2caeb14",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Part 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 121,
|
||||
"id": "45e4c72c-1ce9-4012-9937-ac0f0d4db3c6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from dataclasses import dataclass, field\n",
|
||||
"from queue import SimpleQueue"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 122,
|
||||
"id": "a54cd000-15b6-4257-abe5-000df7ed59c5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"@dataclass\n",
|
||||
"class File:\n",
|
||||
" name: str\n",
|
||||
" size: int\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@dataclass\n",
|
||||
"class Dir:\n",
|
||||
" name: str\n",
|
||||
" files: list[File] = field(default_factory=list)\n",
|
||||
" subdirs: 'list[Dir]' = field(default_factory=list)\n",
|
||||
" parent: 'Dir' = None\n",
|
||||
" _cached_size: int = None\n",
|
||||
" _cached_path: str = None\n",
|
||||
" \n",
|
||||
" @property\n",
|
||||
" def size(self) -> int:\n",
|
||||
" if self._cached_size is None:\n",
|
||||
" self._cached_size = 0\n",
|
||||
" for file in self.files:\n",
|
||||
" self._cached_size += file.size\n",
|
||||
" for subdir in self.subdirs:\n",
|
||||
" self._cached_size += subdir.size\n",
|
||||
" return self._cached_size\n",
|
||||
" \n",
|
||||
" @property\n",
|
||||
" def path(self) -> str:\n",
|
||||
" if self._cached_path is None:\n",
|
||||
" if self.parent is None:\n",
|
||||
" self._cached_path = self.name\n",
|
||||
" else:\n",
|
||||
" self._cached_path = f\"{self.parent.path}{self.name}/\"\n",
|
||||
" self._cached_path = self._cached_path.replace(\"//\", \"/\")\n",
|
||||
" return self._cached_path"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 123,
|
||||
"id": "6303fecb-3618-493d-b6fb-e9c1858af90e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"('/', 44795677, 1, 8)"
|
||||
]
|
||||
},
|
||||
"execution_count": 123,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"with open(\"aoc7_input.txt\", \"r\") as f:\n",
|
||||
" root = Dir(name=\"/\")\n",
|
||||
" next(f)\n",
|
||||
" pwd = root\n",
|
||||
" for line in f:\n",
|
||||
" match line.strip().split():\n",
|
||||
" case [\"$\", \"cd\", \"..\"]:\n",
|
||||
" pwd = pwd.parent\n",
|
||||
" case [\"$\", \"cd\", cd]:\n",
|
||||
" for subdir in pwd.subdirs:\n",
|
||||
" if subdir.name == cd:\n",
|
||||
" pwd = subdir\n",
|
||||
" break\n",
|
||||
" else:\n",
|
||||
" raise AttributeError(f\"Folder '{cd}' not found in current dir!\")\n",
|
||||
" case [\"$\", \"ls\"]:\n",
|
||||
" ...\n",
|
||||
" case [\"dir\", dirname]:\n",
|
||||
" pwd.subdirs.append(Dir(name=dirname, parent=pwd))\n",
|
||||
" case [filesize, filename]:\n",
|
||||
" pwd.files.append(File(name=filename, size=int(filesize)))\n",
|
||||
"\n",
|
||||
"root.name, root.size, len(root.files), len(root.subdirs)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 124,
|
||||
"id": "8ed82a45-dd7c-4a8f-b087-bc741148da47",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1391690"
|
||||
]
|
||||
},
|
||||
"execution_count": 124,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"traversible, traversed, requested = SimpleQueue(), set(), []\n",
|
||||
"traversible.put(root)\n",
|
||||
"\n",
|
||||
"while not traversible.empty():\n",
|
||||
" dir: Dir = traversible.get()\n",
|
||||
" if dir.path in traversed:\n",
|
||||
" continue\n",
|
||||
" if dir.size <= 100000:\n",
|
||||
" requested.append(dir)\n",
|
||||
" for subdir in dir.subdirs:\n",
|
||||
" traversible.put(subdir)\n",
|
||||
" traversed.add(dir.path)\n",
|
||||
"\n",
|
||||
"cumm_sum = sum(map(lambda x: x.size, requested))\n",
|
||||
"cumm_sum"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a61f8782-d7f6-4908-b5b0-e7aacfec455b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Part 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 133,
|
||||
"id": "22bbbeea-0e73-4d05-8637-09cbc6112a7b",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"179 dirs\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"('dqbnbl', '/hmw/tsrqvpbq/dqbnbl/', 5469168)"
|
||||
]
|
||||
},
|
||||
"execution_count": 133,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"traversible, flat_file_list = SimpleQueue(), []\n",
|
||||
"traversible.put(root)\n",
|
||||
"\n",
|
||||
"while not traversible.empty():\n",
|
||||
" dir: Dir = traversible.get()\n",
|
||||
" flat_file_list.append(dir)\n",
|
||||
" for subdir in dir.subdirs:\n",
|
||||
" traversible.put(subdir)\n",
|
||||
" traversed.add(dir.path)\n",
|
||||
"\n",
|
||||
"print(len(flat_file_list), \"dirs\")\n",
|
||||
"\n",
|
||||
"space_left = 70000000 - root.size\n",
|
||||
"flat_file_list.sort(key=lambda x: space_left - x.size, reverse=True)\n",
|
||||
"big_enough = filter(lambda x: space_left + x.size > 30000000, flat_file_list)\n",
|
||||
"needed_dir = next(big_enough)\n",
|
||||
"needed_dir.name, needed_dir.path, needed_dir.size"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
1008
aoc7_input.txt
Normal file
1008
aoc7_input.txt
Normal file
File diff suppressed because it is too large
Load diff
176
aoc8.ipynb
Normal file
176
aoc8.ipynb
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "44a4d803-d75a-4954-9395-f496f05cfa3c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Part 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 82,
|
||||
"id": "472462b7-896e-4993-80c4-996f318c0c44",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"with open(\"aoc8_input.txt\", \"r\") as f:\n",
|
||||
" forest = []\n",
|
||||
" for line in f:\n",
|
||||
" forest.append([*map(int, line.strip())])\n",
|
||||
"\n",
|
||||
"W, H = len(forest[0]), len(forest)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 83,
|
||||
"id": "828ee197-c184-4826-afc4-3700b0e97762",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def get_row(row):\n",
|
||||
" return forest[row]\n",
|
||||
"\n",
|
||||
"def get_col(col):\n",
|
||||
" return list(map(lambda row: row[col], forest))\n",
|
||||
"\n",
|
||||
"def is_visible(x: int, y:int) -> bool:\n",
|
||||
" v = forest[x][y]\n",
|
||||
" r, c = get_row(x), get_col(y)\n",
|
||||
" \n",
|
||||
" rlp = r[:y] + [0]\n",
|
||||
" rrp = r[y+1:] + [0]\n",
|
||||
" cup = c[:x] + [0]\n",
|
||||
" cdp = c[x+1:] + [0]\n",
|
||||
" \n",
|
||||
" return max(rlp) >= v and max(rrp) >= v and max(cup) >= v and max(cdp) >= v"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 84,
|
||||
"id": "92c923a5-b93f-4492-8ac0-afc98ebd0205",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1818"
|
||||
]
|
||||
},
|
||||
"execution_count": 84,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"c = 0\n",
|
||||
"total = W * H\n",
|
||||
"\n",
|
||||
"for x in range(1, len(forest)-1):\n",
|
||||
" for y in range(1, len(forest[x])-1):\n",
|
||||
" c += int(is_visible(x, y))\n",
|
||||
"\n",
|
||||
"total - c"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "34161fd4-966e-4536-a338-17835748f372",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Part 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 85,
|
||||
"id": "25132b83-3c45-46e0-80df-89ebb8a431a8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def calculate_scenic_score(x: int, y: int) -> int:\n",
|
||||
" v = forest[x][y]\n",
|
||||
" r, c = get_row(x), get_col(y)\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" rlp = r[:y][::-1]\n",
|
||||
" rrp = r[y+1:]\n",
|
||||
" cup = c[:x][::-1]\n",
|
||||
" cdp = c[x+1:]\n",
|
||||
" \n",
|
||||
" ssl, ssr, ssu, ssd = 0, 0, 0, 0\n",
|
||||
" for t in rlp:\n",
|
||||
" ssl += 1\n",
|
||||
" if t >= v:\n",
|
||||
" break\n",
|
||||
" for t in rrp:\n",
|
||||
" ssr += 1\n",
|
||||
" if t >= v:\n",
|
||||
" break\n",
|
||||
" for t in cup:\n",
|
||||
" ssu += 1\n",
|
||||
" if t >= v:\n",
|
||||
" break\n",
|
||||
" for t in cdp:\n",
|
||||
" ssd += 1\n",
|
||||
" if t >= v:\n",
|
||||
" break\n",
|
||||
" \n",
|
||||
" return ssl * ssr * ssu * ssd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 86,
|
||||
"id": "54b7e07c-4e3c-4f3b-bab8-588d11117639",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"368368"
|
||||
]
|
||||
},
|
||||
"execution_count": 86,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"highest_scenic_score = 0\n",
|
||||
"\n",
|
||||
"for x in range(1, len(forest)-1):\n",
|
||||
" for y in range(1, len(forest[x])-1):\n",
|
||||
" sscore = calculate_scenic_score(x, y)\n",
|
||||
" if sscore > highest_scenic_score:\n",
|
||||
" highest_scenic_score = sscore\n",
|
||||
"\n",
|
||||
"highest_scenic_score"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
99
aoc8_input.txt
Normal file
99
aoc8_input.txt
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
200200221023111313131033314121142013103432145142351212334232423210101340410243413011333312111010010
|
||||
021002023301222221234134021422342024344555521535143232341414552024224120114233210330203002020100112
|
||||
120000123021210023111321143114331115334535223455511513445233523154411102203411040133312002213001021
|
||||
110211312303200204232110124204135453554533435152342542252215415141133330323032234114310011301232202
|
||||
112002122201001100330432244432552555524445123151222142521452233321152332132412434434431321322021220
|
||||
000131233030332102140440124221314455255431113413445553414144524134315351524134030112312012102102122
|
||||
011002120310213142402320144522121125454423123245535451115134412543215113433312403430132101003202030
|
||||
001221312201314442411333454131552331253553254425236334643151355314514413411344034432330410221101023
|
||||
133033302114012204213054544541124453214232545523665466356466451514332142121512400041213432211332332
|
||||
122103100320433433403313515121232352332442555253656542336644235234542522322522414400320014312110331
|
||||
220032121143103434234531224315451255225362634256634623342624242245654341134514413144333113211200033
|
||||
320112113344013332224131114231235263526556625325625352254643224563365551253353323542200003301120011
|
||||
130332114433413215333445212514445445656665256554333534422554442522234433415533124353022320300112030
|
||||
122220320003402342433443415465352622564252264442264334335624365224645544545412124352220434440211220
|
||||
012123032311134245212342233263346563632453535355553473445564362634252543555515242444423232000444220
|
||||
210332422344222154315435122245243633424643346345734336333746422324336263624544151122442021330341202
|
||||
122113144440445232235222443563362625543565533465377647363543377645634552632254214531354231413432430
|
||||
312340402310532324322313244522226622547366756445444754767335355365264622465662241215332253310001232
|
||||
203342203201331433144542522354633356376457563745333765735577477354743263423666625212251354244021004
|
||||
023132211325442531332565334564256663665357767653737436565453774766335532544656254552332354313323032
|
||||
104344140125552254523443534436547653753334746356364664565677777637444474643245425325454224440231203
|
||||
030303323422144551254256535247737377634445575474654433333453643564664344462332353234553115322142242
|
||||
043342223454513255464263333566337576377476354884845654658465735544446646436232534263314313142020101
|
||||
340311214411551345423466343646644336367654787858788857666654635337366537645634644263323112331404131
|
||||
040141315333331565455545334767475747755574585547567756844746644445646736447635456236413253453410130
|
||||
211021153443415666656253646443465373878486485664464485545486846643475567536535465634262415153200040
|
||||
434443334231526223353563373464374574547886487867474546748668788886554566336675234542522151345414431
|
||||
342100553111533623655466757467553555676668887764575574556755884875687334634675256256443425223423211
|
||||
421145141552463255552236436455476686566587654558577848647854485587448337355756554555544211113112433
|
||||
401034232152434624233754647737667758845867866675595798957488447876578774367337742646625521543244120
|
||||
201414142512656264345465456536564477766677986565767776589758477664747866666435364642236343442335143
|
||||
422042442525465325256445643735574646548578959977866889666586787677748745536646677524242544332243420
|
||||
101531424154626224664754337344565457557999965875599965977796778866568855445766577565632633451545144
|
||||
111515354125252635577747557658555488765757696767797558565755699985844788764347763523465333315513212
|
||||
222334234142233522754645544788567846579566995878775676667979868685866578655574543564453254615121150
|
||||
121552233464445256557546467767485865866888757989977669966767877786686475874646454752632664243132511
|
||||
412242332564644335747746348878865677677797755798669796798699855757865564547645373677564252625352445
|
||||
104135225262634344357677645645458796767865979969889676688676788669777674757634454746666526341145313
|
||||
021542323626266573437334685574765967759968767697666876767887775889896866845887736736426556541522241
|
||||
321245255565266675757675486554868969567677786789686889669988776968557656488476534636744443443445532
|
||||
424153123565322534465577464547665888797687899787966868666667897595997786576655333657432563645515114
|
||||
151513345354454444763668544475487669995769769878776696968966788666679588686556634737544644543232332
|
||||
315411214333624753546345646876778875556666766899787967667988799866697798768788653774352466325322155
|
||||
411515135354235576553778556478657685968679689776697889878966888788686556488744645555636235464132151
|
||||
521535123365535747465567756884789758877668899777979788877786896957896655744848765333672323354342345
|
||||
511122245466262643344764588545559786677866787999989789989769786875585659588677463454335226643415231
|
||||
234355522634365636744684556586586576767676868898988888987788888877768767654646777776645642226512141
|
||||
113123464223654555566666486667798785887896678897787899778677766996769787745467865757755656543512345
|
||||
513251343243554753654655574645569758987667887877878998789898989677659987488676836733553556554225344
|
||||
514313564242345475335768454478576556889868687997999987778988866675979779845785867656464634654245123
|
||||
114315542426623675675378664848688856798777688977789877988898769769667968885864643357435456442515251
|
||||
342223563236537773664686558445968779787887987788777777899877867865678669767686535536743642245412355
|
||||
125543254543547353647388564555887588899766978788778797797796898997787999888766547554567344424443422
|
||||
235522554554262346774664445787579599869688998989778778978989968998575857577865454747575353226552114
|
||||
222421136654623646474466478475666768686777899887878779887688896658596779765485853765563356364225314
|
||||
521231534444644737467764858748655998796879877877788879799986898965697856444748453437553352232525543
|
||||
451421316463534654736364878868555996777987969978898798976796968858967778666788533743354325346223354
|
||||
353521254635223475773456867765596786879787787769889887896999898885688596454456655466765442452131244
|
||||
112452332645434776643548885574558878789797669769989989886877966757566586444578445673434665652431423
|
||||
125112515242255354574555588568695879785886989867778677698879979576678878668587547744623644323213555
|
||||
222335123454333544773645644774469985799577787667779799699876685666756857858446357667422332624342332
|
||||
342124352633564466565447655564575889567797869876686996679999868665879886844677564455723264641334552
|
||||
211531121363532576364535865484865759689798698998996686966767965765789787447464533667726322444223531
|
||||
003112555432534436636776465475555776887557956877687879969697585659596546865447775565562326263355343
|
||||
433244413454525566563634447454784577659787856568996976596789778896764874668454673456462646455545115
|
||||
315114535444536635475346535567864558579958679557799758766667597987857466754537555645552424625323424
|
||||
041544243435426366744535764674465545875655656695956899997569789788477547755346553676234364525135211
|
||||
110125213453624243247556736654454474595787967599557857997699578855767558775435554762633446551353134
|
||||
230513132216566245267463366654684755868756978975659588575959655686655788733345435522656542222543322
|
||||
042134352115436525535436657767864645756586865777685969969787676584458468744346376522324323225232212
|
||||
113011555414226244554676353335845564485568555689599656977797776777868787473376444245355443123441231
|
||||
141222553351554636564756467565656675455484874698998587887767666457458846465776554544333612224555323
|
||||
410201213345143434422573347343756574748746464486554485756685477655667634334766422236535313341542224
|
||||
400013155121116452255553534765374544884448574876457458645878446585657476536357256436654223345343132
|
||||
142320132432156443246333547553474375466866456765867768748787675644755677446563663223424341524352200
|
||||
130310433221343524424456477364543647448885475465487864674454548867635637545422424333245424354220221
|
||||
104443025533452125362252625375463664447488646447874885476567646456653665465543643663511122334514003
|
||||
302020415314212533664642446555554345445458887778858887685645576353536647674424342553325334543032421
|
||||
241431045353353251642363462546445336355737566757557674865573447644353353564422462552323432524142311
|
||||
123213233322144323666345645436644754537635574357377674465747755476333656624223243445125521412332331
|
||||
012331042212144212425325652566536457633744775665435737646677453634637335562564643341411132411032042
|
||||
312330023343231454516256365325363757435647543374644573757667446466553456424326532235455225410011222
|
||||
330440423204155515131264636336326536353437335474474464535536754457526344465446535213522513202431334
|
||||
111010303340451214252454445262262654354536464545434674354557674362552463364322545323344220103312142
|
||||
011012340310414525221212256242445654336566374374366636534765356655652454533664444453134140113204011
|
||||
230024312112245355233251252646423364546365646735756334573543653656365434363633141223321213032042131
|
||||
031001023032240425233144214253446244556226622634747362226456645266342264223215113131540112130410110
|
||||
322123043034044225552242443355356433432465646225242242422346453346634325254325435535313321413201023
|
||||
022331002231110112224233354325624225342363424426633436565344545533465463152555421312331102120410200
|
||||
013020314334233240543141441351342432435423252532545655664253435662546145412112135314414140233322202
|
||||
023101011114024240134343343214355543453244325544366633232356362353335431215322232434231302030012200
|
||||
121203223241323132430512521115213312263253263242264335335446352453314333354413113210133333212120303
|
||||
102030123234100043232214342352345452215246465634534464364425653323345231332311444434220444330131120
|
||||
000331303323044244144032522114521112125142214553424464423124453113211413324230342333130021200000221
|
||||
121203123313224230334312325441234431451535345453515132125413445443323514321330302200100022013232311
|
||||
000221331111234212331404233225332533323225131525322111443344452254442544201223424140243032213101301
|
||||
010202021330012103042021024434411545123253214353525251521434235541535344240243403200122322133122101
|
||||
121102231211003113342040440404003344542241345133131133414435235243325441120032344431223311313111221
|
||||
011210032333020312123124101444102341443212553521355222414135533333310320012002223342012031112321112
|
||||
Loading…
Add table
Add a link
Reference in a new issue