Paste: fizzbuzz

Author: brennanc
Mode: factor
Date: Thu, 13 Nov 2008 23:25:30
Plain Text |
USING: kernel io math math.ranges math.parser sequences ;
IN: fizzbuzz 

: /by? ( x y -- x ? ) dupd mod 0 = ;

: fizzbuzz ( -- ) 
    100 [1,b]
        [ 15 /by? 
            [ "fizzbuzz" print drop ]
            [ 5 /by?
                [ "buzz" print drop ] [ 3 /by?
                    [ "fizz" print drop ] [ number>string print ] if
                ] if
            ] if
        ] each ;

Annotation: fizzbuzz

Author: erg
Mode: factor
Date: Thu, 13 Nov 2008 23:32:39
Plain Text |
clear 100 [1,b] [
    dup number>string write bl
    {
        { [ dup 15 mod 0 = ] [ drop "fizzbuzz" print ] }
        { [ dup 5 mod 0 = ] [ drop "buzz" print ] }
        { [ dup 3 mod 0 = ] [ drop "fizz" print ] }
        [ nl drop ]
    } cond
] each

Annotation: change nesting of quotations

Author: doublec
Mode: factor
Date: Thu, 13 Nov 2008 23:34:08
Plain Text |
: fizzbuzz ( -- ) 
  100 [1,b] [ 
    15 /by? [ 
      "fizzbuzz" print drop 
    ] [ 
      5 /by? [ 
        "buzz" print drop 
      ] [ 
        3 /by? [ 
          "fizz" print drop 
        ] [ 
          number>string print 
        ] if
      ] if
    ] if
  ] each ;

New Annotation

Summary:
Author:
Mode:
Body: