Skip to content

Instantly share code, notes, and snippets.

@davidblitz
Created April 28, 2020 19:08
Show Gist options
  • Save davidblitz/32cf07cd55cf485ea7f7d568c34d0604 to your computer and use it in GitHub Desktop.
Save davidblitz/32cf07cd55cf485ea7f7d568c34d0604 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from itertools import groupby"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def lookandsay(number):\n",
" return ''.join( str(len(list(g))) + k\n",
" for k,g in groupby(number) )"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Iteration: 0 Element: 1 Digitsum: 1\n",
"Iteration: 1 Element: 11 Digitsum: 2\n",
"Iteration: 2 Element: 21 Digitsum: 3\n",
"Iteration: 3 Element: 1211 Digitsum: 5\n",
"Iteration: 4 Element: 111221 Digitsum: 8\n",
"Iteration: 5 Element: 312211 Digitsum: 10\n",
"Iteration: 6 Element: 13112221 Digitsum: 13\n",
"Iteration: 7 Element: 1113213211 Digitsum: 16\n",
"Iteration: 8 Element: 31131211131221 Digitsum: 23\n",
"Iteration: 9 Element: 13211311123113112211 Digitsum: 32\n",
"Iteration: 10 Element: 11131221133112132113212221 Digitsum: 44\n",
"Iteration: 11 Element: 3113112221232112111312211312113211 Digitsum: 56\n",
"Iteration: 12 Element: 1321132132111213122112311311222113111221131221 Digitsum: 76\n",
"Iteration: 13 Element: 11131221131211131231121113112221121321132132211331222113112211 Digitsum: 102\n",
"Iteration: 14 Element: 311311222113111231131112132112311321322112111312211312111322212311322113212221 Digitsum: 132\n",
"Iteration: 15 Element: 132113213221133112132113311211131221121321131211132221123113112221131112311332111213211322211312113211 Digitsum: 174\n",
"Iteration: 16 Element: 11131221131211132221232112111312212321123113112221121113122113111231133221121321132132211331121321231231121113122113322113111221131221 Digitsum: 227\n",
"Iteration: 17 Element: 31131122211311123113321112131221123113112211121312211213211321322112311311222113311213212322211211131221131211132221232112111312111213111213211231131122212322211331222113112211 Digitsum: 296\n",
"Iteration: 18 Element: 1321132132211331121321231231121113112221121321132122311211131122211211131221131211132221121321132132212321121113121112133221123113112221131112311332111213122112311311123112111331121113122112132113213211121332212311322113212221 Digitsum: 383\n",
"Iteration: 19 Element: 11131221131211132221232112111312111213111213211231132132211211131221131211221321123113213221123113112221131112311332211211131221131211132211121312211231131112311211232221121321132132211331121321231231121113112221121321133112132112312321123113112221121113122113121113123112112322111213211322211312113211 Digitsum: 505\n"
]
}
],
"source": [
"numberstring='1'\n",
"ds = 1\n",
"last_ds = 1\n",
"l=1\n",
"for i in range(20):\n",
" print(\"Iteration:\", i, 'Element:', numberstring, 'Digitsum:', sum([int(k) for k in list(numberstring)]))\n",
" before_last_ds = last_ds\n",
" last_ds = ds\n",
" ds = sum([int(k) for k in list(numberstring)])\n",
" last_l = l\n",
" l = len(numberstring)\n",
" #print(\"Iteration:\", i, 'Length:', l, 'Length Quotient:', l/last_l, 'Digitsum:', ds, 'Digitsum Quotient:', ds / last_ds)\n",
" #|print(\"Iteration:\", i, 'Digitsum/Length Quotient:', before_last_ds / l)\n",
" numberstring = lookandsay(numberstring)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Iteration: 0 Length: 1 Length Quotient: 1.0 Digitsum: 1 Digitsum Quotient: 1.0\n",
"Iteration: 1 Length: 2 Length Quotient: 2.0 Digitsum: 2 Digitsum Quotient: 2.0\n",
"Iteration: 2 Length: 2 Length Quotient: 1.0 Digitsum: 3 Digitsum Quotient: 1.5\n",
"Iteration: 3 Length: 4 Length Quotient: 2.0 Digitsum: 5 Digitsum Quotient: 1.6666666666666667\n",
"Iteration: 4 Length: 6 Length Quotient: 1.5 Digitsum: 8 Digitsum Quotient: 1.6\n",
"Iteration: 5 Length: 6 Length Quotient: 1.0 Digitsum: 10 Digitsum Quotient: 1.25\n",
"Iteration: 6 Length: 8 Length Quotient: 1.3333333333333333 Digitsum: 13 Digitsum Quotient: 1.3\n",
"Iteration: 7 Length: 10 Length Quotient: 1.25 Digitsum: 16 Digitsum Quotient: 1.2307692307692308\n",
"Iteration: 8 Length: 14 Length Quotient: 1.4 Digitsum: 23 Digitsum Quotient: 1.4375\n",
"Iteration: 9 Length: 20 Length Quotient: 1.4285714285714286 Digitsum: 32 Digitsum Quotient: 1.391304347826087\n",
"Iteration: 10 Length: 26 Length Quotient: 1.3 Digitsum: 44 Digitsum Quotient: 1.375\n",
"Iteration: 11 Length: 34 Length Quotient: 1.3076923076923077 Digitsum: 56 Digitsum Quotient: 1.2727272727272727\n",
"Iteration: 12 Length: 46 Length Quotient: 1.3529411764705883 Digitsum: 76 Digitsum Quotient: 1.3571428571428572\n",
"Iteration: 13 Length: 62 Length Quotient: 1.3478260869565217 Digitsum: 102 Digitsum Quotient: 1.3421052631578947\n",
"Iteration: 14 Length: 78 Length Quotient: 1.2580645161290323 Digitsum: 132 Digitsum Quotient: 1.2941176470588236\n",
"Iteration: 15 Length: 102 Length Quotient: 1.3076923076923077 Digitsum: 174 Digitsum Quotient: 1.3181818181818181\n",
"Iteration: 16 Length: 134 Length Quotient: 1.3137254901960784 Digitsum: 227 Digitsum Quotient: 1.3045977011494252\n",
"Iteration: 17 Length: 176 Length Quotient: 1.3134328358208955 Digitsum: 296 Digitsum Quotient: 1.303964757709251\n",
"Iteration: 18 Length: 226 Length Quotient: 1.2840909090909092 Digitsum: 383 Digitsum Quotient: 1.2939189189189189\n",
"Iteration: 19 Length: 302 Length Quotient: 1.336283185840708 Digitsum: 505 Digitsum Quotient: 1.318537859007833\n",
"Iteration: 20 Length: 408 Length Quotient: 1.3509933774834437 Digitsum: 679 Digitsum Quotient: 1.3445544554455446\n",
"Iteration: 21 Length: 528 Length Quotient: 1.2941176470588236 Digitsum: 892 Digitsum Quotient: 1.3136966126656848\n",
"Iteration: 22 Length: 678 Length Quotient: 1.2840909090909092 Digitsum: 1151 Digitsum Quotient: 1.2903587443946187\n",
"Iteration: 23 Length: 904 Length Quotient: 1.3333333333333333 Digitsum: 1516 Digitsum Quotient: 1.317115551694179\n",
"Iteration: 24 Length: 1182 Length Quotient: 1.3075221238938053 Digitsum: 1988 Digitsum Quotient: 1.3113456464379947\n",
"Iteration: 25 Length: 1540 Length Quotient: 1.3028764805414552 Digitsum: 2602 Digitsum Quotient: 1.3088531187122736\n",
"Iteration: 26 Length: 2012 Length Quotient: 1.3064935064935066 Digitsum: 3400 Digitsum Quotient: 1.3066871637202153\n",
"Iteration: 27 Length: 2606 Length Quotient: 1.2952286282306162 Digitsum: 4410 Digitsum Quotient: 1.2970588235294118\n",
"Iteration: 28 Length: 3410 Length Quotient: 1.308518802762855 Digitsum: 5759 Digitsum Quotient: 1.3058956916099773\n",
"Iteration: 29 Length: 4462 Length Quotient: 1.3085043988269796 Digitsum: 7519 Digitsum Quotient: 1.3056086126063553\n",
"Iteration: 30 Length: 5808 Length Quotient: 1.3016584491259524 Digitsum: 9809 Digitsum Quotient: 1.3045617768320255\n",
"Iteration: 31 Length: 7586 Length Quotient: 1.3061294765840221 Digitsum: 12810 Digitsum Quotient: 1.3059435212559893\n",
"Iteration: 32 Length: 9898 Length Quotient: 1.3047719483258635 Digitsum: 16710 Digitsum Quotient: 1.3044496487119437\n",
"Iteration: 33 Length: 12884 Length Quotient: 1.3016771064861588 Digitsum: 21758 Digitsum Quotient: 1.3020945541591862\n",
"Iteration: 34 Length: 16774 Length Quotient: 1.3019248680533995 Digitsum: 28356 Digitsum Quotient: 1.3032447835278977\n",
"Iteration: 35 Length: 21890 Length Quotient: 1.3049958268749255 Digitsum: 36955 Digitsum Quotient: 1.3032515164339118\n",
"Iteration: 36 Length: 28528 Length Quotient: 1.3032434901781635 Digitsum: 48189 Digitsum Quotient: 1.3039913408199162\n",
"Iteration: 37 Length: 37158 Length Quotient: 1.3025098149186765 Digitsum: 62805 Digitsum Quotient: 1.30330573367366\n",
"Iteration: 38 Length: 48410 Length Quotient: 1.302815006189784 Digitsum: 81803 Digitsum Quotient: 1.3024918398216703\n",
"Iteration: 39 Length: 63138 Length Quotient: 1.3042346622598637 Digitsum: 106647 Digitsum Quotient: 1.3037052430839944\n",
"Iteration: 40 Length: 82350 Length Quotient: 1.3042858500427634 Digitsum: 139088 Digitsum Quotient: 1.3041904601160839\n",
"Iteration: 41 Length: 107312 Length Quotient: 1.3031208257437765 Digitsum: 181301 Digitsum Quotient: 1.3034985045438858\n",
"Iteration: 42 Length: 139984 Length Quotient: 1.3044580289250036 Digitsum: 236453 Digitsum Quotient: 1.3042013005995554\n",
"Iteration: 43 Length: 182376 Length Quotient: 1.3028346096696766 Digitsum: 308150 Digitsum Quotient: 1.30321882149941\n",
"Iteration: 44 Length: 237746 Length Quotient: 1.303603544326008 Digitsum: 401689 Digitsum Quotient: 1.3035502190491643\n",
"Iteration: 45 Length: 310036 Length Quotient: 1.3040640010767794 Digitsum: 523719 Digitsum Quotient: 1.3037922372780932\n",
"Iteration: 46 Length: 403966 Length Quotient: 1.302964816988995 Digitsum: 682571 Digitsum Quotient: 1.3033153274943243\n",
"Iteration: 47 Length: 526646 Length Quotient: 1.3036889243154126 Digitsum: 889807 Digitsum Quotient: 1.3036109064112011\n",
"Iteration: 48 Length: 686646 Length Quotient: 1.303809389988721 Digitsum: 1159977 Digitsum Quotient: 1.3036276406007146\n",
"Iteration: 49 Length: 894810 Length Quotient: 1.3031605805611626 Digitsum: 1511915 Digitsum Quotient: 1.3034008432925825\n",
"Iteration: 50 Length: 1166642 Length Quotient: 1.3037873962070161 Digitsum: 1970964 Digitsum Quotient: 1.3036209046143468\n",
"Iteration: 51 Length: 1520986 Length Quotient: 1.3037298502882633 Digitsum: 2569494 Digitsum Quotient: 1.3036737352889247\n",
"Iteration: 52 Length: 1982710 Length Quotient: 1.3035688691414649 Digitsum: 3349648 Digitsum Quotient: 1.3036216469079127\n",
"Iteration: 53 Length: 2584304 Length Quotient: 1.3034200664746736 Digitsum: 4366359 Digitsum Quotient: 1.3035277139568098\n",
"Iteration: 54 Length: 3369156 Length Quotient: 1.3036995647570875 Digitsum: 5691884 Digitsum Quotient: 1.3035767329255337\n",
"Iteration: 55 Length: 4391702 Length Quotient: 1.303502123380455 Digitsum: 7419702 Digitsum Quotient: 1.3035581891689991\n",
"Iteration: 56 Length: 5724486 Length Quotient: 1.303477786061076 Digitsum: 9671795 Digitsum Quotient: 1.3035287670582996\n",
"Iteration: 57 Length: 7462860 Length Quotient: 1.3036733778368923 Digitsum: 12608013 Digitsum Quotient: 1.3035856322430324\n",
"Iteration: 58 Length: 9727930 Length Quotient: 1.303512326373535 Digitsum: 16435261 Digitsum Quotient: 1.3035567936041945\n",
"Iteration: 59 Length: 12680852 Length Quotient: 1.303550909597417 Digitsum: 21424450 Digitsum Quotient: 1.3035661557184883\n"
]
}
],
"source": [
"numberstring='1'\n",
"ds = 1\n",
"last_ds = 1\n",
"l=1\n",
"for i in range(60):\n",
" #print(\"Iteration:\", i, 'Element:', numberstring, 'Digitsum:', sum([int(k) for k in list(numberstring)]))\n",
" before_last_ds = last_ds\n",
" last_ds = ds\n",
" ds = sum([int(k) for k in list(numberstring)])\n",
" last_l = l\n",
" l = len(numberstring)\n",
" print(\"Iteration:\", i, 'Length:', l, 'Length Quotient:', l/last_l, 'Digitsum:', ds, 'Digitsum Quotient:', ds / last_ds)\n",
" #print(\"Iteration:\", i, 'Digitsum/Length Quotient:', before_last_ds / l)\n",
" numberstring = lookandsay(numberstring)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Iteration: 0 ((Before Last Digitsum)/(Length)) Quotient: 1.0\n",
"Iteration: 1 ((Before Last Digitsum)/(Length)) Quotient: 0.5\n",
"Iteration: 2 ((Before Last Digitsum)/(Length)) Quotient: 0.5\n",
"Iteration: 3 ((Before Last Digitsum)/(Length)) Quotient: 0.5\n",
"Iteration: 4 ((Before Last Digitsum)/(Length)) Quotient: 0.5\n",
"Iteration: 5 ((Before Last Digitsum)/(Length)) Quotient: 0.8333333333333334\n",
"Iteration: 6 ((Before Last Digitsum)/(Length)) Quotient: 1.0\n",
"Iteration: 7 ((Before Last Digitsum)/(Length)) Quotient: 1.0\n",
"Iteration: 8 ((Before Last Digitsum)/(Length)) Quotient: 0.9285714285714286\n",
"Iteration: 9 ((Before Last Digitsum)/(Length)) Quotient: 0.8\n",
"Iteration: 10 ((Before Last Digitsum)/(Length)) Quotient: 0.8846153846153846\n",
"Iteration: 11 ((Before Last Digitsum)/(Length)) Quotient: 0.9411764705882353\n",
"Iteration: 12 ((Before Last Digitsum)/(Length)) Quotient: 0.9565217391304348\n",
"Iteration: 13 ((Before Last Digitsum)/(Length)) Quotient: 0.9032258064516129\n",
"Iteration: 14 ((Before Last Digitsum)/(Length)) Quotient: 0.9743589743589743\n",
"Iteration: 15 ((Before Last Digitsum)/(Length)) Quotient: 1.0\n",
"Iteration: 16 ((Before Last Digitsum)/(Length)) Quotient: 0.9850746268656716\n",
"Iteration: 17 ((Before Last Digitsum)/(Length)) Quotient: 0.9886363636363636\n",
"Iteration: 18 ((Before Last Digitsum)/(Length)) Quotient: 1.0044247787610618\n",
"Iteration: 19 ((Before Last Digitsum)/(Length)) Quotient: 0.9801324503311258\n",
"Iteration: 20 ((Before Last Digitsum)/(Length)) Quotient: 0.9387254901960784\n",
"Iteration: 21 ((Before Last Digitsum)/(Length)) Quotient: 0.9564393939393939\n",
"Iteration: 22 ((Before Last Digitsum)/(Length)) Quotient: 1.0014749262536873\n",
"Iteration: 23 ((Before Last Digitsum)/(Length)) Quotient: 0.9867256637168141\n",
"Iteration: 24 ((Before Last Digitsum)/(Length)) Quotient: 0.9737732656514383\n",
"Iteration: 25 ((Before Last Digitsum)/(Length)) Quotient: 0.9844155844155844\n",
"Iteration: 26 ((Before Last Digitsum)/(Length)) Quotient: 0.9880715705765407\n",
"Iteration: 27 ((Before Last Digitsum)/(Length)) Quotient: 0.9984650805832693\n",
"Iteration: 28 ((Before Last Digitsum)/(Length)) Quotient: 0.9970674486803519\n",
"Iteration: 29 ((Before Last Digitsum)/(Length)) Quotient: 0.9883460331689825\n",
"Iteration: 30 ((Before Last Digitsum)/(Length)) Quotient: 0.9915633608815427\n",
"Iteration: 31 ((Before Last Digitsum)/(Length)) Quotient: 0.991167940943844\n",
"Iteration: 32 ((Before Last Digitsum)/(Length)) Quotient: 0.9910082845019196\n",
"Iteration: 33 ((Before Last Digitsum)/(Length)) Quotient: 0.9942564420987271\n",
"Iteration: 34 ((Before Last Digitsum)/(Length)) Quotient: 0.9961845713604388\n",
"Iteration: 35 ((Before Last Digitsum)/(Length)) Quotient: 0.9939698492462311\n",
"Iteration: 36 ((Before Last Digitsum)/(Length)) Quotient: 0.9939708356702187\n",
"Iteration: 37 ((Before Last Digitsum)/(Length)) Quotient: 0.9945368426718338\n",
"Iteration: 38 ((Before Last Digitsum)/(Length)) Quotient: 0.9954348275149763\n",
"Iteration: 39 ((Before Last Digitsum)/(Length)) Quotient: 0.9947258386391713\n",
"Iteration: 40 ((Before Last Digitsum)/(Length)) Quotient: 0.9933576199149969\n",
"Iteration: 41 ((Before Last Digitsum)/(Length)) Quotient: 0.9938031161473088\n",
"Iteration: 42 ((Before Last Digitsum)/(Length)) Quotient: 0.9935992684878272\n",
"Iteration: 43 ((Before Last Digitsum)/(Length)) Quotient: 0.9941055840680791\n",
"Iteration: 44 ((Before Last Digitsum)/(Length)) Quotient: 0.9945614226948087\n",
"Iteration: 45 ((Before Last Digitsum)/(Length)) Quotient: 0.9939168354642687\n",
"Iteration: 46 ((Before Last Digitsum)/(Length)) Quotient: 0.9943633870177193\n",
"Iteration: 47 ((Before Last Digitsum)/(Length)) Quotient: 0.9944421869718938\n",
"Iteration: 48 ((Before Last Digitsum)/(Length)) Quotient: 0.9940653553650644\n",
"Iteration: 49 ((Before Last Digitsum)/(Length)) Quotient: 0.9944088689218941\n",
"Iteration: 50 ((Before Last Digitsum)/(Length)) Quotient: 0.9942870220684666\n",
"Iteration: 51 ((Before Last Digitsum)/(Length)) Quotient: 0.9940361055262836\n",
"Iteration: 52 ((Before Last Digitsum)/(Length)) Quotient: 0.9940757851627318\n",
"Iteration: 53 ((Before Last Digitsum)/(Length)) Quotient: 0.9942692500572688\n",
"Iteration: 54 ((Before Last Digitsum)/(Length)) Quotient: 0.9942098258436237\n",
"Iteration: 55 ((Before Last Digitsum)/(Length)) Quotient: 0.994229344340759\n",
"Iteration: 56 ((Before Last Digitsum)/(Length)) Quotient: 0.9943048161878638\n",
"Iteration: 57 ((Before Last Digitsum)/(Length)) Quotient: 0.9942169623977939\n",
"Iteration: 58 ((Before Last Digitsum)/(Length)) Quotient: 0.9942295020626176\n",
"Iteration: 59 ((Before Last Digitsum)/(Length)) Quotient: 0.9942559853233837\n"
]
}
],
"source": [
"numberstring='1'\n",
"ds = 1\n",
"last_ds = 1\n",
"l=1\n",
"for i in range(60):\n",
" #print(\"Iteration:\", i, 'Element:', numberstring, 'Digitsum:', sum([int(k) for k in list(numberstring)]))\n",
" before_last_ds = last_ds\n",
" last_ds = ds\n",
" ds = sum([int(k) for k in list(numberstring)])\n",
" last_l = l\n",
" l = len(numberstring)\n",
" #print(\"Iteration:\", i, 'Length:', l, 'Length Quotient:', l/last_l, 'Digitsum:', ds, 'Digitsum Quotient:', ds / last_ds)\n",
" print(\"Iteration:\", i, '((Before Last Digitsum)/(Length)) Quotient:', before_last_ds / l)\n",
" numberstring = lookandsay(numberstring)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment