reverted files

This commit is contained in:
wdonahoe
2015-07-11 11:07:15 -04:00
parent f45be890af
commit 91b021f4b5
5 changed files with 35 additions and 110 deletions

View File

@@ -34,6 +34,7 @@
"source": [
"## Constraints\n",
"\n",
"* Is a naiive solution sufficient?\n",
" * Yes"
]
@@ -67,25 +68,15 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def insert(l,item_pos):\n",
" item = l[item_pos]\n",
" while item_pos > 0:\n",
" if l[item_pos - 1] > item:\n",
" l[item_pos - 1], l[item_pos] = l[item_pos], l[item_pos - 1]\n",
" item_pos -= 1\n",
" else:\n",
" break\n",
"\n",
"def insertion_sort(data):\n",
" for i,item in enumerate(data):\n",
" insert(data,i)\n",
" return data"
" # TODO: Implement me\n",
" pass"
]
},
{
@@ -101,22 +92,11 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Empty input\n",
"One element\n",
"Two or more elements\n",
"Success: test_insertion_sort\n"
]
}
],
"outputs": [],
"source": [
"# %load test_insertion_sort.py\n",
"from nose.tools import assert_equal\n",
@@ -173,7 +153,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
"version": "2.7.10"
}
},
"nbformat": 4,

View File

@@ -33,6 +33,7 @@
"source": [
"## Constraints\n",
"\n",
"* Is a naiive solution sufficient?\n",
" * Yes"
]
@@ -151,7 +152,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {
"collapsed": false
},
@@ -160,34 +161,16 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Empty input\n"
]
},
{
"ename": "NameError",
"evalue": "global name 'insertion_sort' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/wdonahoe/Documents/interactive-coding-challenges/sorting_searching/insertion_sort/test_insertion_sort.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0m__name__\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'__main__'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 25\u001b[0m \u001b[0mtest\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mTestInsertionSort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 26\u001b[1;33m \u001b[0mtest\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtest_insertion_sort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m/home/wdonahoe/Documents/interactive-coding-challenges/sorting_searching/insertion_sort/test_insertion_sort.py\u001b[0m in \u001b[0;36mtest_insertion_sort\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Empty input'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m \u001b[0minsertion_sort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 10\u001b[0m \u001b[0massert_equal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mNameError\u001b[0m: global name 'insertion_sort' is not defined"
"Empty input\n",
"One element\n",
"Two or more elements\n",
"Success: test_insertion_sort\n"
]
}
],
"source": [
"%run -i test_insertion_sort.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
@@ -206,7 +189,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
"version": "2.7.10"
}
},
"nbformat": 4,