{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cell-23-02-00",
   "metadata": {},
   "source": [
    "# 23-02 · Generator losowych historii\n",
    "\n",
    "Praktyka do sekcji [„Domowy projekt B: generator losowych historii”](/pl/chapters/rozdzial-23/23-hw-02-generator-istorij.html). Pełny plik — `projects/console/story-generator/story_generator.py`."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-23-02-01",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Wygenerować kilka historii i upewnić się, że każda jest złożona z oczekiwanych list słów."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-23-02-02",
   "metadata": {},
   "source": [
    "## Example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cell-23-02-03",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "import random\n",
    "\n",
    "sys.path.insert(0, \"../../projects/console/story-generator\")\n",
    "import story_generator as sg\n",
    "\n",
    "random.seed(7)\n",
    "for _ in range(3):\n",
    "    print(sg.sluchajnaya_istoriya())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-23-02-04",
   "metadata": {},
   "source": [
    "## Sprawdzenie wyniku"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cell-23-02-05",
   "metadata": {},
   "outputs": [],
   "source": [
    "for _ in range(50):\n",
    "    istoriya = sg.sluchajnaya_istoriya()\n",
    "    assert any(p in istoriya for p in sg.PRILAGATELNYE)\n",
    "    assert any(s in istoriya for s in sg.SUSHESTVITELNYE)\n",
    "    assert any(m in istoriya for m in sg.MESTA)\n",
    "    assert any(g in istoriya for g in sg.GLAGOLY)\n",
    "    assert any(pr in istoriya for pr in sg.PREDMETY)\n",
    "    assert istoriya.startswith(\"Однажды\") and istoriya.endswith(\"прежней.\")\n",
    "\n",
    "print(\"Верно: 50 случайных историй — и все построены по шаблону.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-23-02-06",
   "metadata": {},
   "source": [
    "## Starter\n",
    "\n",
    "Wypełnij zaznaczone miejsce. Niezmieniony starter nie przechodzi tests."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "task-23-02",
   "metadata": {
    "tags": [
     "exercise",
     "starter"
    ]
   },
   "outputs": [],
   "source": [
    "def poschitat_varianty(*gruppy):\n",
    "    \"\"\"Return the number of Cartesian-product combinations.\"\"\"\n",
    "    # TODO: multiply len(group) for every group.\n",
    "    raise NotImplementedError\n",
    "\n",
    "\n",
    "kolichestvo_variantov = poschitat_varianty(\n",
    "    sg.PRILAGATELNYE, sg.SUSHESTVITELNYE, sg.MESTA, sg.GLAGOLY, sg.PREDMETY\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-23-02-08",
   "metadata": {},
   "source": [
    "## Task\n",
    "\n",
    "Write `poschitat_varianty(*gruppy)`: liczba kombinacji jest równa iloczynowi długości. Grupa pusta daje zero."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-23-02-09",
   "metadata": {},
   "source": [
    "## Tests\n",
    "\n",
    "Run After task cell: jest podstawowy przykład i przynajmniej jeden skrajny przypadek."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "tests-23-02",
   "metadata": {
    "tags": [
     "exercise-tests"
    ]
   },
   "outputs": [],
   "source": [
    "assert kolichestvo_variantov == 5 * 5 * 4 * 5 * 4\n",
    "assert poschitat_varianty([1, 2], [\"a\", \"b\", \"c\"]) == 6\n",
    "assert poschitat_varianty([], [1, 2]) == 0\n",
    "print(\"Tests passed\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-23-02-11",
   "metadata": {},
   "source": [
    "## Hint\n",
    "\n",
    "Zacznij od `result = 1` i pomnóż przez `len(group)` w pętli."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-23-02-12",
   "metadata": {},
   "source": [
    "## Solution\n",
    "\n",
    "Pokaż rozwiązanie po własnej próbie</summary>\n",
    "\n",
    "```python\n",
    "def poschitat_varianty(*gruppy):\n",
    "    result = 1\n",
    "    for group in gruppy:\n",
    "        result *= len(group)\n",
    "    return result\n",
    "\n",
    "\n",
    "kolichestvo_variantov = poschitat_varianty(\n",
    "    sg.PRILAGATELNYE, sg.SUSHESTVITELNYE, sg.MESTA, sg.GLAGOLY, sg.PREDMETY\n",
    ")\n",
    "```\n",
    "\n",
    "</details>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "name": "python",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
