Python Jupyter Day 4

This commit is contained in:
Tobias Berger 2020-11-22 17:58:31 +01:00
parent 19417310a3
commit 875dd911b7
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
2 changed files with 113 additions and 0 deletions

1
Python/day4/input Normal file
View file

@ -0,0 +1 @@
yzbqklnj

112
Python/day4/solution.ipynb Normal file
View file

@ -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)"
]
}
]
}