Skip to content

Instantly share code, notes, and snippets.

@marchdown
Created November 21, 2014 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marchdown/c1f78216c5d31b3df8ed to your computer and use it in GitHub Desktop.
Save marchdown/c1f78216c5d31b3df8ed to your computer and use it in GitHub Desktop.
def comp2(f,g):
return lambda x: f(g(x))
def comp(*fs):
return reduce(comp2, fs)
def reduce(reducing_function, fs, initial_value=None):
fs = iter(fs)
v = fs.next() if initial_value is None else initial_value
for f in fs:
v = reducing_function(v, f)
return v
def inc(x):
return x + 1
def double(x):
return x * 2
def droot(x):
while (len(str(x))>1):
x = sum(map(int, str(x)))
return x
def droot_(x):
while (len(str(x))>1):
x = sum(map(int, str(x)))
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment