Implement FizzBuzz in Python, with the fewest possible tokens.
Write a program that prints the decimal numbers from 1 to 100 inclusive. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”. Programs must be written in some version of Python.
For more details, see 1, 2, Fizz, 4, Buzz
Your score will be equal to the number of nodes in the abstract syntax tree of your code, as reported by this program for Python 3, or this program for Python 2. To run the programs, provide the filename of your code as command line argument to the program. For instance:
python simple_counter.py fizzbuzz.py
These programs are based off of Python's ast module. If you have any difficulty, let me know.
To prevent trivial solutions, such as executing a long string with the actual program, or hardcoding the output, there are some additional restrictions:
No token in your code may be longer than 15 characters. The above programs will check this requirement for you. Note that for ease of implementation, the above programs count comments as tokens.
Code execution/evaluation is banned.
If you have questions as to whether something is allowed, ask me.
The following rules are typically enough to calculate the score of your program:
Block statements are 1 points:
for ... in ...,
Standalone statements are 1 point:
Variables are 2 points
Single-token literals are 1 point:
Functions are 3 points (2 for using a variable, 1 extra):
Operators are 2 points:
=is 1 point
Augmented assignment is 2 points:
Parentheses, indentation, etc. are 0 points.
A line containing an expression, as opposed to an assignment or an expression, is + 1 point.
Having code at all is 1 point.
The lowest score wins. Good luck!