Jump to content

McNuggets problem: Difference between revisions

m
Line 1,155:
 
box = size(limit)
return set(bind(box(6))(
lambda x:bind(
mapbox(f, xs6)
 
)(lambda x: bind(box(9))(
lambda y:box(9)
)(lambda y: bind(
 
bind(box(20))(
)(lambda z: (
lambda v=sum([x, y, z]): (
 
[] if v > lambdalimit v=sum([x,else y, z[v]): (
[] if v > limit else [v])
)())))
)()))))
 
 
Line 1,192:
 
 
# TEST --------------------------------- TEST --------------------------
def main():
'''List monad and set comprehension - parallel routes'''
Line 1,218:
 
 
# GENERIC ABSTRACTIONS ------------------------ GENERIC -------------------------
 
# bind (>>=) :: [a] -> (a -> [b]) -> [b]
Line 1,227:
passed as an argument to the second.
'''
return lambda f: listchain.from_iterable(
chain.from_iterablemap(f, xs)
map(f, xs)
)
)
 
Line 1,237 ⟶ 1,235:
def enumFromThenTo(m):
'''Integer values enumerated from m to n
with a step defined by nxt - m.
'''
def go(nxt, n):
d = nxt - m
return range(m, n - 1 if d < 0 else 1 + n, d)
return lambda nxt: lambda n: list(go(nxt, n))
 
 
# FORMATTING ------------------------ DISPLAY -------------------------
 
# fTable :: String -> (a -> String) ->
# (b -> String) -> (a -> b) -> [a] -> String
def fTable(s):
'''Heading -> x display function -> fx display function ->
f -> xs -> tabular string.
'''
def gogox(xShow, fxShow, f, xs):
ysdef = [xShowgofx(xfxShow) for x in xs]:
w = max(map(len, ys) def gof(f):
return s + '\n' + '\n'.join(map def goxs(xs):
lambda x, y: y.rjust(w, ' ') + ' ->ys '= + fxShow(f[xShow(x)), for x in xs]
xs w = max(map(len, ys))
 
))
def arrowed(x, y):
return lambda xShow: lambda fxShow: lambda f: lambda xs: go(
return y.rjust(w, ' ') + ' -> ' + fxShow(f(x))
xShow, fxShow, f, xs
return s + '\n' + '\n'.join(
)
map(arrowed, xs, ys)
)
return goxs
return gof
))return gofx
return gox
 
 
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.