Skip to content

Commit 99c4dec

Browse files
committed
Adding session2 HW
1 parent 09df765 commit 99c4dec

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

Students/Tyler G/session2/Ack.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
3+
def Ack(m, n):
4+
"""
5+
This is the Ackerman function
6+
which is recursive and I don't understand
7+
all that well. It returns a non-negative integer.
8+
"""
9+
if m < 0 or n < 0:
10+
return None
11+
if m == 0:
12+
return n + 1
13+
elif m > 0 and n == 0:
14+
return Ack(m-1,1)
15+
elif m > 0 and n > 0:
16+
return Ack(m-1,Ack(m,n-1))
17+
18+
def main():
19+
m_entry = int((sys.argv[1]))
20+
n_entry = int((sys.argv[2]))
21+
22+
print Ack(m_entry, n_entry)
23+
24+
if __name__ == "__main__":
25+
main()
26+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
#Session 2 Extra Credit
4+
def FizzBuzzFrodoBilboGandalf(n):
5+
for i in range(1,n+1):
6+
holder = " "
7+
if i % 3 == 0:
8+
holder += "Fizz"
9+
if i % 5 == 0:
10+
holder += "Buzz"
11+
if i % 7 == 0:
12+
holder += "Frodo"
13+
if i % 11 == 0:
14+
holder += "Bilbo"
15+
if i % 13 == 0:
16+
holder += "Gandalf"
17+
if holder == " ":
18+
print i
19+
else:
20+
print holder.lstrip(" ")
21+
22+
23+
FizzBuzzFrodoBilboGandalf(100)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
def fibonacci(n):
2+
"""
3+
Returns the nth value of the fibonacci sequence.
4+
"""
5+
sequence = [0,1]
6+
for i in range(n-2):
7+
sequence.append(sequence[len(sequence)-2] + sequence[len(sequence)-1])
8+
return sequence[n-1]
9+
10+
def lucas(n):
11+
"""
12+
Returns the nth value of the lucas sequence. It is
13+
the same as the fibonacci series except the starting
14+
numbers are 2 and 1 instead of 0 and 1.
15+
"""
16+
sequence = [2,1]
17+
for i in range(n-2):
18+
sequence.append(sequence[len(sequence)-2] + sequence[len(sequence)-1])
19+
return sequence[n-1]
20+
21+
def sum_series(n, o = 0, p = 1):
22+
"""
23+
First parameter returns nth value of series. The second
24+
and third optional parameters allows the user to define
25+
the first two values in the fibonacci sequence.
26+
"""
27+
sequence = [o, p]
28+
for i in range(n-2):
29+
sequence.append(sequence[len(sequence)-2] + sequence[len(sequence)-1])
30+
return sequence[n-1]
31+
32+
def main():
33+
n_entry = int((sys.argv[1]))
34+
o_entry = int((sys.argv[2]))
35+
p_entry = int((sys.argv[3]))
36+
37+
print sum_series(n_entry, o_entry, p_entry)
38+
39+
if __name__ == "__main__":
40+
main()

0 commit comments

Comments
 (0)