{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "#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",
    "stones = {int(x):1 for x in input.split()}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import defaultdict\n",
    "\n",
    "def step(stones):\n",
    "    output=defaultdict(int)\n",
    "    for stone,count in stones.items():\n",
    "        if stone == 0:\n",
    "            output[1]+=count\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\n",
    "            output[right]+=count\n",
    "        else:\n",
    "            output[stone * 2024]+=count\n",
    "    return output\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "193269"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for i in range(25):\n",
    "    stones=step(stones)\n",
    "sum(stones.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "228449040027793"
      ]
     },
     "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())"
   ]
  }
 ],
 "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.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
