[Haskell-cafe] How to take a minimum sub list that only contain certain number of elements of certain type?

Gwern Branwen gwern0 at gmail.com
Wed Sep 26 02:28:19 CEST 2012


On Tue, Sep 25, 2012 at 8:17 PM, Richard O'Keefe <ok at cs.otago.ac.nz> wrote:
> Wrong.  The original poster gave an explicit example
> in which even elements were *retained* in the output,
> they just weren't *counted*.

You are at least the fourth person to email me now to point this out.
I'm glad I could make four people's day better with the joy of
correction...

But I never said it was a full solution - please note that I did
include the output of the function!

One could consider it a partial solution, however: that gives you the
_nth_ odd, so if you want a list of numbers up to the _nth_ odd, that
gives you a stop condition - 'takeWhile =/ nth+1' etc. A 2N traverse
(which laziness might fuse to just 1 traverse, dunno).

-- 
gwern
http://www.gwern.net



More information about the Haskell-Cafe mailing list