This file contains 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
def num_paths(n): | |
""" | |
A function to calculate the number of different paths up a flight of stairs that has n-steps, if you can only move | |
1,2,3 steps at a time. | |
""" | |
# Base cases: | |
if n < 0: | |
return 0 | |
if n == 1: |
This file contains 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
def sum(array): | |
# Base Case: | |
if len(array) == 1: | |
return array[0] | |
# Inductive Step: | |
return array[0] + sum(array[1:]) | |
print(sum([1,2,3,4,5])) |