Teacup rim text: Difference between revisions

Content deleted Content added
Added C solution
Hout (talk | contribs)
Line 1,235: Line 1,235:
'''
'''
def go(ws):
def go(ws):
return concatMap(
def f(xs):
lambda xs: [
return [
[snd(x) for x in xs]
[snd(x) for x in xs]
] if n <= len(xs) >= len(xs[0][0]) else []
] if n <= len(xs) >= len(xs[0][0]) else []
)(
return concatMap(f)(groupBy(fst)(sorted(
groupBy(fst)(
[(''.join(sorted(w)), w) for w in ws],
sorted(
key=fst
)))
[(''.join(sorted(w)), w) for w in ws],
return go
key=fst
)
)
)
return lambda ws: go(ws)




Line 1,285: Line 1,281:
(0, True, rotated(w))
(0, True, rotated(w))
)[1]
)[1]
return go

return lambda s: go(s)




Line 1,306: Line 1,301:
(using an empty list to represent computational failure).
(using an empty list to represent computational failure).
'''
'''
return lambda xs: list(
def go(xs):
chain.from_iterable(map(f, xs))
return chain.from_iterable(map(f, xs))
)
return go




Line 1,323: Line 1,318:
in terms of the key function f.
in terms of the key function f.
'''
'''
return lambda xs: [
def go(xs):
return [
list(x[1]) for x in groupby(xs, key=f)
list(x[1]) for x in groupby(xs, key=f)
]
]
return go




Line 1,377: Line 1,374:
over a start value of x.
over a start value of x.
'''
'''
def go(f, x):
def go(f):
def g(a, i):
def g(x):
v = f(a) if i else x
def h(a, i):
return (v, v)
v = f(a) if i else x
return mapAccumL(g)(x)(
return (v, v)
range(0, 1 + n)
return mapAccumL(h)(x)(
)[1]
range(0, 1 + n)
return lambda f: lambda x: go(f, x)
)[1]
return g
return go




Line 1,392: Line 1,391:
The initial seed value is x.
The initial seed value is x.
'''
'''
def go(f, x):
def go(f):
v = x
def g(x):
while not p(v):
v = x
v = f(v)
while not p(v):
return v
v = f(v)
return lambda f: lambda x: go(f, x)
return v
return g
return go