Created
August 9, 2012 14:56
-
-
Save kmizumar/3304919 to your computer and use it in GitHub Desktop.
FizzBuzz
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
#!/usr/bin/env gosh | |
(use gauche.generator) | |
(use slib) | |
(require 'format) | |
(define (main args) | |
(let ((mod3 (circular-generator #f #f #t)) | |
(mod5 (circular-generator #f #f #f #f #t)) | |
(nums (giota 100 1))) | |
(do-generator [out (gmap | |
(^[f b n] | |
(format #f "~@[Fizz~]~@[Buzz~]~@[~a~]" | |
f b (if (or f b) #f n))) | |
mod3 mod5 nums)] | |
(print out)))) | |
;; object-apply version by Shiro Kawai | |
(define-method object-apply ((a <string>) (b <string>)) (string-append a b)) | |
(define-method object-apply ((a <string>) (b <number>)) a) | |
(define-method object-apply ((a <boolean>) b) b) | |
(define (main args) | |
(for-each (^[f b n]($ print $ f $ b n)) | |
'#1=(#f #f "Fizz" . #1#) | |
'#2=(#f #f #f #f "Buzz" . #2#) | |
(iota 100 1))) | |
;; gauche.lazy version by Shiro Kawai | |
(use gauche.lazy) | |
(define (++ a b) (if (string? a) (if (number? b) a (string-append a b)) b)) | |
(define (main args) | |
($ for-each print | |
$ map (pa$ fold ++) (iota 100 1) | |
$ lmap list '#1=(_ _ "Fizz" . #1#) '#2=(_ _ _ _ "Buzz" . #2#))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment