Re: Best recursion choice for penultimax

2002-11-25 Thread Dean Herington
Mark P Jones wrote: Moreover, in attempting to optimize the code, you might instead break it and introduce some bugs that will eventually come back and bite. Indeed! If we take Mark Phillips's original version of penultimax as our specification, all four alternate versions are incorrect:

Re: Best recursion choice for penultimax

2002-11-25 Thread Richard Braakman
On Sun, Nov 24, 2002 at 10:06:42PM -0800, Mark P Jones wrote: To your three implementations, let me add another two. If you are looking for the smallest possible definition, consider the following: import List penultimax1 :: Ord a = [a] - a penultimax1 = head . tail . sortBy

RE: Best recursion choice for penultimax

2002-11-25 Thread Simon Marlow
Some quick tests with Hugs +s on a example list that I constructed with 576 elements give food for thought: reductions cells my one liner 403511483 tournament705312288 your penultimax 1671520180 your

RE: Best recursion choice for penultimax

2002-11-25 Thread Dr Mark H Phillips
Thanks for your alternative solutions. (I also take Mark Jones' point that there was an error with some of my initial solutions.) On Mon, 2002-11-25 at 16:36, Mark P Jones wrote: To your three implementations, let me add another two. If you are looking for the smallest possible definition,

Re: Best recursion choice for penultimax

2002-11-25 Thread Dr Mark H Phillips
On Tue, 2002-11-26 at 02:38, Richard Braakman wrote: penultimax1' :: Ord a = [a] - a penultimax1' = head . tail . sortBy (flip compare) . nub What does nub stand for? (This is the first I've heard of it.) From the definition in List.hs it seems to remove repeats, keeping only the first. Is

RE: Best recursion choice for penultimax

2002-11-25 Thread David Bergman
Subject: RE: Best recursion choice for penultimax Hi Mark, | I have just implemented the function penultimax which takes a list | of positive integers and produces the penultimate maximum, that is, | the next biggest integer in the list after the maximum. Eg: | | penultimax [15,7,3,11,5] = 11

Re: Best recursion choice for penultimax

2002-11-25 Thread John Hughes
What does nub stand for? (This is the first I've heard of it.) From the definition in List.hs it seems to remove repeats, keeping only the first. Yes, that's what it does. It doesn't stand for anything, it's a word: nub: small knob or lump, esp. of coal; small residue, stub; point or gist

RE: Best recursion choice for penultimax

2002-11-24 Thread Mark P Jones
Hi Mark, | I have just implemented the function penultimax which takes a list | of positive integers and produces the penultimate maximum, that is, | the next biggest integer in the list after the maximum. Eg: | | penultimax [15,7,3,11,5] = 11 To your three implementations, let me add another