Oh, Go Ahead, Overthink FizzBuzz (2008)
chalain.livejournal.com
chalain.livejournal.com
[0] https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...
Well, how else are you going to store the results before you print them to screen?
Trees upon trees of nearly empty directories, one sparse class per file (with the requisite getters and setters), factories to make factories... the horror.
http://www.adamtornhill.com/articles/fizzbuzz.htm
Fizzbuzz implemented as C++ compiler errors.
No recruiters would accept it.
We honestly didn't care if they blatantly plagiarized the answers (especially on the last two), because the point was the right answer as much to see if they knew enough vocabulary to know how to Google the question.
Out of 30 responses, including recent college graduates with good GPAs, people claiming 20+ years of IT experience, owning their own IT consulting firm, etc, not one of them got all four right. Some even said, "I don't know how to solve this" on FizzBuzz.
The person who actually got them all correct? My wife, an ESL teacher who I gave the questions as a control, and told her to not spend more than 15 minutes on them.
Anyone who overthinks FizzBuzz is an automatic hire in my book. (yes, I know about http://www.joelonsoftware.com/items/2005/01/27.html )
1) Know how to use the internet 2) Know how to problem solve by obtaining information from external sources.
(Way, way off topic, but are you the ceejayoz who used to be a Homeworld webmaster? I spent a month or so of my life on Homeworld in late 2000, fun times.)
And yes, I am. :-)
Awesome. I was a bigger Total Annihilation fan/community member than I was for Homeworld, but still, it tickles me when I see names I recognize from gaming being 'real people' somewhere on the internet years later.
Call it over-thinking, but I preferred to think of it as "jamming"... like calling out a Jazz or Rock standard that everyone knows, as a warm-up... and giving the candidate an opportunity to explore and stretch.
Blog post at http://www.embracingthecloud.com/2012/10/22/EvolutionOfASale...
If this were real code two things would happen;
1. Someone would refactor the `fizzbuzz_word(n)` method and this would all break
2. Your PM would ask for a new feature "multiples of 7 should be said 'Wuzz'"
So that 2 minute test becomes a 10 minute venture into real world problem solving.
let fbg s l u=unlines[case concat[w|(w,c)<-s,mod i c==0]of[]->show i;m->m|i<-[l..u]]
let fizzbuzz = fbg [("Fizz",3),("Buzz",5)] 1 100
main = putStrLn fizzbuzzA collection of terrible fizzbuzz solutions.
26 + log(24) = 26 + 4.58... > 30
words[c] || i
I focused on the bitwise thing and I overlooked that part
Is first expression true? If it isn't evaluate the second expression.
At least it would in C. Of course I'm ignoring the fact that JS is interpreted as will cause a lot of additional bloat, but were not counting that.
In js the for could be replaced with an array of 100 elems and a forEach:
Array.apply(null, { length: 100 }).forEach(function (_, i) { })
#include <stdio.h>
#include <stdlib.h>
int i(const int i) { printf("%d\n", i); return i; }
int f(const int i) { printf("Fizz\n"); return i; }
int b(const int i) { printf("Buzz\n"); return i; }
int fb(const int i) { printf("FizzBuzz\n"); return i; }
int (* PC[15])(int i) = { i,i,f,i,b,f,i,i,f,b,i,f,i,i,fb }; // Printer Cycle
int go(const int arg) {
return PC[(arg - 1) % 15](arg) + 1;
}
int stop(const int arg) {
PC[(arg - 1) % 15](arg);
exit(0);
}
int (* LC[2]) (int index) = { go, stop }; // Logic Cycle
void recurse(const int i, const int kill_num) {
recurse(LC[!(i % kill_num)](i), kill_num);
}
int main(const int argc, const char *argv[]) {
recurse(1, atoi(argv[1]));
}'0' and no number input also crash it.
(Obviously it transforms it to a loop, so it sorta breaks the rules at compile time)
> int (* PC[15])(int i) = { i,i,f,i,b,f,i,i,f,b,i,f,i,i,fb }; // Printer Cycle
> int (* LC[2]) (int index) = { go, stop }; // Logic Cycle
I can see they behave as functions, but I don't understand what exactly are they or the logic that makes then work.
They are both an array of pointers to functions.
Go(int i) is a function that finds the correct "printer" for a number, i, within the cycle of 15. `Go` then calls the printer function with the argument and prints the corresponding line.
Stop(int i) has similar side-effect but exits immediately after.
Since all of the printers return the value of "i", you can recursively call them in cycle-sequence through `go` until the return value lines up with the "kill number" and causes `stop` to be called instead (this works as `i % n > 0` for all numbers below n and you can force this to be zero, and thus index the first element of the array, by negating it).
Sorry for the scatterbrained explanation, the code wasn't designed to be particularly comprehensible!
perl -E 'map { say } map { { 3 => "Fizz", 5 => "Buzz", 15 => "FizzBuzz" }->{ sub { my $val = shift; (grep { $val % $_ == 0 } (3, 5, 15))[-1] }->($_) } || $_ } (1..100)'
Or a little more readable: map { say }
map {
{ 3 => "Fizz", 5 => "Buzz", 15 => "FizzBuzz" }->{
sub {
my $val = shift;
(grep { $val % $_ == 0 } (3, 5, 15))[-1]
}->($_)
} || $_
} (1..100)I think I will use it.