Paste: FizzBuzz Example Comments

Author: Aaron Schaefer
Mode: factor
Date: Sun, 27 Jun 2010 13:30:39
Plain Text |
: fizz ( n -- str )
    3 divisor? "Fizz" "" ? ;

: buzz ( n -- str )
    5 divisor? "Buzz" "" ? ;

: fizzbuzz ( n -- str )
    dup [ fizz ] [ buzz ] bi append
    [ number>string ] [ nip ] if-empty ;

100 [1,b] [ fizzbuzz print ] each

Annotation: Less-Efficient FizzBuzz, But More Clear?

Author: Aaron Schaefer
Mode: factor
Date: Sun, 27 Jun 2010 15:26:08
Plain Text |
: fizzbuzz ( n -- str )
    {
        { [ dup 15 divisor? ] [ drop "FizzBuzz" ] }
        { [ dup 3 divisor? ] [ drop "Fizz" ] }
        { [ dup 5 divisor? ] [ drop "Buzz" ] }
        [ number>string ]
    } cond ;

100 [1,b] [ fizzbuzz print ] each

New Annotation

Summary:
Author:
Mode:
Body: