From 02136326b334b3b37319696e271cb52653cbee5b Mon Sep 17 00:00:00 2001 From: Gianpaolo Macario Date: Wed, 4 Dec 2024 17:55:16 +0000 Subject: [PATCH] wip: gmacario solution for day04 Signed-off-by: Gianpaolo Macario --- .../day04-jupyter/day04-input-gmacario.txt | 140 +++++++ solutions/gmacario/day04-jupyter/day04.ipynb | 347 ++++++++++++++++++ 2 files changed, 487 insertions(+) create mode 100644 solutions/gmacario/day04-jupyter/day04-input-gmacario.txt create mode 100644 solutions/gmacario/day04-jupyter/day04.ipynb diff --git a/solutions/gmacario/day04-jupyter/day04-input-gmacario.txt b/solutions/gmacario/day04-jupyter/day04-input-gmacario.txt new file mode 100644 index 0000000..f3d8fde --- /dev/null +++ b/solutions/gmacario/day04-jupyter/day04-input-gmacario.txt @@ -0,0 +1,140 @@ +SAMMSSSSXSAMXMSMASMMSMSSMMSSXMASMAMMAMSSMSMSAXSSXMXMSASXMSAMXSMMXAMXMMSMSSMXSAMXMMASMSMSMMMAXAAXXASXMMXMSSXMASMMSMXAMSMMMMMAMXSASAMXMMXSAMXM +SAAXAASAASXAAAAAMAAXMAAAMSAAAXAXMAXMSASAASAXAMAMXMSMMAXMAXAMXXAASMSMMAAXXAASASXSXSAMXSAMXAXMSMSMSMMASAMXMSXXAAMSAMMMSMMMAAMAMAXAMXSAMXMAMMAM +SMMMMSMMMMMSMSXSSSSMMMMMMMMSMMASMXXAMXSXMMMMSAMXAMAAMMMAMSSMMSMMSAAXMSSSSMXMAAXSAMXSAMMMMSXXAAAAAAMMMSSMAMMSSMMSASXMAAMSSXSASMMXMASASMAMMMAM +SAAXXMASAXAXMMMXAAXASAXXAMXXXXMMASMXMASAMXXAMSXSSSSSMAXAMXXAAAAAMXMMAAAAXXXMMSAMXMMMMMSAAMXSMSMSMSMMAXXMAXMAMAASXMASXSMAMXSASMSSMASXMXSXSSSS +SSMSSXASXMXSASAMMMMMAAXSAMXXMASMAMMAMXXXMMMMSMXAAMAAXXSSSMSMMSAXSAXASXM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SMSXXXAMMMMASAAMXAXSAMMMXAAAMXXASASMMSXXMAXAAAXMAMMMMMAMAMXSMAMXMMSXMMAAMMMASXMAM +MSMMAMMMMMXAAXMMXAXAXXAAAAXAMXXAXAAAAXAASAMXMAMAAMAMAMASMMAXAMXMAMXAXXAMMSAMXMSASXXSMSMSXMMMASXAAASMMMSMSMSASXASAMMSSSXMASMSMMASMMSSSMMSMXAA +AAAXXMASXSMSSSSMSXSMMMMMMMMSMMMMSXMMSMSMXMXXXSXMXMXMXSXMXXXMAMXMASMSSMSSXMXSXASAMMXAMXMXXAXMXMMMMXMAMXXAXAXAXMAXAASXMMASXMXXASAMMXAAXAMXASMS +SSSMSMASAAAXMMMASMSASASMSMAMAMMXSMMXXAMXAMSMMMXMASXMAMMMMMMSXMXSAAAAAMAMXXAMMMMAMXMMMSASMSMSMMASXMSMMAMMMMMMMSMSSMMASMMMMMSMMMMMSMMSSSMSMMAA +MAAAXMAMMMMMAAMMMASASASAAMASAMAAMASAMSSSXSAAAXASXSAMXSAAAAMMMAAMAMMMSMASMMXSAASAMAAXXMAMMAAAASASAAAAMASAAAAAAAXXAASAMXAAAAAAAXAAAXAAMAMXAMXM +MSMMMMMSAMXSSMSXMMMXMXMMMSMSMSXXSSMXSAMXSSMSMSMSASMMSSMSSSXAXMXSXMASMXMSXXASXMSXMAMSAMXMSXSSXMSSMMMASMSXSSSMSSSSSMMMSXSSSSSSMSMSSSMXSSMSMMAX diff --git a/solutions/gmacario/day04-jupyter/day04.ipynb b/solutions/gmacario/day04-jupyter/day04.ipynb new file mode 100644 index 0000000..02d065e --- /dev/null +++ b/solutions/gmacario/day04-jupyter/day04.ipynb @@ -0,0 +1,347 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e8c36490-ac44-4e4f-9fc3-97d15fbef673", + "metadata": {}, + "source": [ + "# AoC 2024 - Day 4\n", + "\n", + "" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "6b7c6dc6-b77c-47e0-ac97-33f7f86c484c", + "metadata": {}, + "outputs": [], + "source": [ + "from icecream import ic" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "8c9a122d-1ba9-4bfd-b131-ee8e69c7d09f", + "metadata": {}, + "outputs": [], + "source": [ + "movements = {\n", + " \"N\": ( 0, 1), # Move UP\n", + " \"S\": ( 0, -1), # Move DOWN\n", + " \"E\": ( 1, 0), # Move EAST\n", + " \"W\": (-1, 0), # Move WEST\n", + " \"NE\": ( 1, 1),\n", + " \"NW\": (-1, 1),\n", + " \"SE\": ( 1, -1),\n", + " \"SW\": (-1, -1),\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "992b746b-12f1-4576-ae26-f3c5d379c844", + "metadata": {}, + "outputs": [], + "source": [ + "def find_word_across(word, board, position, orientation):\n", + " \"\"\"\n", + " position: (x, y) - (0, 0) is lower left\n", + " \n", + " Return 1 if word was found, otherwise 0\n", + " \"\"\"\n", + " \n", + " # ic(word, board, position, orientation)\n", + "\n", + " height = len(board)\n", + " width = len(board[0])\n", + " \n", + " assert position[0] >= 0 and position[0] < width, f\"{ic(word, board, position)}\"\n", + " assert position[1] >= 0 and position[1] < height, f\"{ic(word, board, position)}\"\n", + "\n", + " pos = list(position)\n", + " for char in word:\n", + " # ic(pos, char)\n", + " board_char = board[height - pos[1] - 1][pos[0]]\n", + " if board_char != char:\n", + " # ic(f\"DEBUG: Unmatch {char} and {board_char} at {pos}\")\n", + " return 0\n", + " # Advance to next character\n", + " move = movements[orientation]\n", + " # ic(\"Advance of\", move)\n", + " pos[0] += move[0]\n", + " if pos[0] < 0 or pos[0] >= width:\n", + " return 0\n", + " pos[1] += move[1]\n", + " if pos[1] < 0 or pos[1] >= height:\n", + " return 0\n", + "\n", + " ic(f\"DEBUG: {word} match starting at {position}, orientation={orientation}\")\n", + " return 1" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "2672708d-3eec-4410-80bd-2e5cb40f6ab3", + "metadata": {}, + "outputs": [], + "source": [ + "def find_word_at(word, board, position):\n", + " \"\"\"\n", + " Find a word on board starting at coordinate position=(x,y)\n", + " \n", + " position: (x, y) - (0, 0) is lower left\n", + " \n", + " Return number of occurrencies found\n", + " \"\"\"\n", + " \n", + " # ic(word, board, position)\n", + "\n", + " total = 0\n", + " total += find_word_across(word, board, position, \"N\")\n", + " total += find_word_across(word, board, position, \"S\")\n", + " total += find_word_across(word, board, position, \"E\")\n", + " total += find_word_across(word, board, position, \"W\")\n", + " total += find_word_across(word, board, position, \"NE\")\n", + " total += find_word_across(word, board, position, \"NW\")\n", + " total += find_word_across(word, board, position, \"SE\")\n", + " total += find_word_across(word, board, position, \"SW\")\n", + " \n", + " return total" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "8d23c8b5-785f-4bfb-8702-f16a064d607b", + "metadata": {}, + "outputs": [], + "source": [ + "def find_word_in_board(word, board):\n", + " \"\"\"\n", + " Find a word on board\n", + " Return number of occurrencies found\n", + " \"\"\"\n", + "\n", + " # ic()\n", + " # ic(word, board)\n", + "\n", + " total = 0\n", + " height = len(board)\n", + " width = len(board[0])\n", + "\n", + " ic(width, height)\n", + " for x in range(width):\n", + " for y in range(height):\n", + " total += find_word_at(word, board, (x, y))\n", + "\n", + " return total" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "a8c2b044-3430-42b6-bb94-95d56950bd2c", + "metadata": {}, + "outputs": [], + "source": [ + "test1 = \"\"\"..X...\n", + ".SAMX.\n", + ".A..A.\n", + "XMAS.S\n", + ".X....\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "96c152a4-182b-463e-8dcc-42b20ab9916a", + "metadata": {}, + "outputs": [], + "source": [ + "test2 = \"\"\"MMMSXXMASM\n", + "MSAMXMSMSA\n", + "AMXSXMAAMM\n", + "MSAMASMSMX\n", + "XMASAMXAMM\n", + "XXAMMXXAMA\n", + "SMSMSASXSS\n", + "SAXAMASAAA\n", + "MAMMMXMMMM\n", + "MXMXAXMASX\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "9cf5cd67-c278-4037-8002-bc6b9308193d", + "metadata": {}, + "outputs": [], + "source": [ + "checkerboard = list()\n", + "\n", + "FILENAME = \"day04-input-gmacario.txt\"\n", + "\n", + "with open(FILENAME, 'r') as file:\n", + " input_text = file.read()\n", + "\n", + "# input_text = test1 # DEBUG\n", + "input_text = test2 # DEBUG\n", + "# ic(input_text)\n", + "\n", + "lineno = 0\n", + "for line in input_text.splitlines():\n", + " lineno += 1\n", + " # ic(lineno, line)\n", + " checkerboard.append(list(line))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "fb02256a-b564-4242-9635-6f6e276a9577", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "# Sanity Checks\n", + "\n", + "# ic(checkerboard)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "7fe4596c-be12-4002-824a-3836cb351d5c", + "metadata": {}, + "outputs": [], + "source": [ + "# test1\n", + "#\n", + "# find_word_across(\"XMAS\", checkerboard, (0,1), \"E\")\n", + "#\n", + "# find_word_at(\"XMAS\", checkerboard, (1,0))" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "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" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# test2\n", + "#\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", + "#\n", + "# find_word_at(\"XMAS\", checkerboard, (9,9))\n", + "# find_word_at(\"XMAS\", checkerboard, (5,9))" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "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" + ] + }, + { + "data": { + "text/plain": [ + "17" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "find_word_in_board(\"XMAS\", checkerboard)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b646299e-fb4e-4b39-bd1e-cf0a15421ebe", + "metadata": { + "collapsed": true, + "jupyter": { + "outputs_hidden": true + } + }, + "outputs": [], + "source": [] + } + ], + "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.11.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}