{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Custom encoding table.\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import string\n", "encoding_table = string.ascii_letters\n", "et_len = len(encoding_table)\n", "\n", "def short_id(value:int) -> str: \n", " t = []\n", " while True:\n", " result = value // et_len\n", " remainder = value - (result * et_len)\n", " value = result\n", " t.append(encoding_table[remainder])\n", " if value == 0:\n", " break\n", " return \"\".join(t[::-1])" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'ApJKSp'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "short_id(9999999999)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.5 ('pages310')", "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.5" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "6f432a2729e41e111fc68229d0303145971e0c11421dc22cdb03f95edd20be36" } } }, "nbformat": 4, "nbformat_minor": 2 }