Files currently attached to this page:
fb.Makefilefb.Makefile: This one is simple: It breaks the numbers down into 4 subsets: Regular, fuzz, buzz, and fuzzbuzz. For each one, it defines a rule that prints the proper thing. The default rule depends on all the numbers from 1 to 100, so it invokes all the number rules in order.
fb.m4fb.m4: This one is straightforward, but in an ugly language, and must use recursion instead of iteration.
fb.bashfb.bash: This one is a bit silly, using bash, seq, dc, and awk. 100 lines are printed by the 'for' loop, which consist of the number first in binary and then in decimal. The awk script uses a regular expression to match multiples-of-three written in binary, and another regular expression (a much simpler one) to match multiples-of-five written in decimal.
fb.ccfb.cc: I'm proudest of this one. It uses C++ templates to produce a heavily nested class X<100>. Each X<int> class but X<0> contains a Y<> class. Y<> is specialized to print the correct thing for each of the 4 cases. Each X<int> but X<0> also contains an X<i-1>, and so on recursively. By the C++ rules concerning order of construction, the output is printed in the desired order. To make things even more efficient, when a number is to be printed, it's converted to ASCII at compile time.
fb.pyfb.py: I couldn't resist finding a perverse way to write this in Python, since the clear ways can be so very clear. Unfortunately, compose() is way too clear, and anyone familiar with how to use the "ternary-like" operator in Python will catch on to the fuzz and buzz functions right away.
fb2.pyfb2.py: Another Python program. Using 'lambda' makes everything clearer, doesn't it!
fb.cfb.c: I love using the C preprocessor, but I've never done this kind of self-inclusion before. Won't run if sizeof(char*) != sizeof(int).
Entry first conceived on 27 February 2007, 22:56 UTC, last modified on 15 January 2012, 3:46 UTC
Website Copyright © 2004-2021 Jeff Epler