-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10recursion.py
More file actions
76 lines (52 loc) · 1.08 KB
/
Copy path10recursion.py
File metadata and controls
76 lines (52 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 10/9/2018
# Recursion!
"""
1! = 1 = 1 : base case
pattern:
2! = 2 = 2*1 = 2*1!
3! = 6 = 3*2*1 = 3*2!
...
n! = n(n-1)!
"""
"""recursive factorial function
# limit to recursive function ~ 998,999
def fact(n):
# pseudo code - putting function on hold to come back later
if n is 1:
# return ends function
return 1
return n*fact(n-1)
print (fact(999))
"""
"""
def add(a,b):
return a+b
"""
#--------------
# Coding Bat!
#--------------
"""counting number of x's in a string with RECURSION!
def countx(user):
# count = 0
if len(user) == 0:
return 0
elif user[0] == 'x':
return 1 + countx(user[1:])
elif user[0] != 'x':
return countx(user[1:])
user = input("Input string: ")
print("Number of x's:", countx(user))
"""
def crazy_eights(numbers):
if len(numbers) == 0:
return 0
elif numbers[0] == '8':
if len(numbers) == 1:
return 1
elif numbers[1] == '8':
return 2 + crazy_eights(numbers[1:])
elif numbers[1] != '8':
return 1 + crazy_eights(numbers[1:])
elif numbers[0] != '8':
return crazy_eights(numbers[1:])
print(crazy_eights("98023402488888"))