7 ms·
Oh, Go Ahead, Overthink FizzBuzz (2008)
- avmich 11y agoCan optionally include this solution - http://codon.com/programming-with-nothing http://codon.com/programming-with-nothing (at the end).
- MAGZine 11y agoThe 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. [0] https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...
- xirdstl 11y agoI don't know. Java seems like the one true language for the Enterprise version of FizzBuzz.
- ashark 11y agoThe 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.
- sosborn 11y ago> And MongoDB used for something, for no good reason. Well, how else are you going to store the results before you print them to screen?
- munificent 11y ago"fizz", "buzz", and "fizzbuzz" should be separate microservices each with their own failover and redundancy systems.
- mbrock 11y agoMany 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.
- xirdstl 11y agoAgreed, but it needs a designation besides Enterprise. My mind is drawing a blank, though.
- redthrowaway 11y agoYou can write Java in any language.
- falcolas 11y agoI 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.
- xirdstl 11y agoI created a xxxxFactoryFactory in a recent project. Partly for practical reasons and partly for satire.
- dkonofalski 11y agoWow. Just... wow. That is more amazing than most of the code I see on a daily basis.
- izzle49 11y agoI dont know needs more tests :)
- jonesb6 11y agoNo factory factories. 0/10, next application please.
- esaym 11y agoAh you beat me too it. I used to have parts of that and the dailywtf version hanging in my office: http://thedailywtf.com/articles/The-Fizz-Buzz-from-Outer-Space http://thedailywtf.com/articles/The-Fizz-Buzz-from-Outer-Spa...
- EC1 11y agoDoes anyone know what the candidate was actually trying to do here? Is it semi intelligible? I can't figure it out.
- vcarl 11y agoI also love this one. http://www.adamtornhill.com/articles/fizzbuzz.htm http://www.adamtornhill.com/articles/fizzbuzz.htm Fizzbuzz implemented as C++ compiler errors.
- ilurk 11y agoIt doesn't look like it was implemented following TDD. No recruiters would accept it.
- exizt88 11y agoI've tried overthinking FizzBuzz myself, but from the architectural point of view: https://medium.com/@sbichenko/the-wrong-fizzbuzz-81cb8e67ef4a https://medium.com/@sbichenko/the-wrong-fizzbuzz-81cb8e67ef4...
- kazagistar 11y agoI 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
- ggurgone 11y agoA 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 https://gist.github.com/giuseppeg/5939177
- adrae5df 11y agoThere are two conditionals in that code.
- ggurgone 11y agoindeed :) it should be: words[c] || i I focused on the bitwise thing and I overlooked that part
- adrae5df 11y ago|| is a conditional. Is first expression true? If it isn't evaluate the second expression.
- ggurgone 11y agosure, what other conditional are you talking about? the for condition?
- adrae5df 11y agoSecond 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.
- ggurgone 11y agoNo doubt about it. The question was about avoiding the if/else within the for loop body. In js the for could be replaced with an array of 100 elems and a forEach: Array.apply(null, { length: 100 }).forEach(function (_, i) { })
- codesuela 11y agoim gonna learn the random number seed by heart and put it as an anwser every time im asked to do fizz buzz from now on
- jacquesm 11y agoYou'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!
- kragniz 11y agoTangentially related: https://github.com/AbstractBeliefs/BadBuzz https://github.com/AbstractBeliefs/BadBuzz A collection of terrible fizzbuzz solutions.
- russnewcomer 11y agoI 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. Anyone who overthinks FizzBuzz is an automatic hire in my book. (yes, I know about http://www.joelonsoftware.com/items/2005/01/27.html http://www.joelonsoftware.com/items/2005/01/27.html )
- ceejayoz 11y agoIn 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.
- jonesb6 11y agoOk but they were emailed these questions (in what appears to be a take-home format). 1) Know how to use the internet 2) Know how to problem solve by obtaining information from external sources.
- ceejayoz 11y agoI'd rather answer "no clue" in an interview than fake knowledge and wind up in a job where I'm lacking basic required skills.
- russnewcomer 11y agoIn 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.)
- matchagaucho 11y agoI 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. Blog post at http://www.embracingthecloud.com/2012/10/22/EvolutionOfASalesforceApexClass.aspx http://www.embracingthecloud.com/2012/10/22/EvolutionOfASale...
- matthewrudy 11y agoWhat this article misses is my favourite bit: maintainability and extensibility. 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.
- gambiting 11y agoOk, now we need a ridiculously simple version in C, that will probably fit in 64 characters and require a page of explanation :-)
- OscarCunningham 11y agoI 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 26 + log(24) = 26 + 4.58... > 30
- thomasahle 11y agoEven if the number he specifies has leading zeroes, it's still one out of the set of 32 bit numbers.
- OscarCunningham 11y agoHaving leading zeros does make the length of the source code itself smaller though.
- yaks_hairbrush 11y agoAnd 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.
- desireco42 11y agoThis is awesome. And funny. I can imagine how this would piss off people interviewing you who think they are smart. I think I will use it.
- emson 11y agoGreat article thanks. I recently launched the elixirgolf.com web site and there were some really interesting FizzBuzz solutions. Mine used Fermat's little theorem http://elixirgolf.com/articles/elixir-fizzbuzz-golf/ http://elixirgolf.com/articles/elixir-fizzbuzz-golf/