Project Euler: Problem 1
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
http://projecteuler.net/index.php?section=problems&id=1
1000 以下の自然数に含まれる 3 および 5 の倍数を集めて、その合計を求めよとのこと。
Scheme というか Gauche で書いてみた。流石に FizzBuzz くらいはどうということはない。
#!/usr/bin/env gosh (define (main args) (let loop ((i 1) (r 0)) ; 合計 (最初は 0) (if (< i 1000) (if (or (= (modulo i 3) 0) ; 3 で割り切れるか (= (modulo i 5) 0)) ; 5 で割り切れるか (loop (+ i 1) (+ r i)) ; 割り切れたら合計に足しておく (loop (+ i 1) r)) (print r))) 0)