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])) |
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 anagram_generator(string): | |
""" | |
A recursive function that generates a list of all possible anagrams for a given string. | |
""" | |
list = [] | |
# The last char in our string will be inserted at every index in order to generate sub-anagrams. | |
insert_char = string[len(string)-1] | |
# Base Case: if string is only 1 character. | |
if len(string) <= 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
#perl program simialr to cat, get input from user via Standar Input, and then print. | |
print foreach eval qw(<STDIN>); exit 0; |