Light Clean up
This commit is contained in:
1 parent
69bf933f03
commit
77c5f531f0
11 files changed
+403
-2394
No files matched your search
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
+28
-72
@@ -2,21 +2,20 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 336,
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"input = r'''0 1 10 99 999'''\n",
|
||||
"input = r'''125 17'''\n",
|
||||
"#input = r'''0 1 10 99 999'''\n",
|
||||
"#input = r'''125 17'''\n",
|
||||
"input = r'''475449 2599064 213 0 2 65 5755 51149'''\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"stones = {int(x):1 for x in input.split()}\n"
|
||||
"stones = {int(x):1 for x in input.split()}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -40,17 +39,29 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"193269"
|
||||
]
|
||||
},
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"for i in range(75):\n",
|
||||
" stones=step(stones)\n"
|
||||
"for i in range(25):\n",
|
||||
" stones=step(stones)\n",
|
||||
"sum(stones.values())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 269,
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -59,77 +70,22 @@
|
||||
"228449040027793"
|
||||
]
|
||||
},
|
||||
"execution_count": 269,
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"stones = {int(x):1 for x in input.split()}\n",
|
||||
"for i in range(75):\n",
|
||||
" stones=step(stones)\n",
|
||||
"sum(stones.values())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 459,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"defaultdict(<class 'int'>, {6072: 673206953446361827286, 4048: 2734962356528935214636, 14168: 1343031271242210938014, 12144: 2300399947749196772879, 32772608: 1863779202753698640740, 40: 1800617350854067786011, 48: 1963004354915731679509, 2024: 1901242329177217918652, 80: 2071514762314577986161, 96: 1909127758252913749300, 16192: 2830947128757671518126, 18216: 1268972356388161972299, 8096: 2899816988343294077917, 10120: 569045306257576076768, 1: 2887855190943409245055, 36869184: 835429087093576428724, 24579456: 1514487337123235977781, 28: 545640724430717426974, 67: 383253720369045854463, 60: 826473730693175762336, 32: 1191095444078885640165, 24: 1908139147880629965130, 57: 656448851778621933102, 94: 656448851778621838017, 56: 656448851778627848108, 3: 1022537248590681705286, 2: 4154202543052785522877, 7: 2039928642914626319453, 6: 3494049803451761028009, 77: 807841723709838053671, 26: 807841723709836079846, 8: 4299935420757677600191, 36: 362115363446705336479, 86: 362115363446702092621, 91: 362115363446699634033, 84: 362115363446704267359, 20: 1414077300163673644677, 0: 4024270438576582418162, 4: 4404541520680163316089, 9: 1927418059972380388541, 72: 443220010324135438919, 28676032: 884207592768322392473, 3277: 1227019168257705602169, 2608: 1227019168257705617679, 20482880: 374644389308688664777, 3686: 550006170363052763461, 9184: 550006170363052763461, 2457: 997052327100450699998, 9456: 997052327100450699998, 5: 864321261489050567651, 2867: 582104108096953186703, 6032: 582104108096953405172, 2048: 246636878600168153652, 2880: 246636878600168153652, 291: 1789758, 151: 342634, 849: 342634, 472: 1844850, 7644: 902465, 6480: 902465, 8717: 902465, 7728: 902465, 7827: 1013758, 104: 2102093, 277518444544: 1013758, 485: 1329398, 760: 2384941, 848: 1206102, 3490282752: 24893, 582: 978569, 912: 1136525, 383: 139159, 177: 64484, 332: 546023, 736: 924747, 514096: 1532150, 902704: 709670, 1068672: 1538929, 1036288: 1746323, 7296: 827680, 3176: 685472, 355910522880: 685472, 36459: 399206, 52640: 399206, 22940: 4557788, 82560: 4557788, 26750: 1000893, 64128: 1000893, 30806: 1830556, 25152: 1830556, 6964: 1212535, 7864: 1212535, 4825: 1661335, 2160: 1423211, 276: 80970, 338: 2639160, 630: 80970, 656: 886237, 327: 439800, 463: 309842, 899: 309842, 136: 1139416, 4294: 961302, 9280: 961302, 5336: 961302, 8832: 961302, 1190112: 1118783, 1991616: 2000995, 1866128: 1680826, 1910656: 1888411, 7097: 179997, 3584: 179997, 282893152256: 179997, 1256904: 253530, 744832: 856504, 26545: 894907, 81248: 894907, 2318662016: 617107, 2949534720: 2453816, 4576: 1106822, 8712: 253523, 409: 711184, 133: 51132, 238: 342218, 272: 215231, 316: 381339, 714: 826842, 483: 436766, 712: 2471469, 7511: 198201, 8736: 501195, 400874541056: 198201, 6235: 1342286, 1344: 1342286, 5090: 1342286, 7648: 1342286, 28757: 184489, 96352: 184489, 1341912: 1767369, 1764928: 4344696, 21384: 506160, 12672: 506160, 785312: 313055, 1230592: 447840, 4593: 258062, 4680: 258062, 30478: 608194, 52544: 608194, 34083: 656657, 51232: 656657, 1260952: 384633, 793408: 1223060, 21097: 255457, 36640: 255457, 817696: 773910, 1619200: 1207773, 1477520: 388830, 1343936: 696267, 1165824: 528848, 1700160: 2254190, 941160: 371454, 1052480: 1580061, 24251: 815059, 72992: 815059, 763: 471883, 827: 522166, 816: 1780515, 2982307328: 2142927, 4170: 376772, 4520: 376772, 318418659328: 376772, 8092: 398269, 3568: 398269, 238322405376: 398269, 378: 181581, 195: 1336377, 896: 1362239, 320: 665404, 2162992128: 1323657, 249: 1118147, 71: 3838249, 820: 476981, 800: 1415292, 623: 452973, 392: 1439963, 920: 2335213, 3219908736: 355285, 2031901696: 1539696, 26422: 118500, 91520: 118500, 26873: 551159, 53856: 551159, 4958: 92533, 1928: 92533, 214857218048: 92533, 39204: 108810, 23232: 108810, 1441088: 2111239, 906752: 475091, 1789216: 601144, 987712: 1556273, 752928: 750103, 841984: 852123, 530288: 633355, 1426920: 526219, 455400: 544669, 1473472: 2494680, 29495: 2095582, 34720: 2095582, 22285: 4328598, 37344: 4328598, 1853984: 1459066, 1540264: 1731186, 394: 1392627, 39378944: 314596, 347: 405899, 258: 420481, 554: 566990, 368: 1009121, 6840: 560668, 3104: 912076, 308062515200: 560668, 6566: 706360, 6656: 706360, 361285230592: 706360, 5737: 41638, 6352: 41638, 6191: 41638, 8208: 385856, 1720400: 121360, 40638: 493941, 3392: 695861, 7462: 115095, 2856: 115095, 3724: 115095, 1600: 115095, 5638: 2326812, 544: 6922743, 293642567680: 2326812, 4692: 383261, 8464: 383261, 254053257216: 383261, 5969: 1537165, 7880: 1537165, 7027: 1537165, 3280: 1558662, 22695: 351408, 23596: 387076, 27776: 387076, 1993640: 85057, 1392512: 4265707, 32117: 764042, 15584: 764042, 1513952: 12930, 1781120: 1280411, 1605032: 896373, 825792: 1413315, 6168: 446442, 7472: 446442, 215250489344: 446442, 82: 4305448, 23: 2720733, 27: 3133528, 65: 6737772, 59: 4095116, 61: 4788411, 327463: 361498, 899136: 361498, 1453232: 589783, 37278: 315239, 84160: 315239, 36049: 938929, 86880: 938929, 2228537344: 5074874, 293: 2126708, 642: 1Line truncated
|
||||
"3811\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(stones)\n",
|
||||
"stones=step(stones)\n",
|
||||
" \n",
|
||||
"print(len(stones))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 271,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"defaultdict(<class 'int'>, {2: 1, 0: 1})\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from collections import defaultdict\n",
|
||||
"\n",
|
||||
"def step(stones):\n",
|
||||
" output = defaultdict(int) # Use defaultdict with int, which defaults to 0\n",
|
||||
" for stone, count in stones.items(): # Iterate over the dictionary of stones with their counts\n",
|
||||
" if stone == 0:\n",
|
||||
" output[1] += count # Zero turns into 1, add the count to the 1 key\n",
|
||||
" elif (tx_stone := str(stone)) and len(tx_stone) % 2 == 0:\n",
|
||||
" half = len(tx_stone) // 2\n",
|
||||
" left = int(tx_stone[:half])\n",
|
||||
" right = int(tx_stone[half:])\n",
|
||||
" output[left] += count # Add the count to the left split part\n",
|
||||
" output[right] += count # Add the count to the right split part\n",
|
||||
" else:\n",
|
||||
" output[stone * 2024] += count # Multiply by 2024 and add to the count for that stone\n",
|
||||
" return output\n",
|
||||
"\n",
|
||||
"# Example usage:\n",
|
||||
"stones = {20: 1} # Example input: stone values and their counts\n",
|
||||
"result = step(stones)\n",
|
||||
"print(result)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "pdf",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
@@ -143,7 +99,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.7"
|
||||
"version": "3.8.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in new issue
Block a user