ループ1

(for-each print
  (map
    (lambda (_) "Hello World!")
    (iota 5)))

FizzBuzz

(print
  (string-join
    (map
      (lambda (x)
        (cond
          ((zero? (modulo x 15)) "FizzBuzz")
          ((zero? (modulo x  5)) "Buzz")
          ((zero? (modulo x  3)) "Fizz")
          (else (format #f "~d" x))))
      (iota 100 1))))

うるう年判定

(define (leap-year? n)
  (cond
    ((zero? (modulo n 400)) #t)
    ((zero? (modulo n 100)) #f)
    ((zero? (modulo n   4)) #t)
    (else                   #f)))
(define (foo n)
  (if (leap-year? n)
    (print (format #f "~d年はうるう年です。" n))
    (print (format #f "~d年はうるう年ではありません。" n))))
(foo 1992)
(foo 2000)
(foo 2001)

累乗1

(define pow
  (lambda (a n)
    (if
      (zero? n) 1
      (* a (pow a (- n 1))))))
(print (pow 2 10))

フィボナッチ数列1

(define fib
  (lambda (n)
    (if
      (< n 2) 1
      (+ (fib (- n 1)) (fib (- n 2))))))
(for-each print
  (map
    (lambda (n) (fib n))
    (iota 10)))

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS