One of my former co-workers had 2 job interviews yesterday. One of the test questions was the "write some php code that, for a sequence of numbers from 1 to 100, if it's divisible by 3, print "BING!", if it's divisible by 5, print "BANG", but if it's divisible by both, print 'BOOM!"
These people can't come up with something more original?
Anyway, I woke up this morning, and said to myself - "How would *I* answer that question?" Obviously, in the interest of runtime efficiency, I don't want to use the modulus operator, or a for loop, or a switch statement, or a bunch of ifs
** the problem:
** for the numbers 1 through 100
** if the number is divisible by 3 but not 5, print BING! + a newline
** if the number is divisible by 5 but not 3, print BANG! + a newline
** if the number is divisible by both 3 and 5, print BOOM! + a newline
** my solution
** f*ck the foor loops and using the modulus operator - they're slow.
** the problem is easily solved by introspection.
** the natural period of the function is 15 (it repeats every 15 digits)
** the "interesting numbers" that trigger events: 3, 5, 6, 9, 10, 12, 15
$tro = "$f$f$f$f$f$f";
** but that wouldn't have been as readable
** (for some values of "readable"