Egyptian division: Difference between revisions
m
→Python :: Functional: (Tidying)
m (Simplified Prolog code) |
m (→Python :: Functional: (Tidying)) |
||
Line 1,797:
#
# main :: IO ()
def main():
'''Test'''
print(
eqyptianQuotRem(580)(34)
Line 1,807 ⟶ 1,806:
#
# Just :: a -> Maybe a
Line 1,822 ⟶ 1,820:
# unfoldl(lambda x: Just(((x - 1), x)) if 0 != x else Nothing())(10)
# -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# unfoldl :: (b -> Maybe (b, a)) -> b -> [a]
def unfoldl(f):
'''Dual to reduce or foldl.
Where
and the residual b
application of f.
When f returns Nothing, the completed list is returned.
'''
def go(v):
xs = []
while True:
mb = f(
if mb.get('Nothing'):
return xs
else:
xs.insert(0,
return xs
return
|