プロジェクト

全般

Wiki

プロフィール

操作

Problem 1 » 履歴 » リビジョン 3

« 前 | リビジョン 3/4 (差分) | 次 »
Noppi, 2023/12/27 11:53


ホーム - Project Euler

Problem 1

Multiples of 3 or 5

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.

3と5の倍数

10未満の自然数のうち, 3 もしくは 5 の倍数になっているものは 3, 5, 6, 9 の4つがあり, これらの合計は 23 になる.
同じようにして, 1000 未満の 3 か 5 の倍数になっている数字の合計を求めよ.

#!r6rs
#!chezscheme

(import (chezscheme))

(define answer-1
  (fold-left
    (lambda (sum current)
      (if (or
            (zero? (mod current 3))
            (zero? (mod current 5)))
        (+ sum current)
        sum))
    0
    (iota 1000)))

(printf "1: ~D~%" answer-1)

Noppi2023/12/27に更新 · 3件の履歴