{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d7113903",
   "metadata": {},
   "source": [
    "# 19-24 · Szybkość i rosnąca złożoność\n",
    "\n",
    "Praktyka do sekcji [„Szybkość i wzrost złożoności”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca0d6b02",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Każde zjedzone jabłko liczy się delay_ms każdego calculate_delay()."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d310fd1",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b671c9b9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:54:14.684715Z",
     "iopub.status.busy": "2026-09-03T00:54:14.684509Z",
     "iopub.status.idle": "2026-09-03T00:54:14.703770Z",
     "shell.execute_reply": "2026-09-03T00:54:14.703253Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30 140\n"
     ]
    }
   ],
   "source": [
    "def calculate_delay(score, *, base_ms=140, min_ms=60, step_score=50, step_ms=10):\n",
    "    steps = score // step_score\n",
    "    return max(min_ms, base_ms - steps * step_ms)\n",
    "\n",
    "def eat_food(score, delay_ms, food_score=10):\n",
    "    score += food_score\n",
    "    delay_ms = calculate_delay(score)\n",
    "    return score, delay_ms\n",
    "\n",
    "score, delay = 0, 140\n",
    "for _ in range(3):\n",
    "    score, delay = eat_food(score, delay)\n",
    "print(score, delay)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "94c92dec",
   "metadata": {},
   "source": [
    "## Podstawowa praktyka zadań ★"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c50b3a35",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:54:14.705631Z",
     "iopub.status.busy": "2026-09-03T00:54:14.705443Z",
     "iopub.status.idle": "2026-09-03T00:54:14.713260Z",
     "shell.execute_reply": "2026-09-03T00:54:14.708502Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Скорость растёт вместе со счётом при каждом съеденном яблоке.\n"
     ]
    }
   ],
   "source": [
    "score, delay = eat_food(40, 140)\n",
    "assert score == 50\n",
    "assert delay == 130\n",
    "\n",
    "score, delay = eat_food(999_990, 60)\n",
    "assert delay == 60  # уже на минимуме, ниже не опускается\n",
    "print(\"Скорость растёт вместе со счётом при каждом съеденном яблоке.\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "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.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
