From 875dd911b7af765038e333a41156169e2a76db97 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Sun, 22 Nov 2020 17:58:31 +0100 Subject: [PATCH] Python Jupyter Day 4 --- Python/day4/input | 1 + Python/day4/solution.ipynb | 112 +++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 Python/day4/input create mode 100644 Python/day4/solution.ipynb diff --git a/Python/day4/input b/Python/day4/input new file mode 100644 index 0000000..203cf7c --- /dev/null +++ b/Python/day4/input @@ -0,0 +1 @@ +yzbqklnj \ No newline at end of file diff --git a/Python/day4/solution.ipynb b/Python/day4/solution.ipynb new file mode 100644 index 0000000..a1a0dad --- /dev/null +++ b/Python/day4/solution.ipynb @@ -0,0 +1,112 @@ +{ + "metadata": { + "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.8.6-final" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "python3", + "display_name": "Python 3.8.6 64-bit", + "metadata": { + "interpreter": { + "hash": "1ddf53fa84779e14f0db18342168679c9c165a81c5f324dac828befab228d68d" + } + } + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import hashlib" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# Get puzzle input from input file\n", + "\n", + "puzzle_input = open(\"input\").read()" + ] + }, + { + "source": [ + "# Part 1 #" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "282749\n" + ] + } + ], + "source": [ + "current_hash = \"\"\n", + "i = 0\n", + "while not current_hash[0:5] == \"00000\":\n", + " i += 1\n", + " md5 = hashlib.md5(f\"{puzzle_input}{i}\".encode(\"utf-8\"))\n", + " current_hash = md5.hexdigest()\n", + "print(i)" + ] + }, + { + "source": [ + "# Part 2 #" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "9962624\n" + ] + } + ], + "source": [ + "current_hash = \"\"\n", + "i = 0\n", + "while not current_hash[0:6] == \"000000\":\n", + " i += 1\n", + " md5 = hashlib.md5(f\"{puzzle_input}{i}\".encode(\"utf-8\"))\n", + " current_hash = md5.hexdigest()\n", + "print(i)" + ] + } + ] +} \ No newline at end of file