List comprehension in Haskell, Python and Ruby

前端 未结 5 949
天命终不由人
天命终不由人 2021-01-01 21:26

I have started looking at the project Euler site as a way to learn Haskell, and improve my Python and Ruby. I think the Haskell and Python versions are ok, but I\'m sure the

5条回答
  •  囚心锁ツ
    2021-01-01 21:45

    Not a list comprehension, I know, but to solve that I would use:

    3*((999/3)**2+999/3)/2+5*((999/5)**2+999/5)/2-15*((999/15)**2+999/15)/2
    

    Faster then any list comprehension one might come up with, and works in any language ;)

    Only posting to show another way of looking at the same problem using http://en.wikipedia.org/wiki/Summation.

提交回复
热议问题