{ "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 }