Talk:Egyptian division: Difference between revisions

Content added Content deleted
(Trying to get the wiki link right :-))
Line 8: Line 8:


:: Fair enough – it's essentially a hylomorphism [https://en.wikipedia.org/wiki/Hylomorphism_(computer_science)], and it seems reasonable / sufficient to ask people not to fuse the building up and the stripping down to the extent that the intermediate data structure is concealed. In the Haskell, JS, and AppleScript versions I've pulled that out and named it 'rows' rather than fusing it out of sight. I hope that seems enough to you :-) [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 19:09, 10 August 2017 (UTC)
:: Fair enough – it's essentially a hylomorphism [https://en.wikipedia.org/wiki/Hylomorphism_(computer_science)], and it seems reasonable / sufficient to ask people not to fuse the building up and the stripping down to the extent that the intermediate data structure is concealed. In the Haskell, JS, and AppleScript versions I've pulled that out and named it 'rows' rather than fusing it out of sight. I hope that seems enough to you :-) [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 19:09, 10 August 2017 (UTC)
::: A fused composition of the unfold and the fold, in which the rows were implicit but not directly visible, might look something like:
::::<lang Haskell>import Data.List (unfoldr)

egyptianQuotRem :: Integral a => a -> a -> (a, a)
egyptianQuotRem m n =
foldr
(\(i, x) (q, r) ->
if x < r
then (q + i, r - x)
else (q, r))
(0, m)
$ unfoldr
(\(i, x) ->
if x > m
then Nothing
else Just ((i, x), (i + i, x + x)))
(1, n)

main :: IO ()
main = print $ egyptianQuotRem 580 34</lang> [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 19:35, 10 August 2017 (UTC)