From 20a61e1ca3a178137108d3ee5ada2e1f1ee83a7f Mon Sep 17 00:00:00 2001 From: Cris Liu Date: Wed, 5 Sep 2018 00:01:03 -0400 Subject: [PATCH] update code on 9/4/2018 --- .../__init__.py | 0 .../fizz_buzz_challenge.ipynb | 47 +++++++++++----- .../fizz_buzz_solution.ipynb | 19 +++---- .../test_fizz_buzz.py | 0 .../__init__.py | 0 .../reverse_string.cpp | 0 .../reverse_string_challenge.ipynb | 15 +++--- .../reverse_string_solution.ipynb | 0 .../test_reverse_string.py | 0 .../{two_sum => [Done]two_sum}/__init__.py | 0 .../test_two_sum.py | 0 .../two_sum_challenge.ipynb | 0 .../two_sum_solution.ipynb | 0 .../__init__.py | 0 .../test_unique_chars.py | 0 .../unique_chars_challenge.ipynb | 40 +++++++++----- .../unique_chars_solution.ipynb | 27 ++++------ .../hash_map/hash_map_challenge.ipynb | 36 +++++++------ .../hash_map/hash_map_solution.ipynb | 18 +++---- .../__init__.py | 0 .../add_digits_challenge.ipynb | 38 +++++++++---- .../add_digits_solution.ipynb | 0 .../test_add_digits.py | 0 .../__init__.py | 0 .../check_prime_challenge.ipynb | 50 ++++++++++++----- .../check_prime_solution.ipynb | 0 .../test_check_prime.py | 0 .../__init__.py | 0 .../check_prime_challenge.ipynb | 52 +++++++++++++----- .../check_prime_solution.ipynb | 18 +++---- .../test_generate_primes.py | 0 .../{math_ops => [Done]math_ops}/__init__.py | 0 .../math_ops_challenge.ipynb | 54 ++++++++++++++----- .../math_ops_solution.ipynb | 18 +++---- .../test_math_ops.py | 0 .../__init__.py | 0 .../power_two_challenge.ipynb | 40 +++++++++----- .../power_two_solution.ipynb | 19 +++---- .../test_is_power_of_two.py | 0 .../{sub_two => [Done]sub_two}/__init__.py | 0 .../sub_two_challenge.ipynb | 0 .../sub_two_solution.ipynb | 0 .../test_sub_two.py | 0 .../{sum_two => [Done]sum_two}/__init__.py | 0 .../sum_two_challenge.ipynb | 19 ++++--- .../sum_two_solution.ipynb | 16 +++--- .../test_sum_two.py | 0 47 files changed, 312 insertions(+), 214 deletions(-) rename arrays_strings/{fizz_buzz => [Done]fizz_buzz}/__init__.py (100%) rename arrays_strings/{fizz_buzz => [Done]fizz_buzz}/fizz_buzz_challenge.ipynb (81%) rename arrays_strings/{fizz_buzz => [Done]fizz_buzz}/fizz_buzz_solution.ipynb (96%) rename arrays_strings/{fizz_buzz => [Done]fizz_buzz}/test_fizz_buzz.py (100%) rename arrays_strings/{reverse_string => [Done]reverse_string}/__init__.py (100%) rename arrays_strings/{reverse_string => [Done]reverse_string}/reverse_string.cpp (100%) rename arrays_strings/{reverse_string => [Done]reverse_string}/reverse_string_challenge.ipynb (96%) rename arrays_strings/{reverse_string => [Done]reverse_string}/reverse_string_solution.ipynb (100%) rename arrays_strings/{reverse_string => [Done]reverse_string}/test_reverse_string.py (100%) rename arrays_strings/{two_sum => [Done]two_sum}/__init__.py (100%) rename arrays_strings/{two_sum => [Done]two_sum}/test_two_sum.py (100%) rename arrays_strings/{two_sum => [Done]two_sum}/two_sum_challenge.ipynb (100%) rename arrays_strings/{two_sum => [Done]two_sum}/two_sum_solution.ipynb (100%) rename arrays_strings/{unique_chars => [Done]unique_chars}/__init__.py (100%) rename arrays_strings/{unique_chars => [Done]unique_chars}/test_unique_chars.py (100%) rename arrays_strings/{unique_chars => [Done]unique_chars}/unique_chars_challenge.ipynb (86%) rename arrays_strings/{unique_chars => [Done]unique_chars}/unique_chars_solution.ipynb (96%) rename math_probability/{add_digits => [Done]add_digits}/__init__.py (100%) rename math_probability/{add_digits => [Done]add_digits}/add_digits_challenge.ipynb (84%) rename math_probability/{add_digits => [Done]add_digits}/add_digits_solution.ipynb (100%) rename math_probability/{add_digits => [Done]add_digits}/test_add_digits.py (100%) rename math_probability/{check_prime => [Done]check_prime}/__init__.py (100%) rename math_probability/{check_prime => [Done]check_prime}/check_prime_challenge.ipynb (81%) rename math_probability/{check_prime => [Done]check_prime}/check_prime_solution.ipynb (100%) rename math_probability/{check_prime => [Done]check_prime}/test_check_prime.py (100%) rename math_probability/{generate_primes => [Done]generate_primes}/__init__.py (100%) rename math_probability/{generate_primes => [Done]generate_primes}/check_prime_challenge.ipynb (77%) rename math_probability/{generate_primes => [Done]generate_primes}/check_prime_solution.ipynb (96%) rename math_probability/{generate_primes => [Done]generate_primes}/test_generate_primes.py (100%) rename math_probability/{math_ops => [Done]math_ops}/__init__.py (100%) rename math_probability/{math_ops => [Done]math_ops}/math_ops_challenge.ipynb (77%) rename math_probability/{math_ops => [Done]math_ops}/math_ops_solution.ipynb (96%) rename math_probability/{math_ops => [Done]math_ops}/test_math_ops.py (100%) rename math_probability/{power_two => [Done]power_two}/__init__.py (100%) rename math_probability/{power_two => [Done]power_two}/power_two_challenge.ipynb (84%) rename math_probability/{power_two => [Done]power_two}/power_two_solution.ipynb (95%) rename math_probability/{power_two => [Done]power_two}/test_is_power_of_two.py (100%) rename math_probability/{sub_two => [Done]sub_two}/__init__.py (100%) rename math_probability/{sub_two => [Done]sub_two}/sub_two_challenge.ipynb (100%) rename math_probability/{sub_two => [Done]sub_two}/sub_two_solution.ipynb (100%) rename math_probability/{sub_two => [Done]sub_two}/test_sub_two.py (100%) rename math_probability/{sum_two => [Done]sum_two}/__init__.py (100%) rename math_probability/{sum_two => [Done]sum_two}/sum_two_challenge.ipynb (93%) rename math_probability/{sum_two => [Done]sum_two}/sum_two_solution.ipynb (96%) rename math_probability/{sum_two => [Done]sum_two}/test_sum_two.py (100%) diff --git a/arrays_strings/fizz_buzz/__init__.py b/arrays_strings/[Done]fizz_buzz/__init__.py similarity index 100% rename from arrays_strings/fizz_buzz/__init__.py rename to arrays_strings/[Done]fizz_buzz/__init__.py diff --git a/arrays_strings/fizz_buzz/fizz_buzz_challenge.ipynb b/arrays_strings/[Done]fizz_buzz/fizz_buzz_challenge.ipynb similarity index 81% rename from arrays_strings/fizz_buzz/fizz_buzz_challenge.ipynb rename to arrays_strings/[Done]fizz_buzz/fizz_buzz_challenge.ipynb index 5fb68d1..62dbb45 100644 --- a/arrays_strings/fizz_buzz/fizz_buzz_challenge.ipynb +++ b/arrays_strings/[Done]fizz_buzz/fizz_buzz_challenge.ipynb @@ -93,17 +93,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, + "execution_count": 1, + "metadata": {}, "outputs": [], "source": [ "class Solution(object):\n", "\n", " def fizz_buzz(self, num):\n", - " # TODO: Implement me\n", - " pass" + " if num is None:\n", + " raise TypeError('num cannot be None')\n", + " if num < 1:\n", + " raise ValueError('num cannot be less than one')\n", + " results = []\n", + " for i in range(1, num + 1):\n", + " if i % 3 == 0 and i % 5 == 0:\n", + " results.append('FizzBuzz')\n", + " elif i % 3 == 0:\n", + " results.append('Fizz')\n", + " elif i % 5 == 0:\n", + " results.append('Buzz')\n", + " else:\n", + " results.append(str(i))\n", + " return results\n", + " " ] }, { @@ -122,11 +134,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Success: test_fizz_buzz\n" + ] + } + ], "source": [ "# %load test_fizz_buzz.py\n", "from nose.tools import assert_equal, assert_raises\n", @@ -179,8 +197,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -194,9 +213,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.4.3" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/arrays_strings/fizz_buzz/fizz_buzz_solution.ipynb b/arrays_strings/[Done]fizz_buzz/fizz_buzz_solution.ipynb similarity index 96% rename from arrays_strings/fizz_buzz/fizz_buzz_solution.ipynb rename to arrays_strings/[Done]fizz_buzz/fizz_buzz_solution.ipynb index 0e3d90d..b9dac9f 100644 --- a/arrays_strings/fizz_buzz/fizz_buzz_solution.ipynb +++ b/arrays_strings/[Done]fizz_buzz/fizz_buzz_solution.ipynb @@ -105,9 +105,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Solution(object):\n", @@ -140,9 +138,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -196,9 +192,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -214,8 +208,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -229,9 +224,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.4.3" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/arrays_strings/fizz_buzz/test_fizz_buzz.py b/arrays_strings/[Done]fizz_buzz/test_fizz_buzz.py similarity index 100% rename from arrays_strings/fizz_buzz/test_fizz_buzz.py rename to arrays_strings/[Done]fizz_buzz/test_fizz_buzz.py diff --git a/arrays_strings/reverse_string/__init__.py b/arrays_strings/[Done]reverse_string/__init__.py similarity index 100% rename from arrays_strings/reverse_string/__init__.py rename to arrays_strings/[Done]reverse_string/__init__.py diff --git a/arrays_strings/reverse_string/reverse_string.cpp b/arrays_strings/[Done]reverse_string/reverse_string.cpp similarity index 100% rename from arrays_strings/reverse_string/reverse_string.cpp rename to arrays_strings/[Done]reverse_string/reverse_string.cpp diff --git a/arrays_strings/reverse_string/reverse_string_challenge.ipynb b/arrays_strings/[Done]reverse_string/reverse_string_challenge.ipynb similarity index 96% rename from arrays_strings/reverse_string/reverse_string_challenge.ipynb rename to arrays_strings/[Done]reverse_string/reverse_string_challenge.ipynb index ebad367..b4dd439 100644 --- a/arrays_strings/reverse_string/reverse_string_challenge.ipynb +++ b/arrays_strings/[Done]reverse_string/reverse_string_challenge.ipynb @@ -73,9 +73,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class ReverseString(object):\n", @@ -104,9 +102,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# %load test_reverse_string.py\n", @@ -152,8 +148,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -167,9 +164,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/arrays_strings/reverse_string/reverse_string_solution.ipynb b/arrays_strings/[Done]reverse_string/reverse_string_solution.ipynb similarity index 100% rename from arrays_strings/reverse_string/reverse_string_solution.ipynb rename to arrays_strings/[Done]reverse_string/reverse_string_solution.ipynb diff --git a/arrays_strings/reverse_string/test_reverse_string.py b/arrays_strings/[Done]reverse_string/test_reverse_string.py similarity index 100% rename from arrays_strings/reverse_string/test_reverse_string.py rename to arrays_strings/[Done]reverse_string/test_reverse_string.py diff --git a/arrays_strings/two_sum/__init__.py b/arrays_strings/[Done]two_sum/__init__.py similarity index 100% rename from arrays_strings/two_sum/__init__.py rename to arrays_strings/[Done]two_sum/__init__.py diff --git a/arrays_strings/two_sum/test_two_sum.py b/arrays_strings/[Done]two_sum/test_two_sum.py similarity index 100% rename from arrays_strings/two_sum/test_two_sum.py rename to arrays_strings/[Done]two_sum/test_two_sum.py diff --git a/arrays_strings/two_sum/two_sum_challenge.ipynb b/arrays_strings/[Done]two_sum/two_sum_challenge.ipynb similarity index 100% rename from arrays_strings/two_sum/two_sum_challenge.ipynb rename to arrays_strings/[Done]two_sum/two_sum_challenge.ipynb diff --git a/arrays_strings/two_sum/two_sum_solution.ipynb b/arrays_strings/[Done]two_sum/two_sum_solution.ipynb similarity index 100% rename from arrays_strings/two_sum/two_sum_solution.ipynb rename to arrays_strings/[Done]two_sum/two_sum_solution.ipynb diff --git a/arrays_strings/unique_chars/__init__.py b/arrays_strings/[Done]unique_chars/__init__.py similarity index 100% rename from arrays_strings/unique_chars/__init__.py rename to arrays_strings/[Done]unique_chars/__init__.py diff --git a/arrays_strings/unique_chars/test_unique_chars.py b/arrays_strings/[Done]unique_chars/test_unique_chars.py similarity index 100% rename from arrays_strings/unique_chars/test_unique_chars.py rename to arrays_strings/[Done]unique_chars/test_unique_chars.py diff --git a/arrays_strings/unique_chars/unique_chars_challenge.ipynb b/arrays_strings/[Done]unique_chars/unique_chars_challenge.ipynb similarity index 86% rename from arrays_strings/unique_chars/unique_chars_challenge.ipynb rename to arrays_strings/[Done]unique_chars/unique_chars_challenge.ipynb index 2daf719..b01a7a2 100644 --- a/arrays_strings/unique_chars/unique_chars_challenge.ipynb +++ b/arrays_strings/[Done]unique_chars/unique_chars_challenge.ipynb @@ -75,17 +75,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, + "execution_count": 1, + "metadata": {}, "outputs": [], "source": [ "class UniqueChars(object):\n", "\n", " def has_unique_chars(self, string):\n", " # TODO: Implement me\n", - " pass" + " if string is None:\n", + " return False\n", + " charset = set()\n", + " \n", + " for char in string:\n", + " if char in charset:\n", + " return False\n", + " else:\n", + " charset.add(char)\n", + " return True" ] }, { @@ -104,11 +111,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Success: test_unique_chars\n" + ] + } + ], "source": [ "# %load test_unique_chars.py\n", "from nose.tools import assert_equal\n", @@ -154,8 +167,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -169,9 +183,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/arrays_strings/unique_chars/unique_chars_solution.ipynb b/arrays_strings/[Done]unique_chars/unique_chars_solution.ipynb similarity index 96% rename from arrays_strings/unique_chars/unique_chars_solution.ipynb rename to arrays_strings/[Done]unique_chars/unique_chars_solution.ipynb index ccd7ee6..fab46b5 100644 --- a/arrays_strings/unique_chars/unique_chars_solution.ipynb +++ b/arrays_strings/[Done]unique_chars/unique_chars_solution.ipynb @@ -88,9 +88,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class UniqueCharsSet(object):\n", @@ -135,9 +133,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class UniqueChars(object):\n", @@ -183,9 +179,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class UniqueCharsInPlace(object):\n", @@ -209,9 +203,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -258,9 +250,7 @@ { "cell_type": "code", "execution_count": 5, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -278,8 +268,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -293,9 +284,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/arrays_strings/hash_map/hash_map_challenge.ipynb b/arrays_strings/hash_map/hash_map_challenge.ipynb index cce6564..893aff4 100644 --- a/arrays_strings/hash_map/hash_map_challenge.ipynb +++ b/arrays_strings/hash_map/hash_map_challenge.ipynb @@ -79,39 +79,46 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Item(object):\n", "\n", " def __init__(self, key, value):\n", " # TODO: Implement me\n", - " pass\n", + " self.key = key\n", + " self.value = value\n", "\n", "\n", "class HashTable(object):\n", "\n", " def __init__(self, size):\n", " # TODO: Implement me\n", - " pass\n", + " self.size = size\n", + " self.table = [[] for _ in range(self.size)]\n", "\n", " def _hash_function(self, key):\n", " # TODO: Implement me\n", - " pass\n", + " return key % self.size\n", "\n", " def set(self, key, value):\n", " # TODO: Implement me\n", - " pass\n", + " self.hash_[key] = value\n", + " \n", "\n", " def get(self, key):\n", " # TODO: Implement me\n", - " pass\n", + " if key in self.hash_:\n", + " return self.hash[key]\n", + " else:\n", + " raise KeyError\n", "\n", " def remove(self, key):\n", " # TODO: Implement me\n", - " pass" + " if key in self.hash_:\n", + " return self.hash[key]\n", + " else:\n", + " raise KeyError" ] }, { @@ -133,9 +140,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# %load test_hash_map.py\n", @@ -199,8 +204,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -214,9 +220,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/arrays_strings/hash_map/hash_map_solution.ipynb b/arrays_strings/hash_map/hash_map_solution.ipynb index 36a38cd..76a8efb 100644 --- a/arrays_strings/hash_map/hash_map_solution.ipynb +++ b/arrays_strings/hash_map/hash_map_solution.ipynb @@ -114,9 +114,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Item(object):\n", @@ -169,9 +167,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -235,9 +231,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -260,7 +254,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -274,9 +268,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/math_probability/add_digits/__init__.py b/math_probability/[Done]add_digits/__init__.py similarity index 100% rename from math_probability/add_digits/__init__.py rename to math_probability/[Done]add_digits/__init__.py diff --git a/math_probability/add_digits/add_digits_challenge.ipynb b/math_probability/[Done]add_digits/add_digits_challenge.ipynb similarity index 84% rename from math_probability/add_digits/add_digits_challenge.ipynb rename to math_probability/[Done]add_digits/add_digits_challenge.ipynb index 6fbdabd..d70d91a 100644 --- a/math_probability/add_digits/add_digits_challenge.ipynb +++ b/math_probability/[Done]add_digits/add_digits_challenge.ipynb @@ -75,17 +75,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, + "execution_count": 13, + "metadata": {}, "outputs": [], "source": [ "class Solution(object):\n", "\n", " def add_digits(self, val):\n", " # TODO: Implement me\n", - " pass" + " if (type(val)!=int) or (val is None):\n", + " raise TypeError\n", + " if val < 0:\n", + " raise ValueError\n", + " if val >= 10:\n", + " v = str(val)\n", + " v2 = [int(i) for i in v]\n", + " return self.add_digits(sum(v2))\n", + " else: \n", + " return val" ] }, { @@ -104,11 +111,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { - "collapsed": false + "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Success: test_add_digits\n" + ] + } + ], "source": [ "# %load test_add_digits.py\n", "from nose.tools import assert_equal, assert_raises\n", @@ -153,8 +168,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -168,9 +184,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/math_probability/add_digits/add_digits_solution.ipynb b/math_probability/[Done]add_digits/add_digits_solution.ipynb similarity index 100% rename from math_probability/add_digits/add_digits_solution.ipynb rename to math_probability/[Done]add_digits/add_digits_solution.ipynb diff --git a/math_probability/add_digits/test_add_digits.py b/math_probability/[Done]add_digits/test_add_digits.py similarity index 100% rename from math_probability/add_digits/test_add_digits.py rename to math_probability/[Done]add_digits/test_add_digits.py diff --git a/math_probability/check_prime/__init__.py b/math_probability/[Done]check_prime/__init__.py similarity index 100% rename from math_probability/check_prime/__init__.py rename to math_probability/[Done]check_prime/__init__.py diff --git a/math_probability/check_prime/check_prime_challenge.ipynb b/math_probability/[Done]check_prime/check_prime_challenge.ipynb similarity index 81% rename from math_probability/check_prime/check_prime_challenge.ipynb rename to math_probability/[Done]check_prime/check_prime_challenge.ipynb index c7d4433..54ce535 100644 --- a/math_probability/check_prime/check_prime_challenge.ipynb +++ b/math_probability/[Done]check_prime/check_prime_challenge.ipynb @@ -72,17 +72,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, + "execution_count": 10, + "metadata": {}, "outputs": [], "source": [ + "import math\n", "class Math(object):\n", "\n", " def check_prime(self, num):\n", " # TODO: Implement me\n", - " pass" + " if num is None:\n", + " raise TypeError\n", + " if type(num)!=int:\n", + " raise TypeError\n", + " if num < 2:\n", + " return False\n", + " for i in range(2,int(math.sqrt(num))):\n", + " if num%i==0:\n", + " return False\n", + " return True" ] }, { @@ -101,11 +109,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Success: test_check_prime\n" + ] + } + ], "source": [ "# %load test_check_prime.py\n", "from nose.tools import assert_equal, assert_raises\n", @@ -140,11 +154,21 @@ "\n", "Review the [Solution Notebook]() for a discussion on algorithms and code solutions." ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -158,9 +182,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/math_probability/check_prime/check_prime_solution.ipynb b/math_probability/[Done]check_prime/check_prime_solution.ipynb similarity index 100% rename from math_probability/check_prime/check_prime_solution.ipynb rename to math_probability/[Done]check_prime/check_prime_solution.ipynb diff --git a/math_probability/check_prime/test_check_prime.py b/math_probability/[Done]check_prime/test_check_prime.py similarity index 100% rename from math_probability/check_prime/test_check_prime.py rename to math_probability/[Done]check_prime/test_check_prime.py diff --git a/math_probability/generate_primes/__init__.py b/math_probability/[Done]generate_primes/__init__.py similarity index 100% rename from math_probability/generate_primes/__init__.py rename to math_probability/[Done]generate_primes/__init__.py diff --git a/math_probability/generate_primes/check_prime_challenge.ipynb b/math_probability/[Done]generate_primes/check_prime_challenge.ipynb similarity index 77% rename from math_probability/generate_primes/check_prime_challenge.ipynb rename to math_probability/[Done]generate_primes/check_prime_challenge.ipynb index a9aaf97..c1d8f2d 100644 --- a/math_probability/generate_primes/check_prime_challenge.ipynb +++ b/math_probability/[Done]generate_primes/check_prime_challenge.ipynb @@ -71,17 +71,34 @@ }, { "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": false - }, + "execution_count": 34, + "metadata": {}, "outputs": [], "source": [ + "import math \n", + "\n", "class PrimeGenerator(object):\n", "\n", " def generate_primes(self, max_num):\n", - " # TODO: Implement me\n", - " pass" + " if max_num is None:\n", + " raise TypeError('max_num cannot be None')\n", + " array = [True] * max_num\n", + " array[0] = False\n", + " array[1] = False\n", + " prime = 2\n", + " while prime <= math.sqrt(max_num):\n", + " self._cross_off(array,prime)\n", + " prime = self._next_prime(array, prime)\n", + " return array\n", + " def _cross_off(self,array,prime):\n", + " for i in range(prime*prime,len(array),prime):\n", + " array[i] = False\n", + " def _next_prime(self,array,prime):\n", + " next = prime + 1\n", + " while next < len(array) & (not array[next]):\n", + " next+=1\n", + " return next\n", + " " ] }, { @@ -100,11 +117,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Success: generate_primes\n" + ] + } + ], "source": [ "# %load test_generate_primes.py\n", "from nose.tools import assert_equal, assert_raises\n", @@ -146,8 +169,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -161,9 +185,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/math_probability/generate_primes/check_prime_solution.ipynb b/math_probability/[Done]generate_primes/check_prime_solution.ipynb similarity index 96% rename from math_probability/generate_primes/check_prime_solution.ipynb rename to math_probability/[Done]generate_primes/check_prime_solution.ipynb index 1dcc4c6..6016e1e 100644 --- a/math_probability/generate_primes/check_prime_solution.ipynb +++ b/math_probability/[Done]generate_primes/check_prime_solution.ipynb @@ -88,9 +88,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "import math\n", @@ -134,9 +132,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -179,9 +175,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -198,7 +192,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -212,9 +206,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/math_probability/generate_primes/test_generate_primes.py b/math_probability/[Done]generate_primes/test_generate_primes.py similarity index 100% rename from math_probability/generate_primes/test_generate_primes.py rename to math_probability/[Done]generate_primes/test_generate_primes.py diff --git a/math_probability/math_ops/__init__.py b/math_probability/[Done]math_ops/__init__.py similarity index 100% rename from math_probability/math_ops/__init__.py rename to math_probability/[Done]math_ops/__init__.py diff --git a/math_probability/math_ops/math_ops_challenge.ipynb b/math_probability/[Done]math_ops/math_ops_challenge.ipynb similarity index 77% rename from math_probability/math_ops/math_ops_challenge.ipynb rename to math_probability/[Done]math_ops/math_ops_challenge.ipynb index 8257a9b..3b768f9 100644 --- a/math_probability/math_ops/math_ops_challenge.ipynb +++ b/math_probability/[Done]math_ops/math_ops_challenge.ipynb @@ -81,27 +81,46 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, + "execution_count": 1, + "metadata": {}, "outputs": [], "source": [ "class Solution(object):\n", "\n", " def __init__(self, upper_limit=100):\n", " # TODO: Implement me\n", - " pass\n", + " self.max = None\n", + " self.min = None\n", + " # Mean\n", + " self.num_items = 0\n", + " self.running_sum = 0\n", + " self.mean = None\n", + " self.array = [0] * (upper_limit + 1)\n", + " self.mode_occurrences = 0\n", + " self.mode = None\n", "\n", " def insert(self, val):\n", " # TODO: Implement me\n", - " pass" + " if val is None:\n", + " raise TypeError('val cannot be None')\n", + " if self.max is None or val > self.max:\n", + " self.max = val\n", + " if self.min is None or val < self.min:\n", + " self.min = val\n", + " self.num_items += 1\n", + " self.running_sum += val\n", + " self.mean = self.running_sum / self.num_items\n", + " self.array[val] += 1\n", + " if self.array[val] > self.mode_occurrences:\n", + " self.mode_occurrences = self.array[val]\n", + " self.mode = val" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ + "\n", "## Unit Test" ] }, @@ -114,11 +133,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Success: test_math_ops\n" + ] + } + ], "source": [ "# %load test_math_ops.py\n", "from nose.tools import assert_equal, assert_true, assert_raises\n", @@ -167,8 +192,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -182,9 +208,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/math_probability/math_ops/math_ops_solution.ipynb b/math_probability/[Done]math_ops/math_ops_solution.ipynb similarity index 96% rename from math_probability/math_ops/math_ops_solution.ipynb rename to math_probability/[Done]math_ops/math_ops_solution.ipynb index 7af7159..56b0a7c 100644 --- a/math_probability/math_ops/math_ops_solution.ipynb +++ b/math_probability/[Done]math_ops/math_ops_solution.ipynb @@ -93,9 +93,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "from __future__ import division\n", @@ -143,9 +141,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -195,9 +191,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -214,7 +208,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -228,9 +222,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/math_probability/math_ops/test_math_ops.py b/math_probability/[Done]math_ops/test_math_ops.py similarity index 100% rename from math_probability/math_ops/test_math_ops.py rename to math_probability/[Done]math_ops/test_math_ops.py diff --git a/math_probability/power_two/__init__.py b/math_probability/[Done]power_two/__init__.py similarity index 100% rename from math_probability/power_two/__init__.py rename to math_probability/[Done]power_two/__init__.py diff --git a/math_probability/power_two/power_two_challenge.ipynb b/math_probability/[Done]power_two/power_two_challenge.ipynb similarity index 84% rename from math_probability/power_two/power_two_challenge.ipynb rename to math_probability/[Done]power_two/power_two_challenge.ipynb index 4815a68..9d2f00d 100644 --- a/math_probability/power_two/power_two_challenge.ipynb +++ b/math_probability/[Done]power_two/power_two_challenge.ipynb @@ -76,17 +76,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, + "execution_count": 5, + "metadata": {}, "outputs": [], "source": [ "class Solution(object):\n", "\n", " def is_power_of_two(self, val):\n", " # TODO: Implement me\n", - " pass" + " if val is None:\n", + " raise TypeError\n", + " if val == 0:\n", + " return False\n", + " elif val == 1:\n", + " return True\n", + " elif val%2 == 1:\n", + " return False\n", + " else:\n", + " return self.is_power_of_two(val/2)" ] }, { @@ -105,11 +112,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Success: test_is_power_of_two\n" + ] + } + ], "source": [ "# %load test_is_power_of_two.py\n", "from nose.tools import assert_equal, assert_raises\n", @@ -148,8 +161,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -163,9 +177,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/math_probability/power_two/power_two_solution.ipynb b/math_probability/[Done]power_two/power_two_solution.ipynb similarity index 95% rename from math_probability/power_two/power_two_solution.ipynb rename to math_probability/[Done]power_two/power_two_solution.ipynb index 9e67bf4..439046a 100644 --- a/math_probability/power_two/power_two_solution.ipynb +++ b/math_probability/[Done]power_two/power_two_solution.ipynb @@ -98,9 +98,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Solution(object):\n", @@ -123,9 +121,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -165,9 +161,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -183,8 +177,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -198,9 +193,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/math_probability/power_two/test_is_power_of_two.py b/math_probability/[Done]power_two/test_is_power_of_two.py similarity index 100% rename from math_probability/power_two/test_is_power_of_two.py rename to math_probability/[Done]power_two/test_is_power_of_two.py diff --git a/math_probability/sub_two/__init__.py b/math_probability/[Done]sub_two/__init__.py similarity index 100% rename from math_probability/sub_two/__init__.py rename to math_probability/[Done]sub_two/__init__.py diff --git a/math_probability/sub_two/sub_two_challenge.ipynb b/math_probability/[Done]sub_two/sub_two_challenge.ipynb similarity index 100% rename from math_probability/sub_two/sub_two_challenge.ipynb rename to math_probability/[Done]sub_two/sub_two_challenge.ipynb diff --git a/math_probability/sub_two/sub_two_solution.ipynb b/math_probability/[Done]sub_two/sub_two_solution.ipynb similarity index 100% rename from math_probability/sub_two/sub_two_solution.ipynb rename to math_probability/[Done]sub_two/sub_two_solution.ipynb diff --git a/math_probability/sub_two/test_sub_two.py b/math_probability/[Done]sub_two/test_sub_two.py similarity index 100% rename from math_probability/sub_two/test_sub_two.py rename to math_probability/[Done]sub_two/test_sub_two.py diff --git a/math_probability/sum_two/__init__.py b/math_probability/[Done]sum_two/__init__.py similarity index 100% rename from math_probability/sum_two/__init__.py rename to math_probability/[Done]sum_two/__init__.py diff --git a/math_probability/sum_two/sum_two_challenge.ipynb b/math_probability/[Done]sum_two/sum_two_challenge.ipynb similarity index 93% rename from math_probability/sum_two/sum_two_challenge.ipynb rename to math_probability/[Done]sum_two/sum_two_challenge.ipynb index 1346c49..a98b355 100644 --- a/math_probability/sum_two/sum_two_challenge.ipynb +++ b/math_probability/[Done]sum_two/sum_two_challenge.ipynb @@ -68,15 +68,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Solution(object):\n", "\n", - " def sum_two(self, val):\n", + " def sum_two(self, a,b):\n", " # TODO: Implement me\n", + " result = a ^ b\n", + " result \n", " pass" ] }, @@ -97,9 +97,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "# %load test_sum_two.py\n", @@ -137,8 +135,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -152,9 +151,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/math_probability/sum_two/sum_two_solution.ipynb b/math_probability/[Done]sum_two/sum_two_solution.ipynb similarity index 96% rename from math_probability/sum_two/sum_two_solution.ipynb rename to math_probability/[Done]sum_two/sum_two_solution.ipynb index cfba2a3..f427b60 100644 --- a/math_probability/sum_two/sum_two_solution.ipynb +++ b/math_probability/[Done]sum_two/sum_two_solution.ipynb @@ -112,9 +112,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "class Solution(object):\n", @@ -139,9 +137,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -180,7 +176,6 @@ "cell_type": "code", "execution_count": 3, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [ @@ -198,8 +193,9 @@ } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, @@ -213,9 +209,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.0" + "version": "3.5.4" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/math_probability/sum_two/test_sum_two.py b/math_probability/[Done]sum_two/test_sum_two.py similarity index 100% rename from math_probability/sum_two/test_sum_two.py rename to math_probability/[Done]sum_two/test_sum_two.py