From 2ce32dce7d4d5329b99ec8d95f2e4c1f023a7a09 Mon Sep 17 00:00:00 2001 From: Stefan Hilts Date: Tue, 22 Dec 2020 14:13:45 -0500 Subject: [PATCH] Day 21 --- Advent of Code 2020 - 21.ipynb | 213 +++++++++++++++++++++++++++++++++ Problem 21 Input.txt | 40 +++++++ 2 files changed, 253 insertions(+) create mode 100644 Advent of Code 2020 - 21.ipynb create mode 100644 Problem 21 Input.txt diff --git a/Advent of Code 2020 - 21.ipynb b/Advent of Code 2020 - 21.ipynb new file mode 100644 index 0000000..3ee72f7 --- /dev/null +++ b/Advent of Code 2020 - 21.ipynb @@ -0,0 +1,213 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "import math" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "with open(r'C:\\Users\\stefa\\OneDrive\\Documents\\Python Scripts\\Problem 21 Input.txt') as f:\n", + " lines = f.read().split('\\n')\n", + "lines = lines[:-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Part 1" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [], + "source": [ + "for x in range(len(lines)):\n", + " lines[x] = lines[x].replace('peanuts', 'peanuds')\n", + " lines[x] = lines[x].replace('shellfish', 'shellfist')\n" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [], + "source": [ + "ing_list =[]\n", + "aller_list = []\n", + "\n", + "for line in lines:\n", + " \n", + " ingred = line.split(\" (contains \")[0]\n", + " aller = line.split(\" (contains \")[1][:-1]\n", + " for x in ingred.split(\" \"):\n", + " ing_list.append(x)\n", + " for y in aller.split(\", \"):\n", + " aller_list.append(y)\n", + "ing_list = list(set(ing_list))\n", + "aller_list = list(set(aller_list))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'fish': 'vhkj',\n", + " 'soy': 'dfzqlk',\n", + " 'peanuds': 'tvdvzd',\n", + " 'dairy': 'smfz',\n", + " 'sesame': 'lcb',\n", + " 'shellfist': 'lrqqqsg',\n", + " 'nuts': 'qzlmr',\n", + " 'wheat': 'shp'}" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "aller_dict = {}\n", + "while len(aller_dict)