|
| 1 | +# Ideas |
| 2 | + |
| 3 | +This document list various ideas on tackling the implementation of FizzBuzz. |
| 4 | +Since some of these ideas are orthogonal, we can rely on a multiplication |
| 5 | +effect to increase the number of options |
| 6 | + |
| 7 | +## Divisibilty |
| 8 | +The essence of the FizzBuzz game is divisibility. There are various different |
| 9 | +ways to determine, what is effectively, the equivalence class of a certain |
| 10 | +number with respect to the modulus. |
| 11 | + |
| 12 | +### `mod` |
| 13 | +The standard implementation used the `mod` function that determines the modulus |
| 14 | +of a number. |
| 15 | + |
| 16 | +### Representation with different Radix |
| 17 | +When the last digit of a representation of a number in a different radix is |
| 18 | +zero that number is divible by the radix. |
| 19 | + |
| 20 | +### Unrolling the loop |
| 21 | +Knowing the remainder after division of 15 is all you need to determine the |
| 22 | +action you need to take. You could use the following table |
| 23 | + |
| 24 | +| Remainder | Result | |
| 25 | +|-----------|------------| |
| 26 | +| 0 | "FizzBuzz" | |
| 27 | +| 1 | "n" | |
| 28 | +| 2 | "n" | |
| 29 | +| 3 | "Fizz" | |
| 30 | +| 4 | "n" | |
| 31 | +| 5 | "Buzz" | |
| 32 | +| 6 | "Fizz" | |
| 33 | +| 7 | "n" | |
| 34 | +| 8 | "n" | |
| 35 | +| 9 | "Fizz" | |
| 36 | +| 10 | "Buzz" | |
| 37 | +| 11 | "n" | |
| 38 | +| 12 | "Fizz" | |
| 39 | +| 13 | "n" | |
| 40 | +| 14 | "n" | |
| 41 | + |
| 42 | +Where `"n"` represents the String representation of the subject under test. |
| 43 | + |
| 44 | +This technique can be applied to various ways of looking up the result |
| 45 | +depending on the remainder. E.g. using a switch expression, using a map for the |
| 46 | +lookup. |
| 47 | + |
| 48 | +### Casting out 9 |
| 49 | +There is a "well-know" calculation aid called casting out nines. This allows a |
| 50 | +(human) computer to check if a result is plausible. In effect it can determine |
| 51 | +if a number is divisible by nine. |
| 52 | + |
| 53 | +The crux for decimal number (base 10) is that 10 = 9 + 1. There is a similar |
| 54 | +test for divisibility of 11, which hinges on the fact that 10 = 11 - 1. |
| 55 | + |
| 56 | +By inspecting the binary representation one can devise a similar test because |
| 57 | +2 = 3 - 1 and 2^2 = 4 = 5 - 1. |
| 58 | + |
| 59 | +Details will be in the presentation |
| 60 | + |
| 61 | +## Technology |
| 62 | +There are various other means then flat out implement the algorithm. Below are |
| 63 | +a few suggestions |
| 64 | + |
| 65 | +### SQL |
| 66 | +One could query an prepared structured database. |
| 67 | + |
| 68 | +### Knowledge System |
| 69 | +One could query an knowledge system, like Prolog. |
| 70 | + |
| 71 | +### Machine learning |
| 72 | +One could train an machine to pick out the FizzBuzzyness of numbers. |
0 commit comments