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

Alejandro Serrano Mena trupill at gmail.com
Tue Sep 25 10:02:47 CEST 2012


It also comes to my mind that you can use something similar to regular
expressions and parsing, seeing your list as a word made of Int elements. I
think you can achieve it using Parsec or attoparsec.
One you define your basic combinators for 'odd', you can see your sublist
as the minimal part of the list matching
(even* odd)(even* odd)(even* odd)(even* odd)

2012/9/25 Ivan Lazar Miljenovic <ivan.miljenovic at gmail.com>

> On 25 September 2012 16:51, Magicloud Magiclouds
> <magicloud.magiclouds at gmail.com> wrote:
> > Hi,
> >   For example, I have an array [0..]. Now I want to take a sub list
> > that starts from index 0, and only contain 4 odds, and is minimum
> > result. The answer should be [0, 1, 2, 3, 4, 5, 6, 7].
>
> If you have listTest :: [a] -> Bool, then head . dropWhile (not .
> listTest) . inits ?
>
> >   How to do that? Combining lazy computing, I cannot figure out an
> > efficient algorithm.
> > --
> > 竹密岂妨流水过
> > 山高哪阻野云飞
> >
> > And for G+, please use magiclouds#gmail.com.
> >
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
> --
> Ivan Lazar Miljenovic
> Ivan.Miljenovic at gmail.com
> http://IvanMiljenovic.wordpress.com
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120925/a485f79f/attachment.htm>


More information about the Haskell-Cafe mailing list