Egyptian division: Difference between revisions

m
m (Simplified Prolog code)
Line 1,797:
 
 
# TEST -------------------------- TEST --------------------------
# main :: IO ()
def main():
'''Test'''
 
print(
eqyptianQuotRem(580)(34)
Line 1,807 ⟶ 1,806:
 
 
# GENERIC FUNCTIONS -------------------- GENERIC FUNCTIONS -------------------
 
 
# 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 athese fold reducesreduce a list to a summary value, unfoldl
unfoldl builds a list from a seed value.
WhenWhere f returns Just(a, b), a is appended to the list,
and the residual b becomesis used as the argument for the next
application of f.
When f returns Nothing, the completed list is returned.'''
'''
def go(v):
xrx, r = v, v
xs = []
while True:
mb = f(xr[0]x)
if mb.get('Nothing'):
return xs
else:
xrx, r = mb.get('Just')
xs.insert(0, xr[1]r)
return xs
return lambda x: go(x)
 
 
9,655

edits