FizzBuzz: Difference between revisions
Content added Content deleted
Ididjdjjdjd (talk | contribs) m (I do not think this is so unimportant that it should be in parentheses.) |
|||
Line 3,949: | Line 3,949: | ||
MAIN: FizzBuzzQuxx-100 |
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> |
</syntaxhighlight> |
||