Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  any feedback on this solution (Kees Bleijenberg)
   2. Re:  recursion problem. (Joel Neely)
   3. Re:  sum problem (Joel Neely)
   4. Re:  sum problem (Roelof Wobben)
   5. Re:  any feedback on this solution (Joel Williamson)


----------------------------------------------------------------------

Message: 1
Date: Sat, 7 Feb 2015 13:48:25 +0100
From: "Kees Bleijenberg" <[email protected]>
To: "'The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell'" <[email protected]>
Subject: Re: [Haskell-beginners] any feedback on this solution
Message-ID: <[email protected]>
Content-Type: text/plain;       charset="us-ascii"

Roelof,

Say, you find after a few months a bug or a better algorithm for toDigits,
then you have to remember that sumDigits uses this algorithm (in a bit
different form) too. In this case the functions are so small that it is not
a problem.

If you apply toDigits to all elements of a list of int's and  you get almost
the solution
apply toDigits to alle elements of [4,12,3] and you get [[4],[1,2],[3]],
which is a small step to [4,1,2,3]

Kees

-----Oorspronkelijk bericht-----
Van: Beginners [mailto:[email protected]] Namens Roelof Wobben
Verzonden: zaterdag 7 februari 2015 11:02
Aan: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell
Onderwerp: Re: [Haskell-beginners] any feedback on this solution

Why,

They have opposite terms.

SumDigits takes a array and has a integer as output.
ToDigits takes a integer and puts  out a array.

Roelof


Kees Bleijenberg schreef op 7-2-2015 om 10:56:
> Roelof,
>
> Maybe it's better to reuse toDigits in sumDigits.
>
> Kees
>
> -----Oorspronkelijk bericht-----
> Van: Beginners [mailto:[email protected]] Namens Roelof 
> Wobben
> Verzonden: zaterdag 7 februari 2015 10:37
> Aan: The Haskell-Beginners Mailing List - Discussion of primarily 
> beginner-level topics related to Haskell
> Onderwerp: [Haskell-beginners] any feedback on this solution
>
> Hello,
>
> I finally solved exercise 1 where I had to write a programm which 
> checks if a creditcard number is valid.
>
> I solved it this way :
>
> toDigits :: Integer -> [Integer]
> toDigits n
>      | n < 0 = []
>      | n < 10 = [n]
>      | otherwise =  toDigits (n `div` 10) ++ [n `mod` 10]
>
> -- | convert a number to a reversed array where a negative number will 
> be a empty array toDigitsRev :: Integer -> [Integer] toDigitsRev 0 = 
> [0] toDigitsRev n
>      | n < 0 = []
>      | n < 10 = [n]
>      | otherwise = n `mod` 10 : toDigitsRev (n `div` 10)
>
>    -- | Doubles every second number from the right.
> doubleEveryOther :: [Integer] -> [Integer]
> doubleEveryOther []         = []
> doubleEveryOther (x:[])     = [x]
> doubleEveryOther (x:(y:zs))
>      | length (x:(y:zs)) `mod` 2 /= 0 = [x] ++ (y * 2) : doubleEveryOther
zs
>      | otherwise = [x *2]  ++ y : doubleEveryOther zs
>
>
> -- | sum all the digits of a array
> sumDigits :: [Integer] -> Integer
> sumDigits []  = 0
> sumDigits (x:zs)
>      | x < 10     = x + sumDigits zs
>      | otherwise  = x `mod` 10 + x `div` 10 + sumDigits zs
>
>
> -- | validate a number by looking if a number can be divided by 10 
> validate :: Integer -> Bool validate n = 
> sumDigits(doubleEveryOther(toDigits(n))) `mod` 10 == 0
>
>
> -- | The main entry point.
> main :: IO ()
> main = do
>       print $ validate  4012888888881881
>
> Any remarks about this solution.
>
> I know there are higher function solutions but that part is not 
> descrived in chapter 1 .
>
> Roelof
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2015.0.5646 / Virus Database: 4281/9071 - Release Date: 
> 02/07/15
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2015.0.5646 / Virus Database: 4281/9071 - Release Date: 02/07/15



------------------------------

Message: 2
Date: Sat, 7 Feb 2015 07:25:32 -0600
From: Joel Neely <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] recursion problem.
Message-ID:
        <CAEEzXAgXoV95jpfpBVi=jbtfgp9uey7rqaetc+oudbkwdkq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Brilliantly succinct answer!

And the programming task that started this thread is a nice (though
microscopic) illustration of the culture shock when our tidy, jewel-like
programming models come to grips with the messy, non-systematic nature of
many application domains.

Thanks for both.

-jn-


On Fri, Feb 6, 2015 at 10:59 PM, Karl Voelker <[email protected]> wrote:

> On Fri, Feb 6, 2015, at 01:25 AM, Roelof Wobben wrote:
> > but now when I do toDigits 0 , I see [] as output where I was expected
> > [0]
>
> In our written notation, "0" is a special case: it's the only integer
> written with a leading zero. So don't be too surprised if your code
> requires a special case for it.
>
> -Karl
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Beauty of style and harmony and grace and good rhythm depend on simplicity.
- Plato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150207/e23edcea/attachment-0001.html>

------------------------------

Message: 3
Date: Sat, 7 Feb 2015 07:42:21 -0600
From: Joel Neely <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] sum problem
Message-ID:
        <CAEEzXAjSEykjj4h2vGRY-Sp+0hS6miYRhe9AP7RSMVmOEh=m...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Question/hint:  You refer to acc three times, all in the right-hand-side
expressions. Where is acc defined?

-jn-

On Sat, Feb 7, 2015 at 2:53 AM, Roelof Wobben <[email protected]> wrote:

> Hello,
>
> The exercises of CIS 194 are really hard.
>
> Now I have to sum all the numbers in a array with a catch
> If a number is greater then 10 it has to be dived in single numbers.
>
> so [ 1 , 12, 3] will be [ 1, 1,2,3] and then sum up.
>
> So far I have this :
>
> -- | sum all the digits of a array
> sumDigits :: [Integer] -> Integer
> sumDigits n
>    | n == 0 = acc
>    | n < 10 = acc + n
>    | otherwise = sumDigits acc + n `mod` 10 + n `rem` 10
>
>
> But now I see a message that acc is not known which is not wierd.
>
> But when I do sumDigits n acc I see a message that sumDigits has only 1
> parameter where I give it to,
>
> When I only had to sum up i is easy , I could use map [+] xs
>
> Anyone  who can give a me tip without giving the answer otherwise I do not
> learn anything.
>
> Roelof
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Beauty of style and harmony and grace and good rhythm depend on simplicity.
- Plato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150207/c5153f11/attachment-0001.html>

------------------------------

Message: 4
Date: Sat, 07 Feb 2015 16:52:55 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] sum problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150207/f33cf831/attachment-0001.html>

------------------------------

Message: 5
Date: Sat, 07 Feb 2015 15:56:14 +0000
From: Joel Williamson <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] any feedback on this solution
Message-ID:
        <cajgxserjkhy+oocvnkpkjaf3hyptwbqvfrf3vfkmcatcrio...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Roelof,

It doesn't look like you ever call toDigitsRev. To keep the solution
clearer, you should remove any unneeded definitions.

Joel

On Sat, 7 Feb 2015 07:50 Kees Bleijenberg <[email protected]>
wrote:

> Roelof,
>
> Say, you find after a few months a bug or a better algorithm for toDigits,
> then you have to remember that sumDigits uses this algorithm (in a bit
> different form) too. In this case the functions are so small that it is not
> a problem.
>
> If you apply toDigits to all elements of a list of int's and  you get
> almost
> the solution
> apply toDigits to alle elements of [4,12,3] and you get [[4],[1,2],[3]],
> which is a small step to [4,1,2,3]
>
> Kees
>
> -----Oorspronkelijk bericht-----
> Van: Beginners [mailto:[email protected]] Namens Roelof Wobben
> Verzonden: zaterdag 7 februari 2015 11:02
> Aan: The Haskell-Beginners Mailing List - Discussion of primarily
> beginner-level topics related to Haskell
> Onderwerp: Re: [Haskell-beginners] any feedback on this solution
>
> Why,
>
> They have opposite terms.
>
> SumDigits takes a array and has a integer as output.
> ToDigits takes a integer and puts  out a array.
>
> Roelof
>
>
> Kees Bleijenberg schreef op 7-2-2015 om 10:56:
> > Roelof,
> >
> > Maybe it's better to reuse toDigits in sumDigits.
> >
> > Kees
> >
> > -----Oorspronkelijk bericht-----
> > Van: Beginners [mailto:[email protected]] Namens Roelof
> > Wobben
> > Verzonden: zaterdag 7 februari 2015 10:37
> > Aan: The Haskell-Beginners Mailing List - Discussion of primarily
> > beginner-level topics related to Haskell
> > Onderwerp: [Haskell-beginners] any feedback on this solution
> >
> > Hello,
> >
> > I finally solved exercise 1 where I had to write a programm which
> > checks if a creditcard number is valid.
> >
> > I solved it this way :
> >
> > toDigits :: Integer -> [Integer]
> > toDigits n
> >      | n < 0 = []
> >      | n < 10 = [n]
> >      | otherwise =  toDigits (n `div` 10) ++ [n `mod` 10]
> >
> > -- | convert a number to a reversed array where a negative number will
> > be a empty array toDigitsRev :: Integer -> [Integer] toDigitsRev 0 =
> > [0] toDigitsRev n
> >      | n < 0 = []
> >      | n < 10 = [n]
> >      | otherwise = n `mod` 10 : toDigitsRev (n `div` 10)
> >
> >    -- | Doubles every second number from the right.
> > doubleEveryOther :: [Integer] -> [Integer]
> > doubleEveryOther []         = []
> > doubleEveryOther (x:[])     = [x]
> > doubleEveryOther (x:(y:zs))
> >      | length (x:(y:zs)) `mod` 2 /= 0 = [x] ++ (y * 2) : doubleEveryOther
> zs
> >      | otherwise = [x *2]  ++ y : doubleEveryOther zs
> >
> >
> > -- | sum all the digits of a array
> > sumDigits :: [Integer] -> Integer
> > sumDigits []  = 0
> > sumDigits (x:zs)
> >      | x < 10     = x + sumDigits zs
> >      | otherwise  = x `mod` 10 + x `div` 10 + sumDigits zs
> >
> >
> > -- | validate a number by looking if a number can be divided by 10
> > validate :: Integer -> Bool validate n =
> > sumDigits(doubleEveryOther(toDigits(n))) `mod` 10 == 0
> >
> >
> > -- | The main entry point.
> > main :: IO ()
> > main = do
> >       print $ validate  4012888888881881
> >
> > Any remarks about this solution.
> >
> > I know there are higher function solutions but that part is not
> > descrived in chapter 1 .
> >
> > Roelof
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> >
> > -----
> > No virus found in this message.
> > Checked by AVG - www.avg.com
> > Version: 2015.0.5646 / Virus Database: 4281/9071 - Release Date:
> > 02/07/15
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2015.0.5646 / Virus Database: 4281/9071 - Release Date: 02/07/15
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150207/d9d205d0/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 80, Issue 14
*****************************************

Reply via email to