The EnterpriseQualityCoding version of FizzBuzz[0] is the ultimate (hilarious) version of this. Though, there is still some room for development of node, js, etc versions.
The Node version could be pretty great anyway. Huge list of modules required, multiple implementations of the same basic thing in use, separate modules for "fizz" and "buzz". And MongoDB used for something, for no good reason.
Many years ago I stumbled on a programming golf contest on the old Something Awful forum. The challenge was to convert a byte string to a hex dump. I wrote it as a distributed JNI system with CORBA based RPC. The boilerplate stuff alone was like 500 lines. This is what I did for fun in high school. I wasted my youth.
I shudder to agree. Doing a code review from someone who wrote an entire program in Java formatted Python was one of the low points of my career.
Trees upon trees of nearly empty directories, one sparse class per file (with the requisite getters and setters), factories to make factories... the horror.
I agree that string concatenation is the optimal solution and always take the chance to bring out a properly generic solution.
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 fizzbuzz
A girl on irc once asked if there is a way to solve FizzBuzz with just one comparison.
Yours is indeed one and it is pretty clever :)
Here is another one https://gist.github.com/giuseppeg/5939177
Second expression in the for loop and ||, both behave as conditionals, i.e. are equivalent to an if statement and the generated instruction will be a branch.
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.
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!
You're going to be so in for a surprise when the RNG used on the machine you're showing off your skills on has a different underlying implementation than the one that you suspect!
I worked for a while for an IT services company. For our entry level tech support position, I put together a quick interview document that we emailed applicants, asking them 4 questions. They had to help someone fix their printer via email, fix their email client, write a powershell script to copy files from one directory to another, and solve FizzBuzz.
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.
In fairness, someone with 20+ years of IT experience could very legitimately not have needed to do any significant amount programming. Maybe they built servers all day.
In general, I would agree with you. In that particular case (which I remember because the person with 20+ years of experience was recommended by a client), that person claimed they had written their own CRM system.
(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.)
Yeah, we only gave that candidate the document because we were had just come up with it, we figured he would completely ace it. When he came back with really bad answers for all of the questions (including, "I've never heard of Powershell and I'm not sure how I would use it to do this" in 2012 with claiming the last 10 years as a Windows admin), my boss called me into his office and we just stared at the answers in shock.
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.
I used FizzBuzz when interviewing candidates at Facebook.
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.
I like the fact that the information theory adds up. To specify 30 bits he used a 26 bit number and then specified one of 24 permutaions, and this is just right because
And this suggests a path for lowering the magic number. We can lower the number of bits needed by noting that the required outputs for 8 through 14 (mod 15) are the same as the outputs for 1 through 7 (mod 15), only reversed.
Great article thanks. I recently launched the elixirgolf.com web site and there were some really interesting FizzBuzz solutions. Mine used Fermat's little theorem
59 comments
[ 4.9 ms ] story [ 127 ms ] thread[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.
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) { })
'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!
A collection of terrible fizzbuzz solutions.
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.
26 + log(24) = 26 + 4.58... > 30
I think I will use it.
http://elixirgolf.com/articles/elixir-fizzbuzz-golf/