Skip to content

Commit

Permalink
fix: gmacario day04 Part 1 solved
Browse files Browse the repository at this point in the history
Signed-off-by: Gianpaolo Macario <[email protected]>
  • Loading branch information
gmacario committed Dec 4, 2024
1 parent 0213632 commit f68e67e
Showing 1 changed file with 26 additions and 43 deletions.
69 changes: 26 additions & 43 deletions solutions/gmacario/day04-jupyter/day04.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 29,
"id": "992b746b-12f1-4576-ae26-f3c5d379c844",
"metadata": {},
"outputs": [],
Expand All @@ -62,7 +62,7 @@
" assert position[1] >= 0 and position[1] < height, f\"{ic(word, board, position)}\"\n",
"\n",
" pos = list(position)\n",
" for char in word:\n",
" for char in word[:-1]:\n",
" # ic(pos, char)\n",
" board_char = board[height - pos[1] - 1][pos[0]]\n",
" if board_char != char:\n",
Expand All @@ -78,13 +78,19 @@
" if pos[1] < 0 or pos[1] >= height:\n",
" return 0\n",
"\n",
" ic(f\"DEBUG: {word} match starting at {position}, orientation={orientation}\")\n",
" # Check last\n",
" board_char = board[height - pos[1] - 1][pos[0]]\n",
" if board_char != word[-1:]:\n",
" # ic(f\"DEBUG: Unmatch {char} and {board_char} at {pos}\")\n",
" return 0\n",
" \n",
" # ic(f\"DEBUG: {word} match starting at {position}, orientation={orientation}\")\n",
" return 1"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 30,
"id": "2672708d-3eec-4410-80bd-2e5cb40f6ab3",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -115,7 +121,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 31,
"id": "8d23c8b5-785f-4bfb-8702-f16a064d607b",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -143,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 32,
"id": "a8c2b044-3430-42b6-bb94-95d56950bd2c",
"metadata": {},
"outputs": [],
Expand All @@ -158,7 +164,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 33,
"id": "96c152a4-182b-463e-8dcc-42b20ab9916a",
"metadata": {},
"outputs": [],
Expand All @@ -178,7 +184,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 39,
"id": "9cf5cd67-c278-4037-8002-bc6b9308193d",
"metadata": {},
"outputs": [],
Expand All @@ -191,7 +197,7 @@
" input_text = file.read()\n",
"\n",
"# input_text = test1 # DEBUG\n",
"input_text = test2 # DEBUG\n",
"# input_text = test2 # DEBUG\n",
"# ic(input_text)\n",
"\n",
"lineno = 0\n",
Expand All @@ -203,7 +209,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 40,
"id": "fb02256a-b564-4242-9635-6f6e276a9577",
"metadata": {
"scrolled": true
Expand All @@ -217,7 +223,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 41,
"id": "7fe4596c-be12-4002-824a-3836cb351d5c",
"metadata": {},
"outputs": [],
Expand All @@ -231,76 +237,53 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 42,
"id": "db67d781-8902-44a2-97c3-d9402a8686eb",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (9, 6), orientation=S'\n"
]
},
{
"data": {
"text/plain": [
"1"
"0"
]
},
"execution_count": 11,
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# test2\n",
"#\n",
"find_word_across(\"XMAS\", checkerboard, (3,0), \"NW\")\n",
"# find_word_across(\"XMAS\", checkerboard, (9,6), \"S\")\n",
"# find_word_across(\"XMAS\", checkerboard, (5,9), \"E\")\n",
"find_word_across(\"XMAS\", checkerboard, (9,6), \"S\")\n",
"# find_word_across(\"XMAS\", checkerboard, (9,6), \"S\")\n",
"#\n",
"# find_word_at(\"XMAS\", checkerboard, (9,9))\n",
"# find_word_at(\"XMAS\", checkerboard, (5,9))"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 43,
"id": "f3764b52-eec3-44b4-baee-90fff6e6a837",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ic| width: 10, height: 10\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (0, 4), orientation=NE'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (0, 5), orientation=E'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (1, 0), orientation=NE'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (3, 0), orientation=NE'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (4, 8), orientation=W'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (4, 9), orientation=SE'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (5, 0), orientation=E'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (5, 0), orientation=NE'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (5, 0), orientation=NW'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (5, 9), orientation=E'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (6, 4), orientation=NW'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (6, 5), orientation=N'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (6, 5), orientation=W'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (9, 0), orientation=N'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (9, 0), orientation=NW'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (9, 6), orientation=S'\n",
"ic| f\"DEBUG: {word} match starting at {position}, orientation={orientation}\": 'DEBUG: XMAS match starting at (9, 6), orientation=SW'\n"
"ic| width: 140, height: 140\n"
]
},
{
"data": {
"text/plain": [
"17"
"2642"
]
},
"execution_count": 12,
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
Expand Down

0 comments on commit f68e67e

Please sign in to comment.