[clean-list] stupid question

David Minor david-m at orbotech.com
Tue Dec 11 10:05:32 MET 2007


I expected it to recurse on isum until x<10, that is isum 999 should equal 9, why does it terminate at 27?


-----Original Message-----
From: Cristian Baboi [mailto:cristi at ot.onrc.ro] 
Sent: Tuesday, December 11, 2007 11:00 AM
To: David Minor
Cc: clean-list at science.ru.nl
Subject: Re: [clean-list] stupid question


On Tue, 11 Dec 2007 10:46:45 +0200, David Minor <david-m at orbotech.com>  
wrote:

> I must be missing something obvious, I'm going through the tutorial, why
> doesn't the following terminate on a one digit number when given 999 as
> expected?

I don't know what is expected, but it sums the digit of numbers given in  
the lists.
1+8=9
3 = 3
9+9+9 = 27


> module test
>
> import StdEnv
>
>
> Start = [isum 18, isum 3, isum 999]
>
>
> isum :: Int -> Int
>
> isum x
>
>             | x<10 = x
>
>             | otherwise = ones x + isum (x / 10)
>
>
> div9 :: Int -> Bool
>
> div9 x
>
>             | isum x == 9 = True
>
>             | otherwise = False
>
>
> ones :: Int -> Int
>
> ones x = (x - ((x / 10) * 10))
>
>
> Thanks,
>
> David
>
>
>
>
>
> ________ Information from NOD32 ________
> This message was checked by NOD32 Antivirus System for Linux Mail  
> Servers.
>    - is OK
>   part000.txt - is OK
>   part001.htm - is OK
>   part001.txt - is OK
> http://www.eset.com




________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
  part000.txt - is OK
http://www.eset.com



More information about the clean-list mailing list