Skip to content

Instantly share code, notes, and snippets.

@EZLiang
Last active March 23, 2022 19:25
Show Gist options
  • Save EZLiang/28ee46c72d76cae04b4bde53b9f3d376 to your computer and use it in GitHub Desktop.
Save EZLiang/28ee46c72d76cae04b4bde53b9f3d376 to your computer and use it in GitHub Desktop.
Number Synthesizer Plus
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Number Synthesizer"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"_Number Synthesizer_ writes out numbers, e.g. `1001 -> one thousand one`. Its range is from $0$ through $10^{66}-1$, though the upper bound can be extended through trivial modification."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```\n",
"LISENCE FOR NUMBER SYNTHESIZER\n",
"\n",
"COPYRIGHT (c) JANUARY 12 MMXX (2020) C.E.\n",
"BY ``EVIN LIANG\"\n",
"THIS IS ABSOLUTELY FREE SOFTWARE. THIS MAY BE DISTRIBUTED FREELY UNDER THE FOLLOWING TERMS AND CONDITIONS:\n",
"1. AUTHOR SHALL NOT BE LIABLE FOR ANY DAMAGE CAUSED BY THIS PROGRAM\n",
"2. THIS PROGRAM SHALL NOT BE DISTRIBUTED FOR PERSONAL GAIN OR IN A MANNER THAT CUSES PERSONAL GAIN\n",
"3. AUTHOR SHALL NOT BE LIABLE FOR ANY DEFICIENCIES OF THE PROGRAM\n",
"\n",
"BY USING THIS PROGRAM OR DISTRIBUTING PROGAM LISENCEE SHALL AGREE TO THE TERMS AND CONDITIONS:\n",
"[ ] I AGREE TO THE TERMS AND CONDITIONS",
"```\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"_Program now follows_"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"suffixes = [\"\", \"thousand\", \"million\", \"billion\", \"trillion\", \"quadrillion\", \"quintillion\", \"sextillion\", \"septillion\", \"octillion\", \"nonillion\", \"decillion\", \"undecillion\", \"duodecillion\", \"tredecillion\", \"quatturodecillion\", \"quindecillion\", \"sexdecillion\", \"septendecillion\", \"octodecillion\", \"novemdecillion\", \"vingtillion\"]\n",
"numbers = [\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\"]\n",
"teens = [\"ten\", \"eleven\", \"twelve\", \"thirteen\", \"fourteen\", \"fifteen\", \"sixteen\", \"seventeen\", \"eighteen\", \"nineteen\"]\n",
"tens = [\"zero\", \"ten\", \"twenty\", \"thirty\", \"forty\", \"fifty\", \"sixty\", \"seventy\", \"eighty\", \"ninety\"]\n",
"\n",
"def synth2(n):\n",
" if n == 0:\n",
" return \"\"\n",
" elif n < 10:\n",
" return numbers[n]\n",
" elif n < 20:\n",
" return teens[n - 10]\n",
" elif n % 10 == 0:\n",
" return tens[int(n / 10)]\n",
" else:\n",
" u = n % 10\n",
" t = int((n - u) / 10)\n",
" return \"{} {}\".format(tens[t], numbers[u])\n",
"\n",
"def synth3(n):\n",
" if n == 0:\n",
" return \"\"\n",
" elif n < 100:\n",
" return synth2(n)\n",
" elif n % 100 == 0:\n",
" return \"{} hundred\".format(numbers[int(n / 100)])\n",
" else:\n",
" return \"{} hundred {}\".format(numbers[int((n - (n % 100)) / 100)], synth2(n % 100))\n",
"\n",
"def expand(n):\n",
" a = []\n",
" while n:\n",
" a.append(n % 1000)\n",
" n -= a[-1]\n",
" n = int(n / 1000)\n",
" return a\n",
"\n",
"def synthesis(n):\n",
" if n == 0:\n",
" return \"zero\"\n",
" l = expand(n)\n",
" r = []\n",
" for i in range(len(l)):\n",
" if synth3(l[i]):\n",
" r.reverse()\n",
" if i:\n",
" r.append(suffixes[i])\n",
" r.append(synth3(l[i]))\n",
" r.reverse()\n",
" return \" \".join(r)\n"
]
}
],
"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.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
@DotDotJames
Copy link

love this! as kid attempted world record of typing out checkbook numbers one summer this guy definitely stuck with it a lot longer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment