Created
December 9, 2014 19:16
-
-
Save maryrosecook/6b5d94e61f55225b397d to your computer and use it in GitHub Desktop.
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
def zero(s): | |
if s[0] == "0": | |
return s[1:] | |
def one(s): | |
if s[0] == "1": | |
return s[1:] | |
""" | |
def rule_sequence(s, rules): | |
for rule in rules: | |
s = rule(s) | |
if s == None: | |
break | |
return s | |
""" | |
print rule_sequence('0101', [zero, one, zero]) | |
# => 1 | |
print rule_sequence('0101', [zero, zero]) | |
# => None | |
# Reimplement rule_sequence as a recursive function. | |
# Make sure that when it is run, it returns the results shown above. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment