diff --git a/graphs_trees/a_star/__init__.py b/graphs_trees/a_star/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/graphs_trees/a_star/astar_challenge.ipynb b/graphs_trees/a_star/astar_challenge.ipynb new file mode 100644 index 0000000..3c250b4 --- /dev/null +++ b/graphs_trees/a_star/astar_challenge.ipynb @@ -0,0 +1,319 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This notebook was prepared by [Author](https://github.com/). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Challenge Notebook" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Problem: Implement A* algorithm\n", + "\n", + "* [Constraints](#Constraints)\n", + "* [Test Cases](#Test-Cases)\n", + "* [Algorithm](#Algorithm)\n", + "* [Code](#Code)\n", + "* [Unit Test](#Unit-Test)\n", + "* [Solution Notebook](#Solution-Notebook)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Constraints\n", + "\n", + "* Can we assume we have a Node Class?\n", + " * No\n", + "* Can we assume the inputs are valid?\n", + " * Yes\n", + "* Can we assume this fits memory?\n", + " * Yes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Test Cases\n", + "\n", + "
board | \n", + "start | \n", + "end | \n", + "cost | \n", + "output | \n", + "
[] | \n", + "[0, 0] | \n", + "[3, 5] | \n", + "1 | \n", + "None | \n", + "
[[0, 1, 0, 0, 0, 0],\n", + "[0, 0, 0, 0, 0, 1],\n", + "[0, 1, 0, 1, 0, 0],\n", + "[0, 1, 0, 0, 1, 0],\n", + "[0, 0, 0, 0, 1, 0]] | \n",
+ "[0, 0] | \n", + "[3, 5] | \n", + "1 | \n", + "[[0, -1, -1, -1, -1, -1],\n", + "[1, 2, 3, 4, 5, -1],\n", + "[-1, -1, -1, -1, 6, 7],\n", + "[-1, -1, -1, -1, -1, 8],\n", + "[-1, -1, -1, -1, -1, -1]] | \n",
+ "
[[0, 1, 0, 0, 0, 0],\n", + "[0, 0, 0, 0, 0, 1],\n", + "[0, 1, 0, 1, 0, 0],\n", + "[0, 1, 0, 0, 1, 0],\n", + "[0, 0, 0, 0, 1, 0]] | \n",
+ "[0, 5] | \n", + "[4, 0] | \n", + "1 | \n", + "[[-1, -1, -1, -1, 1, 0],\n", + "[-1, -1, 4, 3, 2, -1],\n", + "[-1, -1, 5, -1, -1, -1],\n", + "[-1, -1, 6, -1, -1, -1],\n", + "[ 9, 8, 7, -1, -1, -1]] | \n",
+ "
[[0, 1, 0, 0, 0, 0],\n", + "[0, 0, 0, 0, 0, 1],\n", + "[0, 1, 0, 1, 0, 0],\n", + "[0, 1, 0, 0, 1, 0],\n", + "[0, 0, 0, 0, 1, 0]] | \n",
+ "[0, 1] | \n", + "[3, 5] | \n", + "1 | \n", + "None | \n", + "
[[0, 1, 0, 0, 0, 0],\n", + "[0, 0, 0, 0, 0, 1],\n", + "[0, 1, 0, 1, 0, 0],\n", + "[0, 1, 0, 0, 1, 0],\n", + "[0, 0, 0, 0, 1, 0]] | \n",
+ "[0, 0] | \n", + "[2, 3] | \n", + "1 | \n", + "None | \n", + "
board | \n", + "start | \n", + "end | \n", + "cost | \n", + "expected | \n", + "
[] | \n", + "[0, 0] | \n", + "[3, 5] | \n", + "1 | \n", + "None | \n", + "
[[0, 1, 0, 0, 0, 0],\n", + "[0, 0, 0, 0, 0, 1],\n", + "[0, 1, 0, 1, 0, 0],\n", + "[0, 1, 0, 0, 1, 0],\n", + "[0, 0, 0, 0, 1, 0]] | \n",
+ "[0, 0] | \n", + "[3, 5] | \n", + "1 | \n", + "[[0, -1, -1, -1, -1, -1],\n", + "[1, 2, 3, 4, 5, -1],\n", + "[-1, -1, -1, -1, 6, 7],\n", + "[-1, -1, -1, -1, -1, 8],\n", + "[-1, -1, -1, -1, -1, -1]] | \n",
+ "
[[0, 1, 0, 0, 0, 0],\n", + "[0, 0, 0, 0, 0, 1],\n", + "[0, 1, 0, 1, 0, 0],\n", + "[0, 1, 0, 0, 1, 0],\n", + "[0, 0, 0, 0, 1, 0]] | \n",
+ "[0, 5] | \n", + "[4, 0] | \n", + "1 | \n", + "[[-1, -1, -1, -1, 1, 0],\n", + "[-1, -1, 4, 3, 2, -1],\n", + "[-1, -1, 5, -1, -1, -1],\n", + "[-1, -1, 6, -1, -1, -1],\n", + "[ 9, 8, 7, -1, -1, -1]] | \n",
+ "
[[0, 1, 0, 0, 0, 0],\n", + "[0, 0, 0, 0, 0, 1],\n", + "[0, 1, 0, 1, 0, 0],\n", + "[0, 1, 0, 0, 1, 0],\n", + "[0, 0, 0, 0, 1, 0]] | \n",
+ "[0, 1] | \n", + "[3, 5] | \n", + "1 | \n", + "None | \n", + "
[[0, 1, 0, 0, 0, 0],\n", + "[0, 0, 0, 0, 0, 1],\n", + "[0, 1, 0, 1, 0, 0],\n", + "[0, 1, 0, 0, 1, 0],\n", + "[0, 0, 0, 0, 1, 0]] | \n",
+ "[0, 0] | \n", + "[2, 3] | \n", + "1 | \n", + "None | \n", + "