From 7d523fe68e50b438672a0454e26b18a379c79f1f Mon Sep 17 00:00:00 2001 From: Arun B John <108453263+kRonos2455@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:59:52 +0530 Subject: [PATCH] my solution for day 7 question 21 --- notebooks/Day_07.ipynb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/notebooks/Day_07.ipynb b/notebooks/Day_07.ipynb index f74f65a..beac616 100644 --- a/notebooks/Day_07.ipynb +++ b/notebooks/Day_07.ipynb @@ -148,6 +148,47 @@ "print(dist)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "Solution by: kRonos2455\n", + "\"\"\"\n", + "movements = {\n", + " 'UPPER': [], \n", + " 'DOWN': [], \n", + " 'LEFT': [], \n", + " 'RIGHT': []\n", + "}\n", + "\n", + "while True:\n", + " moves = input()\n", + " if moves=='' or moves=='q' or moves=='Q':\n", + " break\n", + " else:\n", + " dir = moves.split()[0].strip().upper()\n", + " steps = int(moves.split()[1].strip())\n", + " match dir:\n", + " case 'UPPER': \n", + " movements[dir].append(steps)\n", + " case 'DOWN': \n", + " movements[dir].append(steps)\n", + " case 'LEFT': \n", + " movements[dir].append(steps)\n", + " case 'RIGHT': \n", + " movements[dir].append(steps)\n", + " case _:\n", + " print(\"Invalid entry\")\n", + " continue\n", + "\n", + "y = sum(movements['UPPER'])-sum(movements['DOWN'])\n", + "x = sum(movements['RIGHT'])-sum(movements['LEFT'])\n", + "print(((x**2+y**2)**0.5)//1)" + ] + }, { "cell_type": "markdown", "metadata": {},