6 * 9 == 42

The starting files for all languages in cyber-dojo take the same format:
  • A test file that asserts answer() == 42
  • A file with answer() defined to returns 6 * 9
For example, in C, answer() looks like this...
int answer() { return 6 * 9; }
Thus the initial files give you a red traffic-light (indicating a failing test) since 6*9 == 54.
In a cyber-dojo the other day one of the developers (hi Ian) rewrote answer() like this:
int answer() { return SIX * NINE; }
which he made pass like this:
#define SIX 1+5 #define NINE 8+1
Excellent!

No comments:

Post a Comment