Fix #13, PEP8-ify notebooks.

This commit is contained in:
Donne Martin
2015-07-11 15:35:12 -04:00
parent 04083b2011
commit 03f04fbc4c
12 changed files with 71 additions and 43 deletions

View File

@@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is a naiive solution sufficient?\n", "* Is a naiive solution sufficient?\n",
" * Yes" " * Yes"
] ]
@@ -122,9 +121,14 @@
"\n", "\n",
" print('Success: test_insertion_sort')\n", " print('Success: test_insertion_sort')\n",
"\n", "\n",
"if __name__ == '__main__':\n", "\n",
"def main():\n",
" test = TestInsertionSort()\n", " test = TestInsertionSort()\n",
" test.test_insertion_sort()" " test.test_insertion_sort()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
] ]
}, },
{ {

View File

@@ -33,7 +33,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is a naiive solution sufficient?\n", "* Is a naiive solution sufficient?\n",
" * Yes" " * Yes"
] ]
@@ -145,9 +144,14 @@
"\n", "\n",
" print('Success: test_insertion_sort')\n", " print('Success: test_insertion_sort')\n",
"\n", "\n",
"if __name__ == '__main__':\n", "\n",
"def main():\n",
" test = TestInsertionSort()\n", " test = TestInsertionSort()\n",
" test.test_insertion_sort()" " test.test_insertion_sort()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
] ]
}, },
{ {

View File

@@ -21,6 +21,11 @@ class TestInsertionSort(object):
print('Success: test_insertion_sort') print('Success: test_insertion_sort')
if __name__ == '__main__':
def main():
test = TestInsertionSort() test = TestInsertionSort()
test.test_insertion_sort() test.test_insertion_sort()
if __name__ == '__main__':
main()

View File

@@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is a naiive solution sufficient?\n", "* Is a naiive solution sufficient?\n",
" * Yes" " * Yes"
] ]
@@ -122,10 +121,12 @@
"\n", "\n",
" print('Success: test_merge_sort')\n", " print('Success: test_merge_sort')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestMergeSort()\n", " test = TestMergeSort()\n",
" test.test_merge_sort()\n", " test.test_merge_sort()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@@ -110,6 +110,7 @@
" r += 1\n", " r += 1\n",
" return result\n", " return result\n",
"\n", "\n",
"\n",
"def merge_sort(data):\n", "def merge_sort(data):\n",
" if len(data) < 2:\n", " if len(data) < 2:\n",
" return data\n", " return data\n",
@@ -168,10 +169,12 @@
"\n", "\n",
" print('Success: test_merge_sort')\n", " print('Success: test_merge_sort')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestMergeSort()\n", " test = TestMergeSort()\n",
" test.test_merge_sort()\n", " test.test_merge_sort()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@@ -20,9 +20,11 @@ class TestMergeSort(object):
print('Success: test_merge_sort') print('Success: test_merge_sort')
def main(): def main():
test = TestMergeSort() test = TestMergeSort()
test.test_merge_sort() test.test_merge_sort()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is a naiive solution sufficient (ie not in-place)?\n", "* Is a naiive solution sufficient (ie not in-place)?\n",
" * Yes" " * Yes"
] ]
@@ -121,6 +120,7 @@
"\n", "\n",
" print('Success: test_quick_sort\\n')\n", " print('Success: test_quick_sort\\n')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestQuickSort()\n", " test = TestQuickSort()\n",
" test.test_quick_sort(quick_sort)\n", " test.test_quick_sort(quick_sort)\n",
@@ -131,6 +131,7 @@
" # in the solutions file\n", " # in the solutions file\n",
" pass\n", " pass\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@@ -89,6 +89,7 @@
"source": [ "source": [
"from __future__ import division\n", "from __future__ import division\n",
"\n", "\n",
"\n",
"def quick_sort(data):\n", "def quick_sort(data):\n",
" if len(data) < 2:\n", " if len(data) < 2:\n",
" return data\n", " return data\n",
@@ -118,9 +119,7 @@
"source": [ "source": [
"## Pythonic-Code\n", "## Pythonic-Code\n",
"\n", "\n",
"From http://stackoverflow.com/questions/18262306/quick-sort-with-python\n", "The following code from [Stack Overflow](http://stackoverflow.com/questions/18262306/quick-sort-with-python) is very concise, although it might be a little difficult to read:"
"\n",
"The following code is very concise, although it might be a little difficult to read:"
] ]
}, },
{ {
@@ -185,6 +184,7 @@
"\n", "\n",
" print('Success: test_quick_sort\\n')\n", " print('Success: test_quick_sort\\n')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestQuickSort()\n", " test = TestQuickSort()\n",
" test.test_quick_sort(quick_sort)\n", " test.test_quick_sort(quick_sort)\n",
@@ -195,6 +195,7 @@
" # in the solutions file\n", " # in the solutions file\n",
" pass\n", " pass\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@@ -20,6 +20,7 @@ class TestQuickSort(object):
print('Success: test_quick_sort\n') print('Success: test_quick_sort\n')
def main(): def main():
test = TestQuickSort() test = TestQuickSort()
test.test_quick_sort(quick_sort) test.test_quick_sort(quick_sort)
@@ -30,5 +31,6 @@ def main():
# in the solutions file # in the solutions file
pass pass
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is a naiive solution sufficient (ie not stable, not based on a heap)?\n", "* Is a naiive solution sufficient (ie not stable, not based on a heap)?\n",
" * Yes" " * Yes"
] ]
@@ -135,6 +134,7 @@
"\n", "\n",
" print('Success: test_selection_sort\\n')\n", " print('Success: test_selection_sort\\n')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestSelectionSort()\n", " test = TestSelectionSort()\n",
" test.test_selection_sort(selection_sort)\n", " test.test_selection_sort(selection_sort)\n",
@@ -145,6 +145,7 @@
" # in the solutions file\n", " # in the solutions file\n",
" pass\n", " pass\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@@ -33,7 +33,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is a naiive solution sufficient (ie not stable, not based on a heap)?\n", "* Is a naiive solution sufficient (ie not stable, not based on a heap)?\n",
" * Yes" " * Yes"
] ]
@@ -91,6 +90,7 @@
" min_index = i\n", " min_index = i\n",
" return min_index\n", " return min_index\n",
"\n", "\n",
"\n",
"def swap(data, i, j):\n", "def swap(data, i, j):\n",
" if (i != j):\n", " if (i != j):\n",
" data[i], data[j] = data[j], data[i]" " data[i], data[j] = data[j], data[i]"
@@ -173,6 +173,7 @@
"\n", "\n",
" print('Success: test_selection_sort\\n')\n", " print('Success: test_selection_sort\\n')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestSelectionSort()\n", " test = TestSelectionSort()\n",
" test.test_selection_sort(selection_sort)\n", " test.test_selection_sort(selection_sort)\n",
@@ -183,6 +184,7 @@
" # in the solutions file\n", " # in the solutions file\n",
" pass\n", " pass\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@@ -21,6 +21,7 @@ class TestSelectionSort(object):
print('Success: test_selection_sort\n') print('Success: test_selection_sort\n')
def main(): def main():
test = TestSelectionSort() test = TestSelectionSort()
test.test_selection_sort(selection_sort) test.test_selection_sort(selection_sort)
@@ -31,5 +32,6 @@ def main():
# in the solutions file # in the solutions file
pass pass
if __name__ == '__main__': if __name__ == '__main__':
main() main()