From 734496e462c0810139b147d4a733450af0984acf Mon Sep 17 00:00:00 2001 From: meshmote Date: Tue, 7 Oct 2014 19:28:27 -0700 Subject: [PATCH 01/12] Removing old HW --- Students/Rperkins/break_me.py | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 Students/Rperkins/break_me.py diff --git a/Students/Rperkins/break_me.py b/Students/Rperkins/break_me.py deleted file mode 100644 index 0f72fdd5..00000000 --- a/Students/Rperkins/break_me.py +++ /dev/null @@ -1,14 +0,0 @@ -def NameWrong(): - d = seven - return -def TypeWrong(): - f = 14.2 - len(f) - return -def SyntaxWrong(): - x = len("four - return -def AtrribWrong(): - f = "1234" - f.rocket - return From 97a581f0bf3d090a4d54e5ee12b736ad7d87198b Mon Sep 17 00:00:00 2001 From: meshmote Date: Tue, 7 Oct 2014 19:35:32 -0700 Subject: [PATCH 02/12] Remove old HW --- Students/Rperkins/grid_build.py | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 Students/Rperkins/grid_build.py diff --git a/Students/Rperkins/grid_build.py b/Students/Rperkins/grid_build.py deleted file mode 100644 index 0a5b7a16..00000000 --- a/Students/Rperkins/grid_build.py +++ /dev/null @@ -1,31 +0,0 @@ -def Rowline(size, column): -# prints an "x", then a number of "-"s (scaled by the "size" parameter), -# for each count of the "column" parameter - for i in range(column): - print "+", - for x in range(4 + (size-1)): - print "-", - print "+" # the "bookend" character - return - -def Columnline(size, column): -# prints an "|", then a number of " "s (scaled by the "size" parameter), -# for each count of the "column" parameter - for i in range(column): - print "|", - for x in range(4 + (size-1)): - print " ", - print "|" # the "bookend" character - return - -def PrintGrid(size, row, column): -# the outer loop prints a "row" number of rowlines -# the inner loop prints a number of column lines scaled -# by the "size" parameter - for i in range(row): - Rowline(size, column) - for i in range(4 + (size-1)): - Columnline(size, column) - Rowline(size, column) # the "bookend" row - -PrintGrid(1,2,2) \ No newline at end of file From 7f18a5e56e7b60943e6beced49a5cfe585432760 Mon Sep 17 00:00:00 2001 From: meshmote Date: Tue, 7 Oct 2014 20:39:33 -0700 Subject: [PATCH 03/12] Added session01 directory and HW files --- Students/RPerkins/session01/break_me.py | 14 ++++++++++ Students/RPerkins/session01/grid_build.py | 31 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Students/RPerkins/session01/break_me.py create mode 100644 Students/RPerkins/session01/grid_build.py diff --git a/Students/RPerkins/session01/break_me.py b/Students/RPerkins/session01/break_me.py new file mode 100644 index 00000000..0f72fdd5 --- /dev/null +++ b/Students/RPerkins/session01/break_me.py @@ -0,0 +1,14 @@ +def NameWrong(): + d = seven + return +def TypeWrong(): + f = 14.2 + len(f) + return +def SyntaxWrong(): + x = len("four + return +def AtrribWrong(): + f = "1234" + f.rocket + return diff --git a/Students/RPerkins/session01/grid_build.py b/Students/RPerkins/session01/grid_build.py new file mode 100644 index 00000000..0a5b7a16 --- /dev/null +++ b/Students/RPerkins/session01/grid_build.py @@ -0,0 +1,31 @@ +def Rowline(size, column): +# prints an "x", then a number of "-"s (scaled by the "size" parameter), +# for each count of the "column" parameter + for i in range(column): + print "+", + for x in range(4 + (size-1)): + print "-", + print "+" # the "bookend" character + return + +def Columnline(size, column): +# prints an "|", then a number of " "s (scaled by the "size" parameter), +# for each count of the "column" parameter + for i in range(column): + print "|", + for x in range(4 + (size-1)): + print " ", + print "|" # the "bookend" character + return + +def PrintGrid(size, row, column): +# the outer loop prints a "row" number of rowlines +# the inner loop prints a number of column lines scaled +# by the "size" parameter + for i in range(row): + Rowline(size, column) + for i in range(4 + (size-1)): + Columnline(size, column) + Rowline(size, column) # the "bookend" row + +PrintGrid(1,2,2) \ No newline at end of file From c364569dc0f4a7369a9b76f8f254efbf1c6a7835 Mon Sep 17 00:00:00 2001 From: meshmote Date: Tue, 7 Oct 2014 21:16:55 -0700 Subject: [PATCH 04/12] Added HW file 1 --- Students/RPerkins/session02/ack.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 Students/RPerkins/session02/ack.py diff --git a/Students/RPerkins/session02/ack.py b/Students/RPerkins/session02/ack.py new file mode 100644 index 00000000..cbb10833 --- /dev/null +++ b/Students/RPerkins/session02/ack.py @@ -0,0 +1 @@ +def Ack(m,n): From f66d2aab476aba166f494ad076753f91acf5b976 Mon Sep 17 00:00:00 2001 From: meshmote Date: Wed, 8 Oct 2014 19:48:47 -0700 Subject: [PATCH 05/12] Added first working ack.py --- Students/RPerkins/session02/ack.py | 45 +++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/Students/RPerkins/session02/ack.py b/Students/RPerkins/session02/ack.py index cbb10833..8b294c70 100644 --- a/Students/RPerkins/session02/ack.py +++ b/Students/RPerkins/session02/ack.py @@ -1 +1,44 @@ -def Ack(m,n): +__author__ = 'Robert W. Perkins' + + +def ack(m, n): + """Return the result of the Ackerman function on m and n""" + if m < 0 or n < 0: + return None + elif m == 0: + return n+1 + elif m > 0 and n == 0: + return ack(m-1, 1) + elif m > 0 and n > 0: + return ack(m-1, ack(m, n-1)) + +if __name__ == "__main__": + assert ack(-1, 2) == None + assert ack(2, -1) == None + assert ack(-1, -1) == None + assert ack(0, 0) == 1 + assert ack(0, 1) == 2 + assert ack(0, 2) == 3 + assert ack(0, 3) == 4 + assert ack(0, 4) == 5 + assert ack(1, 0) == 2 + assert ack(1, 1) == 3 + assert ack(1, 2) == 4 + assert ack(1, 3) == 5 + assert ack(1, 4) == 6 + assert ack(2, 0) == 3 + assert ack(2, 1) == 5 + assert ack(2, 2) == 7 + assert ack(2, 3) == 9 + assert ack(2, 4) == 11 + assert ack(3, 0) == 5 + assert ack(3, 1) == 13 + assert ack(3, 2) == 29 + assert ack(3, 3) == 61 + assert ack(3, 4) == 125 + # max recursion depth exceeded after this point + #assert ack(4, 0) == 2**2**2-3 + #assert ack(4, 1) == 2**2**2**2-3 + #assert ack(4, 2) == (2**65536)-3 + #assert ack(4, 3) == (2**2**65536)-3 + #assert ack(4, 4) == (2**2**2**65536)-3 \ No newline at end of file From ff4d3142ef6a130253daf5ff6288081cec6ee5f2 Mon Sep 17 00:00:00 2001 From: meshmote Date: Wed, 8 Oct 2014 19:50:58 -0700 Subject: [PATCH 06/12] Fixed syntax for None comparisons in test block --- Students/RPerkins/session02/ack.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Students/RPerkins/session02/ack.py b/Students/RPerkins/session02/ack.py index 8b294c70..d9c3cbf5 100644 --- a/Students/RPerkins/session02/ack.py +++ b/Students/RPerkins/session02/ack.py @@ -13,9 +13,9 @@ def ack(m, n): return ack(m-1, ack(m, n-1)) if __name__ == "__main__": - assert ack(-1, 2) == None - assert ack(2, -1) == None - assert ack(-1, -1) == None + assert ack(-1, 2) is None + assert ack(2, -1) is None + assert ack(-1, -1) is None assert ack(0, 0) == 1 assert ack(0, 1) == 2 assert ack(0, 2) == 3 From 92059fbf56efa05523d5bebaba0354941dfef1fb Mon Sep 17 00:00:00 2001 From: meshmote Date: Wed, 8 Oct 2014 21:32:11 -0700 Subject: [PATCH 07/12] Added success message to testing block --- Students/RPerkins/session02/ack.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Students/RPerkins/session02/ack.py b/Students/RPerkins/session02/ack.py index d9c3cbf5..d54b896e 100644 --- a/Students/RPerkins/session02/ack.py +++ b/Students/RPerkins/session02/ack.py @@ -2,7 +2,7 @@ def ack(m, n): - """Return the result of the Ackerman function on m and n""" + """Return the result of the Ackermann function on m and n""" if m < 0 or n < 0: return None elif m == 0: @@ -12,6 +12,7 @@ def ack(m, n): elif m > 0 and n > 0: return ack(m-1, ack(m, n-1)) +# Testing Block if __name__ == "__main__": assert ack(-1, 2) is None assert ack(2, -1) is None @@ -41,4 +42,5 @@ def ack(m, n): #assert ack(4, 1) == 2**2**2**2-3 #assert ack(4, 2) == (2**65536)-3 #assert ack(4, 3) == (2**2**65536)-3 - #assert ack(4, 4) == (2**2**2**65536)-3 \ No newline at end of file + #assert ack(4, 4) == (2**2**2**65536)-3 + print 'All tests passed' \ No newline at end of file From 51d47ecb35cb14dc3c47a5df36b035add2567c45 Mon Sep 17 00:00:00 2001 From: meshmote Date: Wed, 8 Oct 2014 21:37:26 -0700 Subject: [PATCH 08/12] Added series.py module with empty fibonacci function --- Students/RPerkins/session02/series.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Students/RPerkins/session02/series.py diff --git a/Students/RPerkins/session02/series.py b/Students/RPerkins/session02/series.py new file mode 100644 index 00000000..475a9f9b --- /dev/null +++ b/Students/RPerkins/session02/series.py @@ -0,0 +1,2 @@ +def fibonacci(n): + """Return the 'n'th value in the Fibonacci series""" \ No newline at end of file From 512365b03f781dfe4b5ce6c726a645d7ff73c706 Mon Sep 17 00:00:00 2001 From: meshmote Date: Sat, 11 Oct 2014 15:45:59 -0700 Subject: [PATCH 09/12] Added fibonacci and lucas series code and test blocks --- Students/RPerkins/session02/series.py | 47 ++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/Students/RPerkins/session02/series.py b/Students/RPerkins/session02/series.py index 475a9f9b..5e73056a 100644 --- a/Students/RPerkins/session02/series.py +++ b/Students/RPerkins/session02/series.py @@ -1,2 +1,47 @@ +__author__ = 'Robert W. Perkins' + + def fibonacci(n): - """Return the 'n'th value in the Fibonacci series""" \ No newline at end of file + """Return the 'n'th value in the Fibonacci series""" + +# test for input in valid range + if n < 0: + return None + +# test for n == 0 + if n == 0: + return 0 + +# base case is n == 1 + if n == 1: + return 1 + else: + return fibonacci(n-1) + fibonacci(n-2) + +def lucas(n): + """Return the 'n'th value in the Lucas number series""" + +# test for input in valid range + if n < 0: + return None + +# test for n == 0 + if n == 0: + return 2 + +# base case is n == 1 + if n == 1: + return 1 + else: + return lucas(n-1) + lucas(n-2) + +# Testing Block +if __name__ == "__main__": + assert fibonacci(-3) is None + assert fibonacci(0) == 0 + assert fibonacci(1) == 1 + assert fibonacci(17) == 1597 + assert lucas(-3) is None + assert lucas(0) == 2 + assert lucas(1) == 1 + assert lucas(10) == 123 \ No newline at end of file From 9986a2b0fae8bde994b68aa0d812fc659b93b7d7 Mon Sep 17 00:00:00 2001 From: meshmote Date: Sat, 11 Oct 2014 16:07:31 -0700 Subject: [PATCH 10/12] added sum_series function and partial test block --- Students/RPerkins/session02/series.py | 39 ++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/Students/RPerkins/session02/series.py b/Students/RPerkins/session02/series.py index 5e73056a..effc9992 100644 --- a/Students/RPerkins/session02/series.py +++ b/Students/RPerkins/session02/series.py @@ -35,13 +35,50 @@ def lucas(n): else: return lucas(n-1) + lucas(n-2) +def sum_series(n,first=0,second=1): + """Return the 'n'th value of a variable series""" + + """The first two numbers are passed via "first" and "second" + and each subsequent element is the sum of n-1 and n-2""" + +# test for input in valid range + if n < 0: + return None + +# test for n == 0 + if n == 0: + return first + +# base case is n == 1 + if n == second: + return 1 + else: + return sum_series(n-1) + sum_series(n-2) + + + # Testing Block if __name__ == "__main__": + + # test fibonacci function for out of range, n == zero, base case, and 18th value in series assert fibonacci(-3) is None assert fibonacci(0) == 0 assert fibonacci(1) == 1 assert fibonacci(17) == 1597 + + # test lucas function for out of range, n == zero, base case, and 11th value in series assert lucas(-3) is None assert lucas(0) == 2 assert lucas(1) == 1 - assert lucas(10) == 123 \ No newline at end of file + assert lucas(10) == 123 + + # tests sum_series function for + assert sum_series(-3) is None + assert sum_series(0) == 0 + assert sum_series(1) == 1 + assert sum_series(17) == 1597 + + assert sum_series(-3,2,1) is None + assert sum_series(0,2,1) == 2 + assert sum_series(1,2,1) == 1 + assert sum_series(10,2,1) == 123 From e8dc4a78cabe97b583a0ca271d7d106c3c90477d Mon Sep 17 00:00:00 2001 From: meshmote Date: Sat, 11 Oct 2014 16:38:17 -0700 Subject: [PATCH 11/12] Fixed missing params in sum_series recursive calls and added final test code --- Students/RPerkins/session02/series.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Students/RPerkins/session02/series.py b/Students/RPerkins/session02/series.py index effc9992..6686e3b1 100644 --- a/Students/RPerkins/session02/series.py +++ b/Students/RPerkins/session02/series.py @@ -39,7 +39,7 @@ def sum_series(n,first=0,second=1): """Return the 'n'th value of a variable series""" """The first two numbers are passed via "first" and "second" - and each subsequent element is the sum of n-1 and n-2""" + and each subsequent element is the sum of the 'n-1'th and 'n-2th' element""" # test for input in valid range if n < 0: @@ -50,11 +50,10 @@ def sum_series(n,first=0,second=1): return first # base case is n == 1 - if n == second: - return 1 + if n == 1: + return second else: - return sum_series(n-1) + sum_series(n-2) - + return sum_series(n-1,first,second) + sum_series(n-2,first,second) # Testing Block @@ -72,13 +71,20 @@ def sum_series(n,first=0,second=1): assert lucas(1) == 1 assert lucas(10) == 123 - # tests sum_series function for + # tests sum_series function for fibonacci behavior with no optional params assert sum_series(-3) is None assert sum_series(0) == 0 assert sum_series(1) == 1 assert sum_series(17) == 1597 + # tests sum_series function for lucas behavior with lucas series params assert sum_series(-3,2,1) is None assert sum_series(0,2,1) == 2 assert sum_series(1,2,1) == 1 assert sum_series(10,2,1) == 123 + + # tests sum_series function for valid results with optional params + assert sum_series(-3,4,2) is None + assert sum_series(0,4,2) == 4 + assert sum_series(1,4,2) == 2 + assert sum_series(10,4,2) == 246 \ No newline at end of file From 6894a687243aaeb59e36d55b31b2a46711f43e55 Mon Sep 17 00:00:00 2001 From: meshmote Date: Sat, 11 Oct 2014 16:45:36 -0700 Subject: [PATCH 12/12] added test block comments --- Students/RPerkins/session02/series.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Students/RPerkins/session02/series.py b/Students/RPerkins/session02/series.py index 6686e3b1..041742a8 100644 --- a/Students/RPerkins/session02/series.py +++ b/Students/RPerkins/session02/series.py @@ -39,7 +39,7 @@ def sum_series(n,first=0,second=1): """Return the 'n'th value of a variable series""" """The first two numbers are passed via "first" and "second" - and each subsequent element is the sum of the 'n-1'th and 'n-2th' element""" + and each subsequent element is the sum of the 'n-1'th and 'n-2'th element (yes, i said tooth)""" # test for input in valid range if n < 0: @@ -72,18 +72,21 @@ def sum_series(n,first=0,second=1): assert lucas(10) == 123 # tests sum_series function for fibonacci behavior with no optional params + # for out of range, n == zero, base case, and 18th value in series assert sum_series(-3) is None assert sum_series(0) == 0 assert sum_series(1) == 1 assert sum_series(17) == 1597 # tests sum_series function for lucas behavior with lucas series params + # for out of range, n == zero, base case, and 11th value in series assert sum_series(-3,2,1) is None assert sum_series(0,2,1) == 2 assert sum_series(1,2,1) == 1 assert sum_series(10,2,1) == 123 # tests sum_series function for valid results with optional params + # for out of range, n == zero, base case, and 11th value in series assert sum_series(-3,4,2) is None assert sum_series(0,4,2) == 4 assert sum_series(1,4,2) == 2