{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Notebook 1: Beginner's Guide to Jupyter & AI Problem Solving\n", "\n", "Welcome to your very first interactive Loktech AI notebook!\n", "\n", "If you have never written a line of code or opened a Jupyter Notebook before, you are in exactly the right place. We assume you have zero prior programming knowledge.\n", "\n", "### What is a Jupyter Notebook?\n", "A notebook is an interactive document made up of **cells**:\n", "1. **Text Cells (Markdown):** Like this box right here, containing explanation that you read.\n", "2. **Code Cells (Python):** Boxes containing small commands for the computer to run.\n", "\n", "### How to Run a Cell\n", "To run a code cell:\n", "- Click anywhere inside the gray code box below.\n", "- Press **Shift + Enter** on your keyboard (or click the Run / Play arrow icon at the top left of the cell).\n", "\n", "**Do not worry:** You cannot break your computer or the website by running code or making mistakes! If anything gets messy, just refresh the page." ] }, { "cell_type": "code", "metadata": {}, "source": [ "# Let us run your very first line of Python code!\n", "# Click this cell and press Shift + Enter.\n", "\n", "print(\"Ram Ram! Welcome to Loktech AI Notebook 1!\")" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": {}, "source": [ "# Python also acts as an instant calculator.\n", "# Try changing these numbers and pressing Shift + Enter again!\n", "\n", "result = 25 + 10 * 3\n", "print(\"The calculation result is:\", result)" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Experiment 1: State Space Search (Finding a Path in our Village)\n", "\n", "In Chapter 2, we learned about **State Spaces** and how an AI problem solver navigates step-by-step from a starting point (`State`) to a goal (`Goal State`).\n", "\n", "Let us represent a simple village map with connected locations using Python, and watch the computer find a path from our `Home` to the `Oran` (traditional forest pasture)." ] }, { "cell_type": "code", "metadata": {}, "source": [ "# Step 1: Define our village map (who is connected to whom)\n", "village_map = {\n", " \"Home\": [\"Well\", \"Field\"],\n", " \"Well\": [\"Home\", \"Naka\", \"Oran\"],\n", " \"Field\": [\"Home\", \"Naka\"],\n", " \"Naka\": [\"Well\", \"Field\", \"Oran\"],\n", " \"Oran\": [\"Well\", \"Naka\"]\n", "}\n", "\n", "print(\"Our village connections are ready:\", village_map)" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": {}, "source": [ "# Step 2: A simple step-by-step search function\n", "def find_path(map_data, current, destination, visited=None):\n", " if visited is None:\n", " visited = []\n", " visited = visited + [current]\n", " \n", " if current == destination:\n", " return visited\n", " \n", " for neighbor in map_data.get(current, []):\n", " if neighbor not in visited:\n", " path = find_path(map_data, neighbor, destination, visited)\n", " if path:\n", " return path\n", " return None\n", "\n", "# Let the computer search for a path from Home to Oran!\n", "path = find_path(village_map, \"Home\", \"Oran\")\n", "print(\"AI found this path through our village:\", \" -> \".join(path))" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Experiment 2: Heuristic Shortcuts (Estimating Distance)\n", "\n", "Instead of checking every single path blindly, AI uses **Heuristics** (practical rules of thumb or shortcuts) to guess which path is closer to the destination.\n", "\n", "Let us calculate the estimated step distance between two points on a grid!" ] }, { "cell_type": "code", "metadata": {}, "source": [ "# Heuristic distance formula (Manhattan distance between grid coordinates)\n", "def heuristic_distance(x1, y1, x2, y2):\n", " return abs(x1 - x2) + abs(y1 - y2)\n", "\n", "# Imagine Home is at (0, 0) and Oran is at (3, 4)\n", "home_pos = (0, 0)\n", "oran_pos = (3, 4)\n", "distance_estimate = heuristic_distance(home_pos[0], home_pos[1], oran_pos[0], oran_pos[1])\n", "\n", "print(f\"Heuristic estimated steps from Home to Oran: {distance_estimate} steps\")" ], "execution_count": null, "outputs": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3" } }, "nbformat": 4, "nbformat_minor": 5 }