update code on 9/4/2018

This commit is contained in:
Cris Liu 2018-09-05 00:01:03 -04:00
parent 561b3203cc
commit 20a61e1ca3
47 changed files with 312 additions and 214 deletions

View File

@ -93,17 +93,29 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Solution(object):\n", "class Solution(object):\n",
"\n", "\n",
" def fizz_buzz(self, num):\n", " def fizz_buzz(self, num):\n",
" # TODO: Implement me\n", " if num is None:\n",
" pass" " 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", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false "outputs": [
}, {
"outputs": [], "name": "stdout",
"output_type": "stream",
"text": [
"Success: test_fizz_buzz\n"
]
}
],
"source": [ "source": [
"# %load test_fizz_buzz.py\n", "# %load test_fizz_buzz.py\n",
"from nose.tools import assert_equal, assert_raises\n", "from nose.tools import assert_equal, assert_raises\n",
@ -179,8 +197,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -194,9 +213,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.4.3" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -105,9 +105,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Solution(object):\n", "class Solution(object):\n",
@ -140,9 +138,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -196,9 +192,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -214,8 +208,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -229,9 +224,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.4.3" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -73,9 +73,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class ReverseString(object):\n", "class ReverseString(object):\n",
@ -104,9 +102,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_reverse_string.py\n", "# %load test_reverse_string.py\n",
@ -152,8 +148,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -167,9 +164,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -75,17 +75,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class UniqueChars(object):\n", "class UniqueChars(object):\n",
"\n", "\n",
" def has_unique_chars(self, string):\n", " def has_unique_chars(self, string):\n",
" # TODO: Implement me\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", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": { "metadata": {},
"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",
@ -154,8 +167,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -169,9 +183,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -88,9 +88,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class UniqueCharsSet(object):\n", "class UniqueCharsSet(object):\n",
@ -135,9 +133,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class UniqueChars(object):\n", "class UniqueChars(object):\n",
@ -183,9 +179,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class UniqueCharsInPlace(object):\n", "class UniqueCharsInPlace(object):\n",
@ -209,9 +203,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -258,9 +250,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 5,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -278,8 +268,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -293,9 +284,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -79,39 +79,46 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Item(object):\n", "class Item(object):\n",
"\n", "\n",
" def __init__(self, key, value):\n", " def __init__(self, key, value):\n",
" # TODO: Implement me\n", " # TODO: Implement me\n",
" pass\n", " self.key = key\n",
" self.value = value\n",
"\n", "\n",
"\n", "\n",
"class HashTable(object):\n", "class HashTable(object):\n",
"\n", "\n",
" def __init__(self, size):\n", " def __init__(self, size):\n",
" # TODO: Implement me\n", " # TODO: Implement me\n",
" pass\n", " self.size = size\n",
" self.table = [[] for _ in range(self.size)]\n",
"\n", "\n",
" def _hash_function(self, key):\n", " def _hash_function(self, key):\n",
" # TODO: Implement me\n", " # TODO: Implement me\n",
" pass\n", " return key % self.size\n",
"\n", "\n",
" def set(self, key, value):\n", " def set(self, key, value):\n",
" # TODO: Implement me\n", " # TODO: Implement me\n",
" pass\n", " self.hash_[key] = value\n",
" \n",
"\n", "\n",
" def get(self, key):\n", " def get(self, key):\n",
" # TODO: Implement me\n", " # TODO: Implement me\n",
" pass\n", " if key in self.hash_:\n",
" return self.hash[key]\n",
" else:\n",
" raise KeyError\n",
"\n", "\n",
" def remove(self, key):\n", " def remove(self, key):\n",
" # TODO: Implement me\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", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_hash_map.py\n", "# %load test_hash_map.py\n",
@ -199,8 +204,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -214,9 +220,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -114,9 +114,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Item(object):\n", "class Item(object):\n",
@ -169,9 +167,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -235,9 +231,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -260,7 +254,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -274,9 +268,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -75,17 +75,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 13,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Solution(object):\n", "class Solution(object):\n",
"\n", "\n",
" def add_digits(self, val):\n", " def add_digits(self, val):\n",
" # TODO: Implement me\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", "cell_type": "code",
"execution_count": null, "execution_count": 14,
"metadata": { "metadata": {
"collapsed": false "scrolled": true
}, },
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_add_digits\n"
]
}
],
"source": [ "source": [
"# %load test_add_digits.py\n", "# %load test_add_digits.py\n",
"from nose.tools import assert_equal, assert_raises\n", "from nose.tools import assert_equal, assert_raises\n",
@ -153,8 +168,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -168,9 +184,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -72,17 +72,25 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 10,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import math\n",
"class Math(object):\n", "class Math(object):\n",
"\n", "\n",
" def check_prime(self, num):\n", " def check_prime(self, num):\n",
" # TODO: Implement me\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", "cell_type": "code",
"execution_count": null, "execution_count": 11,
"metadata": { "metadata": {},
"collapsed": false "outputs": [
}, {
"outputs": [], "name": "stdout",
"output_type": "stream",
"text": [
"Success: test_check_prime\n"
]
}
],
"source": [ "source": [
"# %load test_check_prime.py\n", "# %load test_check_prime.py\n",
"from nose.tools import assert_equal, assert_raises\n", "from nose.tools import assert_equal, assert_raises\n",
@ -140,11 +154,21 @@
"\n", "\n",
"Review the [Solution Notebook]() for a discussion on algorithms and code solutions." "Review the [Solution Notebook]() for a discussion on algorithms and code solutions."
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -158,9 +182,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -71,17 +71,34 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 34,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import math \n",
"\n",
"class PrimeGenerator(object):\n", "class PrimeGenerator(object):\n",
"\n", "\n",
" def generate_primes(self, max_num):\n", " def generate_primes(self, max_num):\n",
" # TODO: Implement me\n", " if max_num is None:\n",
" pass" " 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", "cell_type": "code",
"execution_count": null, "execution_count": 36,
"metadata": { "metadata": {},
"collapsed": false "outputs": [
}, {
"outputs": [], "name": "stdout",
"output_type": "stream",
"text": [
"Success: generate_primes\n"
]
}
],
"source": [ "source": [
"# %load test_generate_primes.py\n", "# %load test_generate_primes.py\n",
"from nose.tools import assert_equal, assert_raises\n", "from nose.tools import assert_equal, assert_raises\n",
@ -146,8 +169,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -161,9 +185,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -88,9 +88,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import math\n", "import math\n",
@ -134,9 +132,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -179,9 +175,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -198,7 +192,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -212,9 +206,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -81,27 +81,46 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Solution(object):\n", "class Solution(object):\n",
"\n", "\n",
" def __init__(self, upper_limit=100):\n", " def __init__(self, upper_limit=100):\n",
" # TODO: Implement me\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", "\n",
" def insert(self, val):\n", " def insert(self, val):\n",
" # TODO: Implement me\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", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"\n",
"## Unit Test" "## Unit Test"
] ]
}, },
@ -114,11 +133,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false "outputs": [
}, {
"outputs": [], "name": "stdout",
"output_type": "stream",
"text": [
"Success: test_math_ops\n"
]
}
],
"source": [ "source": [
"# %load test_math_ops.py\n", "# %load test_math_ops.py\n",
"from nose.tools import assert_equal, assert_true, assert_raises\n", "from nose.tools import assert_equal, assert_true, assert_raises\n",
@ -167,8 +192,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -182,9 +208,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -93,9 +93,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from __future__ import division\n", "from __future__ import division\n",
@ -143,9 +141,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -195,9 +191,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -214,7 +208,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -228,9 +222,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -76,17 +76,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Solution(object):\n", "class Solution(object):\n",
"\n", "\n",
" def is_power_of_two(self, val):\n", " def is_power_of_two(self, val):\n",
" # TODO: Implement me\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", "cell_type": "code",
"execution_count": null, "execution_count": 6,
"metadata": { "metadata": {},
"collapsed": false "outputs": [
}, {
"outputs": [], "name": "stdout",
"output_type": "stream",
"text": [
"Success: test_is_power_of_two\n"
]
}
],
"source": [ "source": [
"# %load test_is_power_of_two.py\n", "# %load test_is_power_of_two.py\n",
"from nose.tools import assert_equal, assert_raises\n", "from nose.tools import assert_equal, assert_raises\n",
@ -148,8 +161,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -163,9 +177,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -98,9 +98,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Solution(object):\n", "class Solution(object):\n",
@ -123,9 +121,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -165,9 +161,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -183,8 +177,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -198,9 +193,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -68,15 +68,15 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Solution(object):\n", "class Solution(object):\n",
"\n", "\n",
" def sum_two(self, val):\n", " def sum_two(self, a,b):\n",
" # TODO: Implement me\n", " # TODO: Implement me\n",
" result = a ^ b\n",
" result \n",
" pass" " pass"
] ]
}, },
@ -97,9 +97,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_sum_two.py\n", "# %load test_sum_two.py\n",
@ -137,8 +135,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -152,9 +151,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -112,9 +112,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Solution(object):\n", "class Solution(object):\n",
@ -139,9 +137,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -180,7 +176,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [ "outputs": [
@ -198,8 +193,9 @@
} }
], ],
"metadata": { "metadata": {
"anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python [default]",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -213,9 +209,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.5.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }