Last active
May 3, 2021 17:17
-
-
Save wulab/f665ec2c7556d2ca183aa5eea41c8292 to your computer and use it in GitHub Desktop.
Write a program that prints the numbers from 1 to 100. But for multiples of three print Fizz instead of the number and for the multiples of five print Buzz. For numbers which are multiples of both three and five print FizzBuzz.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (fizzbuzz) | |
(define (fizzbuzz-iter counter max-count) | |
(print counter) | |
(if (>= counter max-count) | |
'done | |
(fizzbuzz-iter (+ counter 1) max-count))) | |
(define (print n) | |
(cond ((and (divisible n 3) (divisible n 5)) (write-line 'fizzbuzz)) | |
((divisible n 3) (write-line 'fizz)) | |
((divisible n 5) (write-line 'buzz)) | |
(else (write-line n)))) | |
(define (divisible a b) | |
(= (modulo a b) 0)) | |
(fizzbuzz-iter 1 100)) | |
(fizzbuzz) |
Author
wulab
commented
May 3, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment