]> gitweb.factorcode.org Git - factor.git/blob - extra/rosetta-code/fizzbuzz/fizzbuzz.factor
0663a5b6d25463fa66c00b4f0e2451288c1c8b4a
[factor.git] / extra / rosetta-code / fizzbuzz / fizzbuzz.factor
1 ! Copyright (c) 2012 Anonymous
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io kernel math math.functions math.parser math.ranges
4 sequences ;
5 IN: rosetta-code.fizzbuzz
6
7 : fizz ( n -- str ) 3 divisor? "Fizz" "" ? ;
8
9 : buzz ( n -- str ) 5 divisor? "Buzz" "" ? ;
10
11 : fizzbuzz ( n -- str )
12     dup [ fizz ] [ buzz ] bi append [ number>string ] [ nip ] if-empty ;
13
14 : fizzbuzz-main ( -- )
15     100 [1..b] [ fizzbuzz print ] each ;
16
17 MAIN: fizzbuzz-main