{ "cells": [ { "cell_type": "code", "execution_count": 13, "id": "11aa5518", "metadata": {}, "outputs": [], "source": [ "import random\n", "\n", "def random_request():\n", " \"generates a single random request\"\n", " return sorted(random.sample(range(0,100), 2))\n", "\n", "def make_requests(n):\n", " \"generates n random requests\"\n", " # slower version\n", " #requests = []\n", " #for i in range(n):\n", " # requests.append(random_request())\n", " #return requests\n", " # faster version:\n", " return [random_request() for i in range(n)]\n", "\n", "def greedy_solution(requests):\n", " \"\"\"\n", " input is a set of requests, output is the\n", " greedy solution where best = earliest end\n", " time\n", " \"\"\"\n", " sorted_requests = sorted(requests, key=lambda x : x[1])\n", " \n", " solution = []\n", " solution.append(sorted_requests.pop(0))\n", " # when you call L.pop(i) for a list L, it removes\n", " # the element at index i and returns it for you\n", " \n", " # TODO: remove conflicts with this chosen meeting\n", " # and repeat until there are no sorted_requests\n", " # left" ] }, { "cell_type": "code", "execution_count": 14, "id": "274ea735", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[39, 73], [29, 55], [4, 88]]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "make_requests(3)" ] }, { "cell_type": "code", "execution_count": null, "id": "712c9513", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.1" } }, "nbformat": 4, "nbformat_minor": 5 }