{ "cells": [ { "cell_type": "code", "execution_count": 21, "id": "falling-shipping", "metadata": {}, "outputs": [], "source": [ "import hashlib\n", "\n", "def mine(key, zeros=5):\n", " key = key.encode()\n", " n = 0\n", " z = '0' * zeros\n", " while True:\n", " n += 1\n", " nb = str(n).encode()\n", " hex = hashlib.md5(key + nb).hexdigest()\n", " if hex.startswith(z):\n", " return n" ] }, { "cell_type": "code", "execution_count": 22, "id": "immediate-movement", "metadata": {}, "outputs": [], "source": [ "assert mine('abcdef', 5) == 609043\n", "assert mine('pqrstuv', 5) == 1048970" ] }, { "cell_type": "code", "execution_count": 23, "id": "respective-eagle", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "282749" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mine('yzbqklnj', 5)" ] }, { "cell_type": "code", "execution_count": 24, "id": "hourly-hostel", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "9962624" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mine('yzbqklnj', 6)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.9.2" }, "title": "The Ideal Stocking Stuffer" }, "nbformat": 4, "nbformat_minor": 5 }