From dd852d9b5e201cc87b8795ad3c65ad76bd6bcd66 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 12 Dec 2016 10:23:34 -0800 Subject: [PATCH 01/10] fixed docstring errors --- pip-selfcheck.json | 1 - pyvenv.cfg | 3 --- share/man/man1/ipython.1.gz | Bin 1039 -> 0 bytes src/calculate_years.py | 2 +- src/count_bits.py | 8 +++++--- src/decending_order.py | 4 ++-- src/find_odd_int.py | 5 +++-- src/is_isogram.py | 7 ++++--- src/multiply.py | 2 +- src/remove_min.py | 3 ++- src/shortest_word.py | 4 ++-- src/tests/test_count_bits.py | 6 +++--- src/xo.py | 6 +++--- 13 files changed, 26 insertions(+), 25 deletions(-) delete mode 100644 pip-selfcheck.json delete mode 100644 pyvenv.cfg delete mode 100644 share/man/man1/ipython.1.gz diff --git a/pip-selfcheck.json b/pip-selfcheck.json deleted file mode 100644 index 63f85dd..0000000 --- a/pip-selfcheck.json +++ /dev/null @@ -1 +0,0 @@ -{"last_check":"2016-12-11T00:27:19Z","pypi_version":"9.0.1"} \ No newline at end of file diff --git a/pyvenv.cfg b/pyvenv.cfg deleted file mode 100644 index bdc23ad..0000000 --- a/pyvenv.cfg +++ /dev/null @@ -1,3 +0,0 @@ -home = /Users/Sera/Dropbox/codefellows/401/code-katas/src/bin -include-system-site-packages = false -version = 3.5.2 diff --git a/share/man/man1/ipython.1.gz b/share/man/man1/ipython.1.gz deleted file mode 100644 index db5e00ba04a7c6d6f2d5ed519df262d070e750e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1039 zcmV+q1n~PGiwFn{8Lw9Y18H!1bZBpGE-?U&Rbg-2HW2;JUvUTqIPGM49yV+UiUMxp zASxEev%CVqJfxI#ve-(bKvMDa?{_36+iCM*h5^aEyLa#2-O=&x0{++M4*Lj}_lxWF z3Z`$TAhjw>_r_v^xE0!1Xu0MMTGSD&7Wc~tOr^TIfDD1xHRQZC-aExy$>Q8SU0!dK zht+w+eENF?4e#moFay(N26HQv^a#pUs80X}xb`{J0gEdzh!iO=e|r=8=ll(ew|9`N zAGdc8E11K@$FA;S{%Zt3|1_Upc*u2)+z?3drK3`8B@7hYQt}EVK2tW0&%y|~C!2?F z`5t2z8fsDvg4d+sxmG5EQn{ECHOd^Xyi+WzQO`mcp4A9d-%b;O=pjCcLs}yxjwFYx3zM=HOn(5I> zc&IIq2_e(SzXk`>!aMo?%t8J*2W(o~d)L6hsWpf?H7(|%6!}rgQ$u|Pd#CeLI0z}y zyOF~%B~T$Rjug}M%uJ)lb^n^eOx`P(}=yMru8vR7fj(5HvZw zv#O!_%Yn48inO~Fl8F0WsLs+WEn3k_-iVy3>Jzzn3a zm?`x&fD+K9%J5!SqHOPH$|U`z1@ zmb|MiBe);#9`2X3c&ts7a7ymdk-E;E$|#8cqw46wmtH1EBs2sIc;^!t=BX0+jZy4SV4;q9r;R}uYa zS*}l3H&^2zutJ?0KBR=4Za<5YFkDy&3zN4`Av$jR$p9P*bzIqr+ibvi8Ym4iEdC<< zCOzsvf*-W77A0i8FJZLY(7#o!+J;sEw#XZJS6SPdtJ!Q%I&@h~t(Xmj$LIT){RePY JU6%?7006k3`h@@h diff --git a/src/calculate_years.py b/src/calculate_years.py index f191af5..9aba775 100644 --- a/src/calculate_years.py +++ b/src/calculate_years.py @@ -2,7 +2,7 @@ def calculate_years(principal, interest, tax, desired): - """ caculates how many years it take to reach desired principle. """ + """Calculate how many years it take to reach desired principle.""" years = 0 while (principal < desired): accrued = principal * interest diff --git a/src/count_bits.py b/src/count_bits.py index 3079814..591c3b9 100644 --- a/src/count_bits.py +++ b/src/count_bits.py @@ -1,6 +1,8 @@ -""" Implemntation of the Bit Counting Kata. """ -def countBits(n): - """ Converts a number to binary and counts the number of 1 bits. """ +"""Implemntation of the Bit Counting Kata.""" + + +def count_bits(n): + """Convert a number to binary and counts the number of 1 bits.""" print(n) val = bin(n) print(val) diff --git a/src/decending_order.py b/src/decending_order.py index 4d08c7f..c08876d 100644 --- a/src/decending_order.py +++ b/src/decending_order.py @@ -1,8 +1,8 @@ """Implementation of the Kata Descending_Order.""" -def Descending_Order(num): - """takes a non-neg integer and returns its digits in decending order. """ +def decending_order(num): + """Take a non-neg integer and returns its digits in decending order.""" num_array = list(str(num)) reverse_array = sorted(num_array, reverse=True) reverse_string = ''.join(reverse_array) diff --git a/src/find_odd_int.py b/src/find_odd_int.py index 51336e6..e4d4a97 100644 --- a/src/find_odd_int.py +++ b/src/find_odd_int.py @@ -1,7 +1,8 @@ -""" Implementation of the Kata Find the Odd Int. """ +"""Implementation of the Kata Find the Odd Int.""" + def find_it(seq): - """ returns only number appearing odd number of times. """ + """Return only number appearing odd number of times.""" for num in seq: if seq.count(num) % 2 != 0: return num diff --git a/src/is_isogram.py b/src/is_isogram.py index c4d5c65..eb448d1 100644 --- a/src/is_isogram.py +++ b/src/is_isogram.py @@ -1,7 +1,8 @@ -""" Implementation of the Kata Isograms. """ -def is_isogram(string): - """ This tells you if a string is a isogram, word that has no repeating letters. """ +"""Implementation of the Kata Isograms.""" + +def is_isogram(string): + """Tell you if a string is a isogram, word that has no repeating letters.""" string = string.lower() if len(string) == 0: diff --git a/src/multiply.py b/src/multiply.py index a24f841..40972fd 100644 --- a/src/multiply.py +++ b/src/multiply.py @@ -2,5 +2,5 @@ def multiply(a, b): - """takes two integers and returns its product. """ + """Take two integers and returns its product.""" return a * b diff --git a/src/remove_min.py b/src/remove_min.py index b6e550d..ddfdb7d 100644 --- a/src/remove_min.py +++ b/src/remove_min.py @@ -1,7 +1,8 @@ """Implementation of the Kata Remove the Minimum.""" + def remove_smallest(numbers): - """takes an array of integers and remove one of the smallest numbers(s). """ + """Take an array of integers and remove one of the smallest numbers(s).""" try: numbers.remove(min(numbers)) except ValueError: diff --git a/src/shortest_word.py b/src/shortest_word.py index a0170bd..e003156 100644 --- a/src/shortest_word.py +++ b/src/shortest_word.py @@ -1,8 +1,8 @@ -""" Implementation of the Shortest Word Kata. """ +"""Implementation of the Shortest Word Kata.""" def find_short(s): - """ returns the shortest word out of a string of words. """ + """Return the shortest word out of a string of words.""" shortest = 999999999 words = s.split(' ') diff --git a/src/tests/test_count_bits.py b/src/tests/test_count_bits.py index cdc9bf3..f06bb26 100644 --- a/src/tests/test_count_bits.py +++ b/src/tests/test_count_bits.py @@ -11,6 +11,6 @@ @pytest.mark.parametrize("n, result", BITS_TABLE) def test_count_bits(n, result): - """Test the countBits function.""" - from count_bits import countBits - assert countBits(n) == result + """Test the count_bits function.""" + from count_bits import count_bits + assert count_bits(n) == result diff --git a/src/xo.py b/src/xo.py index ee57572..0f18804 100644 --- a/src/xo.py +++ b/src/xo.py @@ -1,8 +1,8 @@ -""" This is an implmentation of the Exes and Ohs kata. """ +"""This is an implmentation of the Exes and Ohs kata.""" -def xo(s): - """ Determines if the string has the same number of x's and o's. """ +def xo(s) + """Determines if the string has the same number of x's and o's.""" s = s.lower() x_count = s.count('x') o_count = s.count('o') From aac934ea762d6647dac45958a9f2483595caeefd Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 12 Dec 2016 11:17:31 -0800 Subject: [PATCH 02/10] fixed docstring errors --- src/multiply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/multiply.py b/src/multiply.py index 40972fd..afdd11b 100644 --- a/src/multiply.py +++ b/src/multiply.py @@ -1,4 +1,4 @@ -"""Implementation of the Kata multiply.""" +"""Implementation ofthe Kata multiply.""" def multiply(a, b): From f971f9aefbed7e952ae6fb35db32c9781fdc8777 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 12 Dec 2016 11:18:17 -0800 Subject: [PATCH 03/10] fixed docstring errors --- src/multiply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/multiply.py b/src/multiply.py index afdd11b..40972fd 100644 --- a/src/multiply.py +++ b/src/multiply.py @@ -1,4 +1,4 @@ -"""Implementation ofthe Kata multiply.""" +"""Implementation of the Kata multiply.""" def multiply(a, b): From 9801a0752b17f3d14fb62c9255567d3674463020 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 18 Dec 2016 23:05:18 -0800 Subject: [PATCH 04/10] completed tests for parenthetics.py --- src/parenthetics.py | 0 src/sum_terms.py | 6 ++++++ src/tests/test_parenthetics.py | 15 +++++++++++++++ src/tests/test_sum_terms.py | 15 +++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 src/parenthetics.py create mode 100644 src/sum_terms.py create mode 100644 src/tests/test_parenthetics.py create mode 100644 src/tests/test_sum_terms.py diff --git a/src/parenthetics.py b/src/parenthetics.py new file mode 100644 index 0000000..e69de29 diff --git a/src/sum_terms.py b/src/sum_terms.py new file mode 100644 index 0000000..e9fe999 --- /dev/null +++ b/src/sum_terms.py @@ -0,0 +1,6 @@ +"""Implementation of the Sum of the first nth term of Series Kata.""" + + +def series_sum(n): + """Return the sum of series in range.""" + return "%.2f" % sum((1.0 / (3 * i + 1) for i in range(n))) diff --git a/src/tests/test_parenthetics.py b/src/tests/test_parenthetics.py new file mode 100644 index 0000000..a5d9a50 --- /dev/null +++ b/src/tests/test_parenthetics.py @@ -0,0 +1,15 @@ +"""Tests for parenthetics module.""" +import pytest + +PAREN_TABLE = [ + ['((()))', 0], + ['((())', 1], + [')))(((', -1] +] + + +@pytest.mark.parametrize("uni_string, result", PAREN_TABLE) +def test_parenthetics(uni_string, result): + """Test the parenthetics function.""" + from parenthetics import parenthetics + assert parenthetics(uni_string) == result diff --git a/src/tests/test_sum_terms.py b/src/tests/test_sum_terms.py new file mode 100644 index 0000000..4709e01 --- /dev/null +++ b/src/tests/test_sum_terms.py @@ -0,0 +1,15 @@ +"""Tests for sum_terms module.""" +import pytest + +TERMS_TABLE = [ + [1, '1.00'], + [2, '1.25'], + [3, '1.39'] +] + + +@pytest.mark.parametrize("n, result", TERMS_TABLE) +def test_sum_terms(n, result): + """Test the series_sum function.""" + from sum_terms import series_sum + assert series_sum(n) == result From bfdd5ca158040e9613f63803c43bec889c2d7181 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 19 Dec 2016 00:38:47 -0800 Subject: [PATCH 05/10] wrote paranthetics using previous Stack functions. Tests written and passing. Need more coverage. --- src/parenthetics.py | 96 ++++++++++++++++++++++++++++++++++ src/tests/test_parenthetics.py | 3 ++ src/xo.py | 4 +- 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/src/parenthetics.py b/src/parenthetics.py index e69de29..45696a9 100644 --- a/src/parenthetics.py +++ b/src/parenthetics.py @@ -0,0 +1,96 @@ +"""Implementation of the Kata Proper Parenthetics.""" + + +def parenthetics(uni_string): + """Take unicode string as input and return value.""" + stack = Stack() + charac_array = list(uni_string) + for charac in charac_array: + if charac == '(': + stack.push(charac) + elif charac == ')': + if stack.size() == 0: + return -1 + else: + stack.pop() + if stack.size() == 0: + return 0 + elif stack.size() > 0: + return 1 + + +class Stack(object): + """Create stack of parenthetics.""" + + def __init__(self, iterable=None): + """Create a new stack, from LinkedList using composition.""" + self._linkedlist = LinkedList() + if iterable and hasattr(iterable, "__iter__"): + for item in iterable: + self.push(item) + elif iterable: + raise TypeError + + def push(self, value): + """Push a new value on top of the stack.""" + self._linkedlist.push(value) + + def size(self): + """Return side of a.""" + return self._linkedlist.size() + + def pop(self): + """Pop the first value of the stack.""" + return self._linkedlist.pop() + + +"""Python implementation of a linked list.""" + + +class Node(): + """Instantiate a Node.""" + + def __init__(self, value=None, next=None): + """Instantiate a node with value and next params.""" + self.value = value + self.next = next + + +class LinkedList(): + """Instantiate a Linked List.""" + + def __init__(self, iterable=None): + """Instantiate an empty Linked list.""" + self.head = None + + if iterable and hasattr(iterable, "__iter__"): + for item in iterable: + self.push(item) + elif iterable: + raise TypeError + + def push(self, val): + """Push a new node as the head of the linked list.""" + new_node = Node(val, self.head) + self.head = new_node + + def pop(self): + """Pop first value off linked list and return value.""" + # if self.head is None: + if self.head is not None: + pop_head = self.head.value + self.head = self.head.next + return pop_head + else: + raise IndexError('cannot pop from empty list') + + def size(self): + """Return the length of the linked list.""" + if self.head is not None: + size = 1 + curr = self.head + while curr.next is not None: + size += 1 + curr = curr.next + return size + return 0 diff --git a/src/tests/test_parenthetics.py b/src/tests/test_parenthetics.py index a5d9a50..8abc3e7 100644 --- a/src/tests/test_parenthetics.py +++ b/src/tests/test_parenthetics.py @@ -1,6 +1,9 @@ """Tests for parenthetics module.""" + + import pytest + PAREN_TABLE = [ ['((()))', 0], ['((())', 1], diff --git a/src/xo.py b/src/xo.py index 0f18804..330b8f2 100644 --- a/src/xo.py +++ b/src/xo.py @@ -1,8 +1,8 @@ """This is an implmentation of the Exes and Ohs kata.""" -def xo(s) - """Determines if the string has the same number of x's and o's.""" +def xo(s): + """Determine if the string has the same number of x's and o's.""" s = s.lower() x_count = s.count('x') o_count = s.count('o') From 0ac9159a203b454f39c8da35388cd52a3f9e8477 Mon Sep 17 00:00:00 2001 From: Sera Smith Date: Mon, 19 Dec 2016 00:56:37 -0800 Subject: [PATCH 06/10] Update README.md --- README.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e76eba0..184484b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ multiply = __import__('operator').mul ###7kyu -###Decending Order: +####Decending Order: - MODULE: decending_order.py - TESTS: test_decending_order.py - LINKS: @@ -29,7 +29,7 @@ def Descending_Order(num): ``` -###Remove the Minimum: +####Remove the Minimum: - MODULE: remove_min.py - TESTS: test_remove.min.py - LINKS: @@ -44,7 +44,7 @@ def remove_smallest(numbers): ``` -###Money, Money, Money: +####Money, Money, Money: - MODULE: calculate_years.py - TESTS: test_calculate_years.py - LINKS: @@ -61,7 +61,7 @@ def calculate_years(principal, interest, tax, desired): ``` -###Isograms: +####Isograms: - MODULE: is_isogram.py - TESTS: test_is_isogram.py - LINKS: @@ -74,7 +74,7 @@ def is_isogram(string): ``` -###Exes and Ohs: +####Exes and Ohs: - MODULE: xo.py - TESTS: test_xo.py - LINKS: @@ -88,7 +88,7 @@ def xo(s): ``` -###Shortest Word: +####Shortest Word: - MODULE: shortest_word.py - TESTS: test_shortest_word.py - LINKS: @@ -104,7 +104,7 @@ def find_short(s): ###6kyu -###Find the Odd Int: +####Find the Odd Int: - MODULE: find_odd_int.py - TESTS: test_find_odd_int.py - LINKS: @@ -129,3 +129,13 @@ def find_it(xs): def countBits(n): return bin(n).count("1") ``` + + +###Other + + +####Interview Challenge: Proper Parenthetics +- Module: proper-parenthetics.py +- TESTS: test_proper-parenthetics.py +- LINKS: None. +- DERIVED FROM: [data-structures repo. Specifically stack branch](https://github.com/ellezv/data_structures/tree/stack), collaborated with Maelle Vance. From afd256058955f0de78d025c44ae51060c09a7b6e Mon Sep 17 00:00:00 2001 From: Sera Smith Date: Mon, 19 Dec 2016 00:57:43 -0800 Subject: [PATCH 07/10] Update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 184484b..bab4abb 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ def find_it(xs): ``` -###Bit Counting: +####Bit Counting: - MODULE: count_bits.py - TESTS: test_count_bits.py - LINKS: [Bit Counting - Kata](https://www.codewars.com/kata/bit-counting/train/python), From e4b3bfe973c0e122464ad68857313b0796660424 Mon Sep 17 00:00:00 2001 From: Sera Smith Date: Mon, 19 Dec 2016 00:59:57 -0800 Subject: [PATCH 08/10] Update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bab4abb..26efa41 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Repo containing my solutions from Code War katas. +Repo containing my solutions from Code Katas. ###8kyu From db28faac6f7579c2f1220e46106cebf4f7fd6413 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 19 Dec 2016 08:47:32 -0800 Subject: [PATCH 09/10] updated tests for 100% coverage. --- src/parenthetics.py | 15 ++------------- src/tests/test_parenthetics.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/parenthetics.py b/src/parenthetics.py index 45696a9..d4c4c53 100644 --- a/src/parenthetics.py +++ b/src/parenthetics.py @@ -22,14 +22,9 @@ def parenthetics(uni_string): class Stack(object): """Create stack of parenthetics.""" - def __init__(self, iterable=None): + def __init__(self): """Create a new stack, from LinkedList using composition.""" self._linkedlist = LinkedList() - if iterable and hasattr(iterable, "__iter__"): - for item in iterable: - self.push(item) - elif iterable: - raise TypeError def push(self, value): """Push a new value on top of the stack.""" @@ -59,16 +54,10 @@ def __init__(self, value=None, next=None): class LinkedList(): """Instantiate a Linked List.""" - def __init__(self, iterable=None): + def __init__(self): """Instantiate an empty Linked list.""" self.head = None - if iterable and hasattr(iterable, "__iter__"): - for item in iterable: - self.push(item) - elif iterable: - raise TypeError - def push(self, val): """Push a new node as the head of the linked list.""" new_node = Node(val, self.head) diff --git a/src/tests/test_parenthetics.py b/src/tests/test_parenthetics.py index 8abc3e7..ae87c75 100644 --- a/src/tests/test_parenthetics.py +++ b/src/tests/test_parenthetics.py @@ -16,3 +16,13 @@ def test_parenthetics(uni_string, result): """Test the parenthetics function.""" from parenthetics import parenthetics assert parenthetics(uni_string) == result + + +def test_pop_empty(): + """Test the parenthetics function.""" + from parenthetics import LinkedList + list = LinkedList() + try: + list.pop() + except Exception as e: + assert str(e) == 'cannot pop from empty list' From 84b5aa64110461b51bb9274b2a8d798dd990828d Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 23 Feb 2017 19:41:15 -0800 Subject: [PATCH 10/10] remove print statements. update .gitignore. --- .gitignore | 2 -- src/count_bits.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/.gitignore b/.gitignore index 92cd3f7..a901a34 100644 --- a/.gitignore +++ b/.gitignore @@ -89,5 +89,3 @@ ENV/ # Rope project settings .ropeproject - -bin/ diff --git a/src/count_bits.py b/src/count_bits.py index 0d9b8c2..a58e73f 100644 --- a/src/count_bits.py +++ b/src/count_bits.py @@ -4,7 +4,5 @@ def count_bits(n): """Convert a number to binary and counts the number of 1 bits.""" - print(n) val = bin(n) - print(val) return val.count("1")