Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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


Today's Topics:

   1.  shortening code (rizwan hudda)
   2. Re:  shortening code (Felipe Lessa)
   3. Re:  shortening code (Michael Mossey)
   4. Re:  Functional Programming in Finance (Ben Lippmeier)
   5. Re:  shortening code (Lyndon Maydwell)


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

Message: 1
Date: Wed, 30 Jun 2010 05:05:11 +0530
From: rizwan hudda <rizwanhu...@gmail.com>
Subject: [Haskell-beginners] shortening code
To: beginners@haskell.org
Message-ID:
        <aanlktik2ih2hfjmtqfaqwpakialtketkz2cxklv5z...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I have recently started learning haskell, and was trying to write a code for
this problem http://www.spoj.pl/problems/KAMIL in haskell. The aim is to
write a shortest possible code for the given task. I have previously solved
this in c,c++,perl,python.My best was 57 characters using perl. So here's my
code in HASKELL:

main = interact $ unlines. map (show.foldl (\a x-> if null $ filter (==x)
"TDLF" then a else a+a) 1) .lines

It is 107 characters [ non white space and newline ]. I was interested in
knowing how i could further optimize the size of this code.


Thanks in advance.


-- 
Thanks and regards
Rizwan A Hudda
http://sites.google.com/site/rizwanhudda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100629/2b3af062/attachment-0001.html

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

Message: 2
Date: Tue, 29 Jun 2010 21:50:06 -0300
From: Felipe Lessa <felipe.le...@gmail.com>
Subject: Re: [Haskell-beginners] shortening code
To: rizwan hudda <rizwanhu...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <aanlktikml77rfsmsvm-aqz-kqquo_ovi1xqr1osvw...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

(Sorry, rizwan, first e-mail wasn't sent to the list)

On Tue, Jun 29, 2010 at 8:35 PM, rizwan hudda <rizwanhu...@gmail.com> wrote:
> I have recently started learning haskell, and was trying to write a code for
> this problem http://www.spoj.pl/problems/KAMIL in haskell. The aim is to
> write a shortest possible code for the given task. I have previously solved
> this in c,c++,perl,python.My best was 57 characters using perl. So here's my
> code in HASKELL:
>
> main = interact $ unlines. map (show.foldl (\a x-> if null $ filter (==x)
> "TDLF" then a else a+a) 1) .lines
>
> It is 107 characters [ non white space and newline ]. I was interested in
> knowing how i could further optimize the size of this code.

Well, we have:

 null (filter (== x) cs)  =  x `notElem` cs  =  not (x `elem` cs)

So we get:

 main = interact $ unlines . map (show . foldl (\a x -> if elem x
"TDLF" then a+a else a) 1) . lines

I'm not looking at the problem, but if I understood the line above
correctly, each line should print 2^n where n is the number of
elements TDLF in that line:

 main = interact $ unlines . map (show . (2^) . length . filter
(`elem` "TDLF")) . lines

That's 70 non-whitespace characters.  This one-liner is pretty
readable, probably more than the Perl one ;D.

Cheers,

-- 
Felipe.


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

Message: 3
Date: Tue, 29 Jun 2010 20:25:18 -0700
From: Michael Mossey <m...@alumni.caltech.edu>
Subject: Re: [Haskell-beginners] shortening code
To: rizwan hudda <rizwanhu...@gmail.com>
Cc: beginners@haskell.org
Message-ID: <4c2ab91e.8070...@alumni.caltech.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed



rizwan hudda wrote:
> I have recently started learning haskell, and was trying to write a code 
> for this problem http://www.spoj.pl/problems/KAMIL in haskell. The aim 
> is to write a shortest possible code for the given task. I have 
> previously solved this in c,c++,perl,python.My best was 57 characters 
> using perl. So here's my code in HASKELL:
> 
> main = interact $ unlines. map (show.foldl (\a x-> if null $ filter 
> (==x) "TDLF" then a else a+a) 1) .lines
> 
> It is 107 characters [ non white space and newline ]. I was interested 
> in knowing how i could further optimize the size of this code.

This kind of contest is fun, but I can't help thinking I hope you are 
learning Haskell to appreciate the things that functional programming is 
good at. Real-world Haskell is often more concise than other languages 
because Haskell has mechanisms for eliminating unnecessary and redundant 
code, but Haskell's strength is not winning "shortest program" contests.

Mike


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

Message: 4
Date: Wed, 30 Jun 2010 13:32:31 +1000
From: Ben Lippmeier <b...@ouroborus.net>
Subject: Re: [Haskell-beginners] Functional Programming in Finance
To: Syed Imran <s.im...@carringtonfox.com>
Cc: "beginners@haskell.org" <beginners@haskell.org>
Message-ID: <d92f0059-0fc7-4772-af20-96974eb96...@ouroborus.net>
Content-Type: text/plain; charset="us-ascii"


Hmm. Spamming the haskell-beginners list.

I guess some companies must be desperate...

Ben.



On 28/06/2010, at 11:45 PM, Syed Imran wrote:

> Hi,
>  
> I hope you are well.
>  
> I am a Head Hunter in the  City of London, I have recently joined the 
> Haskell-Cafe forum.
>  
> I am currently looking for someone with a strong computer science or 
> mathematical background to work with some of the leading financial 
> institutions in London and the USA. Functional Programming is seeing a 
> significant amount of investment with a few of our clients, who are using 
> Haskell as well as F# (and some also use OCaml).
>  
> I appreciate you may not be actively looking to work in the investment 
> banking arena at present however I would be keen to touch base with you 
> should you be interest now or in the future.
>  
> Please could you let me know your current situation and also forward me a 
> copy of your CV and contact number so as I can call.
>  
> Look forward to hearing from you.
>  
> Kindest Regards
>  
> Syed Imran
>  
> Consultant
> Carrington Fox UK Ltd.
> 11 Tokenhouse Yard
> London
> EC2R 7AS
> Tel: +44 207 073 2626
> Fax: +44 207 073 2627
> s.im...@carringtonfox.com
>  
> www.carringtonfox.com
>  
> 
> Carrington Fox UK Ltd.
> 11 Tokenhouse Yard
> London
> EC2R 7AS
> Tel: +44 207 073 2626
> Fax: +44 207 073 2627
> 
> 
> www.carringtonfox.com
> 
> Privileged/Confidential Information may be contained in this message. If you 
> are not the addressee indicated in this message (or responsible for delivery 
> of the message to such person), you may not copy or deliver this message to 
> anyone.
> 
> Please advise immediately if you or your employer do not consent to Internet 
> email for messages of this kind. Opinions, conclusions and other information 
> in this message that do not relate to the official business of my firm shall 
> be understood as neither given nor endorsed by it. Carrington Fox reserves 
> the right to share information between companies within our group. Carrington 
> Fox UK Limited. Registered in England: 04373672 Registered Office: 11 
> Tokenhouse Yard, London, EC2R 7AS. VAT Number: 798-4652-61
> 
> Terms and Conditions of Business available on our web-site.
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100629/08042264/attachment-0001.html

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

Message: 5
Date: Wed, 30 Jun 2010 12:20:17 +0800
From: Lyndon Maydwell <maydw...@gmail.com>
Subject: Re: [Haskell-beginners] shortening code
To: Michael Mossey <m...@alumni.caltech.edu>
Cc: beginners@haskell.org
Message-ID:
        <aanlktimiixgjavtvt-oqmcingfzwe3pymngrj_hte...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

I agree. If you're aiming for really terse code, have a look at the
J/K languages. These seem to win most golf-shootout type competitions.
Haskell is more focused on expressiveness and abstraction.

On Wed, Jun 30, 2010 at 11:25 AM, Michael Mossey <m...@alumni.caltech.edu> 
wrote:
>
>
> rizwan hudda wrote:
>>
>> I have recently started learning haskell, and was trying to write a code
>> for this problem http://www.spoj.pl/problems/KAMIL in haskell. The aim is to
>> write a shortest possible code for the given task. I have previously solved
>> this in c,c++,perl,python.My best was 57 characters using perl. So here's my
>> code in HASKELL:
>>
>> main = interact $ unlines. map (show.foldl (\a x-> if null $ filter (==x)
>> "TDLF" then a else a+a) 1) .lines
>>
>> It is 107 characters [ non white space and newline ]. I was interested in
>> knowing how i could further optimize the size of this code.
>
> This kind of contest is fun, but I can't help thinking I hope you are
> learning Haskell to appreciate the things that functional programming is
> good at. Real-world Haskell is often more concise than other languages
> because Haskell has mechanisms for eliminating unnecessary and redundant
> code, but Haskell's strength is not winning "shortest program" contests.
>
> Mike
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>


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

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 24, Issue 41
*****************************************

Reply via email to