McNuggets problem: Difference between revisions
m
→Python :: List monad: Tidied
m (→Python :: List monad: Tidied) |
|||
Line 1,155:
box = size(limit)
return set
)(lambda x: bind
)(lambda y: bind(
lambda v=sum([x, y, z]): (
[] if v >
Line 1,192:
#
def main():
'''List monad and set comprehension - parallel routes'''
Line 1,218:
#
# bind (>>=) :: [a] -> (a -> [b]) -> [b]
Line 1,227:
passed as an argument to the second.
'''
return lambda f:
▲ map(f, xs)
)▼
)
Line 1,237 ⟶ 1,235:
def enumFromThenTo(m):
'''Integer values enumerated from m to n
with a step defined by nxt
'''
def go(nxt, n):
d = nxt - m
return range(m, n - 1 if d < 0 else 1 + n, d)
return lambda nxt: lambda n:
#
# fTable :: String -> (a -> String) ->
#
def fTable(s):
'''Heading -> x display function -> fx display function ->
'''
def
))▼
def arrowed(x, y):
return y.rjust(w, ' ') + ' -> ' + fxShow(f(x))
return s + '\n' + '\n'.join(
map(arrowed, xs, ys)
▲ )
return goxs
return gof
return gox
|