[clean-list] Re: stupid question

TK 0000tk at gmail.com
Wed Feb 20 16:13:58 MET 2008


>
> isum :: Int -> Int
> isum x
>    | x<10 = x
>    | otherwise = isum ((isum (x / 10)) + (x rem 10))
>
> Instead of "ones" I used "rem" (imported via StdEnv -> StdInt)
> And the recursion step is, first over x/10 and then adding that to the
> remainder, which is the last digit, and recursing again.
>

The outer "isum" call is partially redundant, always receiving numbers from
1 to 18.


isum x
| x < 10 = x
= isum0_18 ( ( isum ( x / 10 ) ) + ( x rem 10 ) )
where
isum0_18 x
| x < 10 = x
= x - 9

...is still partially redundant as "isum0_18" is never called with 0.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.science.ru.nl/pipermail/clean-list/attachments/20080220/00874852/attachment.html


More information about the clean-list mailing list