Jump to content

FizzBuzz: Difference between revisions

714 bytes added ,  10 months ago
m (I do not think this is so unimportant that it should be in parentheses.)
Line 3,949:
 
MAIN: FizzBuzzQuxx-100
</syntaxhighlight>
 
Another approach is leverage Factor's [https://docs.factorcode.org/content/article-predicates.html predicate] and [https://docs.factorcode.org/content/article-intersections.html intersection] classes.
<syntaxhighlight lang="factor">
USING: io kernel math math.functions math.parser sequences ;
IN: rosetta-code.fizz-buzz
 
PREDICATE: fizz < integer 3 divisor? ;
PREDICATE: buzz < integer 5 divisor? ;
INTERSECTION: fizzbuzz fizz buzz ;
 
GENERIC: fizzbuzz. ( x -- )
 
M: fizz fizzbuzz.
drop "Fizz" print ;
 
M: buzz fizzbuzz.
drop "Buzz" print ;
 
M: fizzbuzz fizzbuzz.
drop "Fizz Buzz" print ;
 
M: integer fizzbuzz.
number>string print ;
 
MAIN: [ 20 <iota> [ fizzbuzz. ] each ]
</syntaxhighlight>
 
6

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.