5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Project Eulerをhaskellで練習していく日記: Problem 1

Posted at

問題1

https://projecteuler.net/problem=1
10未満の3か5の倍数は3,5,6,9であり、その和は23となる。
1000未満で同様の和を求めよ。

回答

prob1 n =  foldl (+) 0 [x | x<-[1..n-1], x `mod`3 == 0 || x `mod` 5 == 0]

main = do 
     print $ prob1 1000

感想

haskellの練習として、Project Eulerの問題を解いて行くことにしました。
haskellは書籍「すごいHaskellたのしく学ぼう」で勉強中です。
いきなり剰余の演算子などがするっと出てこなかったので、googleで調べたり。
あんまりエレガントなにおいがしてこないので、まだまだ練習が必要と感じました。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?