mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-05 00:48:03 +00:00
reverted files
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## Constraints\n",
|
"## Constraints\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|
||||||
"* Can we assume the string is ASCII?\n",
|
"* Can we assume the string is ASCII?\n",
|
||||||
" * Yes\n",
|
" * Yes\n",
|
||||||
" * Note: Unicode strings could require special handling depending on your language\n",
|
" * Note: Unicode strings could require special handling depending on your language\n",
|
||||||
@@ -163,7 +164,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
@@ -241,7 +242,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython2",
|
"pygments_lexer": "ipython2",
|
||||||
"version": "2.7.6"
|
"version": "2.7.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## Constraints\n",
|
"## Constraints\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|
||||||
"* Can you assume the string is ASCII?\n",
|
"* Can you assume the string is ASCII?\n",
|
||||||
" * Yes\n",
|
" * Yes\n",
|
||||||
" * Note: Unicode strings could require special handling depending on your language\n",
|
" * Note: Unicode strings could require special handling depending on your language\n",
|
||||||
@@ -74,38 +75,20 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def is_substring(substr, s):\n",
|
"def is_substring(s1, s2):\n",
|
||||||
" if len(s) < len(substr):\n",
|
" # TODO: Implement me\n",
|
||||||
" return False\n",
|
" pass\n",
|
||||||
" elif len(substr) == len(s) and len(s) == 0:\n",
|
|
||||||
" return True\n",
|
|
||||||
" pos = 0\n",
|
|
||||||
" while pos < len(s):\n",
|
|
||||||
" so_far = 0\n",
|
|
||||||
" while so_far < len(substr):\n",
|
|
||||||
" if substr[so_far] != s[pos]:\n",
|
|
||||||
" pos = pos + 1\n",
|
|
||||||
" break\n",
|
|
||||||
" else:\n",
|
|
||||||
" pos = pos + 1\n",
|
|
||||||
" so_far = so_far + 1\n",
|
|
||||||
" if so_far == len(substr):\n",
|
|
||||||
" return True\n",
|
|
||||||
" return False\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"def is_rotation(s1, s2):\n",
|
"def is_rotation(s1, s2):\n",
|
||||||
" if s1 is None or s2 is None:\n",
|
" # TODO: Implement me\n",
|
||||||
" return False\n",
|
" # Call is_substring only once\n",
|
||||||
" elif len(s1) != len(s2):\n",
|
" pass"
|
||||||
" return False\n",
|
|
||||||
" else:\n",
|
|
||||||
" return is_substring(s2,s1+s1)"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -126,19 +109,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Success: test_rotation\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_rotation.py\n",
|
"# %load test_rotation.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"from nose.tools import assert_equal\n",
|
||||||
@@ -188,7 +163,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython2",
|
"pygments_lexer": "ipython2",
|
||||||
"version": "2.7.6"
|
"version": "2.7.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## Constraints\n",
|
"## Constraints\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|
||||||
"* Can you assume the string is ASCII?\n",
|
"* Can you assume the string is ASCII?\n",
|
||||||
" * Yes\n",
|
" * Yes\n",
|
||||||
" * Note: Unicode strings could require special handling depending on your language\n",
|
" * Note: Unicode strings could require special handling depending on your language\n",
|
||||||
@@ -72,22 +73,15 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def unique_chars(string):\n",
|
"def unique_chars(string):\n",
|
||||||
" from collections import defaultdict\n",
|
" # TODO: Implement me\n",
|
||||||
" \n",
|
" pass"
|
||||||
" char_table = defaultdict(int)\n",
|
|
||||||
" for c in string:\n",
|
|
||||||
" if char_table[c] > 0:\n",
|
|
||||||
" return False\n",
|
|
||||||
" else:\n",
|
|
||||||
" char_table[c] = 1\n",
|
|
||||||
" return True"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -106,19 +100,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Success: test_unique_chars\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_unique_chars.py\n",
|
"# %load test_unique_chars.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"from nose.tools import assert_equal\n",
|
||||||
@@ -173,7 +159,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython2",
|
"pygments_lexer": "ipython2",
|
||||||
"version": "2.7.6"
|
"version": "2.7.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## Constraints\n",
|
"## Constraints\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|
||||||
"* Is a naiive solution sufficient?\n",
|
"* Is a naiive solution sufficient?\n",
|
||||||
" * Yes"
|
" * Yes"
|
||||||
]
|
]
|
||||||
@@ -67,25 +68,15 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"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",
|
"def insertion_sort(data):\n",
|
||||||
" for i,item in enumerate(data):\n",
|
" # TODO: Implement me\n",
|
||||||
" insert(data,i)\n",
|
" pass"
|
||||||
" return data"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -101,22 +92,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Empty input\n",
|
|
||||||
"One element\n",
|
|
||||||
"Two or more elements\n",
|
|
||||||
"Success: test_insertion_sort\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"# %load test_insertion_sort.py\n",
|
"# %load test_insertion_sort.py\n",
|
||||||
"from nose.tools import assert_equal\n",
|
"from nose.tools import assert_equal\n",
|
||||||
@@ -173,7 +153,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython2",
|
"pygments_lexer": "ipython2",
|
||||||
"version": "2.7.6"
|
"version": "2.7.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## Constraints\n",
|
"## Constraints\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
|
||||||
"* Is a naiive solution sufficient?\n",
|
"* Is a naiive solution sufficient?\n",
|
||||||
" * Yes"
|
" * Yes"
|
||||||
]
|
]
|
||||||
@@ -151,7 +152,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 3,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
@@ -160,34 +161,16 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"Empty input\n"
|
"Empty input\n",
|
||||||
]
|
"One element\n",
|
||||||
},
|
"Two or more elements\n",
|
||||||
{
|
"Success: test_insertion_sort\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"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"%run -i test_insertion_sort.py"
|
"%run -i test_insertion_sort.py"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {
|
|
||||||
"collapsed": true
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"source": []
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
@@ -206,7 +189,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython2",
|
"pygments_lexer": "ipython2",
|
||||||
"version": "2.7.6"
|
"version": "2.7.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
Reference in New Issue
Block a user