Repository navigation
Initial commit #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Initial commit #60
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| Git Primer | ||
|
|
||
| What is a graph? | ||
|
|
||
| >>A 'graph' - in the world of computer science, | ||
| >>a state/place connected by paths. | ||
|
|
||
| What is an example of recurssive function? | ||
|
|
||
| >> | ||
|
|
||
| - ex using factorials | ||
|
|
||
| def factorial(x): | ||
| if x == 1: | ||
| return 1 | ||
| else: | ||
| return x * factorial(x-1) | ||
|
|
||
| >>factorial(5) | ||
| >>120 | ||
|
|
||
| In math, the factorial of an integer is the | ||
| result of multiplying that integer by every | ||
| integer smaller than it down to 1. | ||
|
|
||
| 5! == 5 * 4 * 3 * 2 * 1 | ||
|
|
||
|
|
||
| What is a module? | ||
|
|
||
| >> basically anything that ends in | ||
| >> .py counts as a module | ||
|
|
||
|
|
||
| What is a package? | ||
|
|
||
| >>IN ORDER For it to be a python package....needs | ||
| >>an __init__.py | ||
|
|
||
| What is the HMK? | ||
|
|
||
| >> 1. Create a module called ack.py. | ||
| >> put it in a session02 folder in your student | ||
| >> folder. Write a function for the Ackerman | ||
| >> function | ||
|
|
||
| >> 2. Fibronaci & Lucas functions | ||
| >> and one that can do either | ||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| __author__ = 'Ari' | ||
|
|
||
|
|
||
| class ackerman: | ||
| def ack(m,n): | ||
| """Return a non-negative integer based on the Ackerman function | ||
|
|
||
| Definition of Ackerman: http://en.wikipedia.org/wiki/Ackermann_function | ||
|
|
||
| m, n: non-negative integers""" | ||
|
|
||
| # validate that m is NOT a negative number | ||
| if m < 0: | ||
| return None | ||
|
|
||
| # validate that n is NOT a negative number | ||
| if n < 0: | ||
| return None | ||
|
|
||
| if m == 0: | ||
| return n+1 | ||
|
|
||
| if m > 0 and n == 0: | ||
| return ack(m-1,1) | ||
|
|
||
| return ack(m-1, ack(m, n-1)) | ||
|
|
||
| def main(): | ||
|
|
||
| input_m = int(sys.argv[1]) | ||
| input_n = int(sys.argv[2]) | ||
|
|
||
| ackerman.ack(input_m, input_n) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| __author__ = 'Ari' | ||
|
|
||
| def fibonacci(n): | ||
| """Return the nth value based on the Fibonacci sequence. | ||
| For the purpose of this assignment I decided to start the | ||
| sequence at 0""" | ||
| current_num = 0 | ||
| prev_num = 1 | ||
| # first two values have already been set, thus n-2 | ||
| for i in range(0, n-2): | ||
| temp = current_num | ||
| current_num = prev_num | ||
| prev_num= temp + prev_num | ||
| return prev_num | ||
|
|
||
| def lucas(n): | ||
| """Return the nth value based on the Lucas sequence""" | ||
| current_num = 2 | ||
| prev_num = 1 | ||
| # first two values have already been set, thus n-2 | ||
| for i in range(0, n-2): | ||
| temp = current_num | ||
| current_num = prev_num | ||
| prev_num = temp + prev_num | ||
| return prev_num | ||
|
|
||
| def sum_series(n, current_num=0, prev_num=1): | ||
| """Return the nth value of either the Fibonacci sequence (default) or the Lucas sequence.""" | ||
| # CURRENTLY this function doesn't work...returns nothing | ||
| # I am not sure why, but my initial if statement | ||
| # also is throwing syntax errors (when I inspect it | ||
| # with the IDE | ||
| if current_num=0 and prev_num=1: | ||
| fibonacci(n) | ||
| else: | ||
| lucas(n) | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| __author__ = 'Ari' | ||
|
|
||
| from ack import ackerman | ||
| import unittest | ||
|
|
||
| # Note to Chris: So, I was experimenting with classes | ||
| # and I've had this problem in the past where I try to run | ||
| # test_somefunction and I get "You have 3 arguments, only need 2" | ||
| # I'd really like to understand why this is (I can surmise it | ||
| # is about the 'self'). Also what is 'unittest.TestCase'?? | ||
|
|
||
| class test_ackerman(unittest.TestCase): | ||
|
|
||
| def test_ack(self): | ||
| # coordinates 0,0 | ||
| test_func = ackerman() | ||
| m = 0 | ||
| n = 0 | ||
| result = test_func.ack(m,n) | ||
| assert_equal(result,1) | ||
|
|
||
| def test_ack(self): | ||
| # coordinates 0,1 | ||
| test_func = ackerman() | ||
| result = test_func.ack(0,1) | ||
| assert_equal(result, 2) | ||
|
|
||
| def test_ack(self): | ||
| # coordinates 1,2 | ||
| test_func = ackerman() | ||
| result = test_func.ack(1,2) | ||
| assert_equal(result, 4) | ||
|
|
||
| def test_ack(self): | ||
| # coordinates 2,2 | ||
| test_func = ackerman() | ||
| result = test_func.ack(2,2) | ||
| assert_equal(result,7) | ||
|
|
||
| def test_ack(self): | ||
| # coordinates 2,3 | ||
| test_func = ackerman() | ||
| result = test_func.ack(2,3) | ||
| assert_equal(result,9) | ||
|
|
||
| def test_ack(self): | ||
| # coordinates 1,4 | ||
| test_func = ackerman() | ||
| result = test_func.ack(1,4) | ||
| assert_equal(result, 6) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting ahead of yourself!