Created
January 26, 2018 00:54
-
-
Save winny-/08bd68320e36157cc14a98a400430278 to your computer and use it in GitHub Desktop.
This file contains 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
#lang racket | |
(require srfi/41) | |
(define (fizzbuzz-stream) | |
(let loop ([n 1]) | |
(stream-cons | |
(match* ((modulo n 3) (modulo n 5)) | |
[(0 0) "FizzBuzz"] | |
[(0 _) "Fizz"] | |
[(_ 0) "Buzz"] | |
[(_ _) (number->string n)]) | |
(loop (add1 n))))) | |
(module+ test | |
(require rackunit) | |
(check-equal? (stream->list (stream-take 15 (fizzbuzz-stream))) | |
'("1" "2" "Fizz" "4" "Buzz" "Fizz" "7" "8" "Fizz" "Buzz" "11" "Fizz" "13" "14" "FizzBuzz"))) | |
(module+ main | |
(stream-for-each displayln (stream-take 100 (fizzbuzz-stream)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment