[Haskell-cafe] Mapping over multiple values of a list at once?

Raynor Vliegendhart shinnonoir at gmail.com
Thu Aug 27 06:41:51 EDT 2009


Just wondering, what should be the expected output be of something
like mavg 4 [1..3]? [3%2] or []?
Patai's and Eugene's solutions assume the former.

On Thu, Aug 27, 2009 at 10:19 AM, <haskell at kudling.de> wrote:
> Hi,
>
> Imagine you have a list with n-values. You are asked to iterate over the list and calculate the average value of each 3 neighbouring values.
>
> For example, starting from
>
> [4,3,2,6,7]
>
> you need to find the averages of
>
> 4,3,2 and 3,2,6 and 2,6,7
>
> resulting in
>
> [3,4,5]
>
> What is the most elegant way to do that?
> The naive ansatz to use "(!!") excessively sounds pretty inefficient.
>
> Bye,
> Lenny
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list