Skip to content

Instantly share code, notes, and snippets.

@maryrosecook
Created December 9, 2014 19:16
Show Gist options
  • Save maryrosecook/6b5d94e61f55225b397d to your computer and use it in GitHub Desktop.
Save maryrosecook/6b5d94e61f55225b397d to your computer and use it in GitHub Desktop.
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