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. Help with improving a program (Marcelo Lacerda)
2. Re: Help with improving a program (Frerich Raabe)
3. Re: Help with improving a program (Francesco Ariis)
4. Re: Help with improving a program (Frerich Raabe)
----------------------------------------------------------------------
Message: 1
Date: Wed, 09 Jul 2014 23:02:14 -0300
From: Marcelo Lacerda <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Help with improving a program
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi I'm just starting with haskell and want some help with it.
I tried to solve the Store Credit[1] problem from google code jam just
to practice, the result was a slow code[2] that I find hard to read.
Can you guys give me some directions on how to improve it?
[1] - https://code.google.com/codejam/contest/351101/dashboard#s=p0
[2] - http://pastebin.com/jNGxGP5H
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 897 bytes
Desc: OpenPGP digital signature
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140709/9a0ef980/attachment-0001.sig>
------------------------------
Message: 2
Date: Thu, 10 Jul 2014 10:52:15 +0200
From: Frerich Raabe <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Help with improving a program
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
On 2014-07-10 04:02, Marcelo Lacerda wrote:
> Hi I'm just starting with haskell and want some help with it.
>
> I tried to solve the Store Credit[1] problem from google code jam just
> to practice, the result was a slow code[2] that I find hard to read.
>
> Can you guys give me some directions on how to improve it?
Accessing list elements via (!!) is rather inefficent for larger lists (it's
an O(n) operation), so try to avoid that. Also, the 'comb' function won't
scale very well for your particular use case. Since you only want to get all
pairs, something like
pairs :: [a] -> [(a, a)]
pairs [] = []
pairs [x] = []
pairs (x:xs) = map (\e -> (x, e)) xs ++ pairs xs
...would do, performing a lot better than 'comb 2'. The repeated usage of
(++) isn't exactly efficient either though but I couldn't think of a way to
avoid that while writing this mail. :-)
--
Frerich Raabe - [email protected]
www.froglogic.com - Multi-Platform GUI Testing
------------------------------
Message: 3
Date: Thu, 10 Jul 2014 11:24:22 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Help with improving a program
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On Wed, Jul 09, 2014 at 11:02:14PM -0300, Marcelo Lacerda wrote:
> Hi I'm just starting with haskell and want some help with it.
>
> I tried to solve the Store Credit[1] problem from google code jam just
> to practice, the result was a slow code[2] that I find hard to read.
>
> Can you guys give me some directions on how to improve it?
>
> [1] - https://code.google.com/codejam/contest/351101/dashboard#s=p0
> [2] - http://pastebin.com/jNGxGP5H
>
Don't know about efficiency, but I never liked (!!). Maybe computing all
pairs+positions in advance using |zip| would be a little better?
I attach my .hs; code is quite caveman-Haskell, but hopefully the idea is clear
-F
-------------- next part --------------
A non-text attachment was scrubbed...
Name: store.hs
Type: text/x-haskell
Size: 601 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140710/3d8e0670/attachment-0001.hs>
------------------------------
Message: 4
Date: Thu, 10 Jul 2014 11:35:02 +0200
From: Frerich Raabe <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Help with improving a program
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"; Format="flowed"
On 2014-07-10 11:24, Francesco Ariis wrote:
> On Wed, Jul 09, 2014 at 11:02:14PM -0300, Marcelo Lacerda wrote:
>> Hi I'm just starting with haskell and want some help with it.
>>
>> I tried to solve the Store Credit[1] problem from google code jam just
>> to practice, the result was a slow code[2] that I find hard to read.
>>
>> Can you guys give me some directions on how to improve it?
>>
>> [1] - https://code.google.com/codejam/contest/351101/dashboard#s=p0
>> [2] - http://pastebin.com/jNGxGP5H
>>
>
> Don't know about efficiency, but I never liked (!!). Maybe computing all
> pairs+positions in advance using |zip| would be a little better?
Yeah, that's what I went for as well. I'm attaching my solution for
comparison to this mail.
--
Frerich Raabe - [email protected]
www.froglogic.com - Multi-Platform GUI Testing
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Main.hs
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140710/84fd2b59/attachment-0001.ksh>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 73, Issue 6
****************************************