LoginSignup
2
0

More than 5 years have passed since last update.

SchemeでFizzBuzz

Posted at

関数型プログラミングができるようになりたい
今まで書いてたJavaとかPythonとかと勝手が違うから書いてて脳みそがちぎれそうになる
参照できるサイトがあまり多くないので自分で考えることが重要になりそうである

fizz-buzz.scm
(define (main args)
    (fizz-buzz 1)
    0)

(define (fizz-buzz x)
    (if (<= x 100)
        (cond 
          ((= (modulo x 15) 0) (print "FizzBuzz") (fizz-buzz (+ x 1) ))
          ((= (modulo x 3) 0) (print "Fizz") (fizz-buzz (+ x 1) ))
          ((= (modulo x 5) 0) (print "Buzz") (fizz-buzz (+ x 1) ))
          ((= x 100) (print "Finish"))
          (else (print x) (fizz-buzz (+ x 1) )))))

無駄ばかりあるような気しかしない
標準入力はどう受け取ったらいいのだろう…

2
0
5

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
2
0