5
1
I have a source file here:
#include <FizzBuzz.h>
fizzbuzz
And I want to make "fizzbuzz
" turn into a FizzBuzz program solely through the preprocessor.
Your task is to write a FizzBuzz.h
that uses only preprocessor directives (things like include, define, etc.) to create a working FizzBuzz program. Specifically, I want to see the use of macros, which will be required to make this work (at minimum, defining fizzbuzz
to be some code).
However, to make sure people try and take full advantage of the power of macros, your score will be defined as the sum of the cubes of the length of the definition portion (the part after #define <symbol>
) of each macro.
So, for example, the following file:
#define A 123
#define B A+A
#define C B*2+A
would have a total score of 179 (3^3 + 3^3 + 5^3). As a rule, I want multiple shorter lines instead of one long line.
Do you have any reason to believe that the answers won't all define one of the tokens to an empty string and the other to a one-line program? (Or in other words, what distinguishes this from a boring "golf fizzbuzz"?) – Peter Taylor – 2013-08-09T22:52:01.717
I thought of that myself. I'll probably reupload it with new restrictions. – Joe Z. – 2013-08-09T22:52:45.563
Added a new scoring algorithm that should favour multiple short lines. – Joe Z. – 2013-08-10T17:54:33.047
Can you give an exact specification of FizzBuzz? I guess we all know the idea, but do you want a function that gets a single number, or a loop (until when?) or what? – ugoren – 2013-08-10T20:18:29.107
The same specification as here: http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html
– Joe Z. – 2013-08-10T21:47:22.510You need an algorithm to favor lines of code, too? How about
The sum of the cubes of each definition multiplied by the number of lines in fizzbuzz.h, excluding empty lines and empty definitions.
? Your example would become(3^3 + 3^3 + 5^3) * 3
for a total score of 537. – Braden Best – 2014-02-15T22:14:18.160