[Haskell-cafe] Rewrite this imperative in FP way
Morel Pisum
morel.pisum at googlemail.com
Sun Feb 5 16:42:48 CET 2012
"+= a[i]" is the same as "+=1", isn't it?
(i accidentally didn't reply to the list on my first try. sorry.)
Am 05.02.2012 16:36, schrieb Haisheng Wu:
> Sorry there is a mistake in the problem description.
> Here it is in Python:
>
> a = [1,1,1,1] b = [0,1,2,3] c = [0,2] d = [0,0,0,0]
> for i in b:
> for j in c:
> if (i+j)<3:
> d[i+j] += a[i]
>
>
> -Haisheng
>
>
> On Sun, Feb 5, 2012 at 2:28 PM, Haisheng Wu<freizl at gmail.com> wrote:
>
>> a = [1,1,1,1]
>> b = [0,1,2,3]
>> d = [0,0,0,0]
>>
>> for i in b:
>> for j in c:
>> if (i+j)<3:
>> d[i+j] += a[i]
>>
>> My just work implementation in Haskell
>> http://hpaste.org/57452
>>
>> Another people implementation in Haskell with Monad and it turns out
>> complex and very imperatively.
>> http://hpaste.org/57358
>>
>> Do you have any cool solution in FP way?
>>
>> Thanks.
>> -Simon
>>
>
>
> _______________________________________________
> 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