11 ms·
The Fastest FizzBuzz in the West
- jessaustin 10y agoThere seem to be a lot of skipped rules. I think it has something to do with: all-1b4059b…-46d74bf1.js:5 Uncaught TypeError: Cannot read property 'length' of null
- xeniak 10y agoDustin seems to take offence at the idea that FizzBuzz would be used in a technical interview to screen job candidates. Jeff Atwood on the other hand thinks it's a great way to filter out "developers" who can't program their way out of a wet paper bag: https://blog.codinghorror.com/why-cant-programmers-program/ https://blog.codinghorror.com/why-cant-programmers-program/
- sotojuan 10y agoA lot of the people that hate on programming interviews haven't had to interview candidates. Don't get me wrong, interviews are still annoying and sorta broken but your perspective really changes when you're the one filtering candidates.
- Bahamut 10y agoI hate them and I have had to make the call to hire/not hire - what is that supposed to say? The side of hiring I find interesting is more on the behavioral side - many employers don't find enough ways to screen candidates on those grounds, and it is interesting the ways you find candidates filtering themselves out there if you ask the right questions.
- flukus 10y agoCan't we hate them and also hate the fact that they are necessary?
- sotojuan 10y agoYes, that's what I do!
- todd8 10y agoYes, my interviewing generally scaled up in difficulty as the interview progressed. I don't like the idea of putting so much stress on nice people, but it's shocking how many people interview for system's level programming jobs with clearly made up resumes. One young person showed up with a resume listing about 10 programming languages. I simply went through the 10 and asked her how to write a comment for each language. We didn't have to go far before she admitted that she really only knew Pascal very well. To be fair, there were a lot of people that would have made good employees be didn't happen to quite fit the job we were trying to fill at the moment. The matching process often involved a significant degree of luck and I sure that I missed out on many people I should have hired.
- ayuvar 10y agoI won't be happy until I see someone do FizzBuzz in silicon.
- jschwartzi 10y agoThis is apparently a FizzBuzz accelerator written in Verilog: https://gist.github.com/houmei/4649209 https://gist.github.com/houmei/4649209
- toomanybeersies 10y agoVideo of it in action: https://www.youtube.com/watch?v=EJAQTHFFgY4 https://www.youtube.com/watch?v=EJAQTHFFgY4
- 50CNT 10y agoCould probably do it with a lookup table, a counter and some fairly simple boolean logic. You could probably put it on a small FPGA.
- hoodoof 10y agoAll these garbage tests need to go into the standard lib. from jobinterviews import fizzbuzz, redblacktree, irrelevanttheoreticaltest fizzbuzz() redblacktree() irrelevanttheoreticaltest()
- ratfacemcgee 10y ago> We don't use FizzBuzz or anything like it when we screen potential new hires at PromptWorks, and I've never actually been asked to implement it. welp
- andrewstuart 10y agoI'll put it out there. "No programming test these days is valid without full access to Google." This is the opposite to conventional wisdom which says that programming tests must be done in an isolated environment without access to the web "please deposit your mobile phone at the testing room door". No programming is done in isolation so the only way to effectively and realistically test someone is to see what results they get in a real world environment, which means full web access. Don't get me wrong - I am very much against the idea that "I don't need to understand fundamentals cause I can Google everything" - only the misguided think that. What I do think is that recruiting needs to be about measuring real world results - that means full access to Google and StackOverflow. THE most critical skill that is almost NEVER meaured - and in fact is generally avoided measuring - is the programmers skills in Googling to solve unfamiliar problems. The best programmers ride Google and StackOverflow like racehorse jockeys ride the ponies.
- pkaye 10y agoShould one need Google access to do a fizz buzz type of programs?
- andrewstuart 10y agoThe whole point is that if you are properly testing candidates then it is an open test and there's no point in theoretical tests like fizzbuzz when it is open book. The correct solution to fizzbuzz in an open book test is to search Google for "optimal fizzbuzz solution in language X". It forces the employer to create a test that is more real world and thus is a closer reflection of the actual work being done at that company. Unless of course your company is doing alot of real world fizzbuzz.
- flukus 10y agoThat would defeat the point of fizzbuzz in the first place. It's to see if they can translate rules into code, to see if they understand the very basics of programming. If they google "optimal fizzbuzz solution in language X" then you're seeing if they can copy and paste code. There is plenty of room for more open tests, but fizzbuzz doesn't require it.
- avolcano 10y agoThe author using FizzBuzz as a comical-but-recognizable launching point for demonstrating introducing the basics of programming language implementation and RPLY, and the HN comments being nothing but people yelling about FizzBuzz, is a pretty amazing summary of the state Hacker News comments. It also makes me think next time I have a technical article, I should prepend some controversial statement to it just to generate buzz :V In all seriousness: this is a really cool article, thanks for sharing! I'm not very familiar with RPython or RPLY and it was really cool to see a "real-world" example of it. I actually just read through something similar in JavaScript (https://github.com/thejameskyle/the-super-tiny-compiler https://github.com/thejameskyle/the-super-tiny-compiler). I really should give language implementation a shot one of these days (closest I've come is writing a JSON lexer & parser); always like to read about it!
- _asummers 10y agoThere was a project linked to HN in ~December or November of last year about building your own Lisp, which would probably be a terrific jump off point into that, if you're looking for a place to get started.
- kornish 10y agoNot sure which you're referring to, but this is a very digestible overview on PL implementation by HN's very own nostrademons. https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_...
- _asummers 10y agoI THINK this is the one I'm thinking of, the timeline matches. https://news.ycombinator.com/item?id=10474717 https://news.ycombinator.com/item?id=10474717
- imron 10y ago> I should prepend some controversial statement to it just to generate buzz Nah, those articles tend to fizz out
- fucknode 10y agoWhenever asked to do fizzbuzz i always do it in ruby (1..100).each{|n| p "#{'fizz' if n%3==0}#{'buzz' if n%5==0}"}
- flukus 10y agoDo you always fail the test? You forgot what happens when n is divisible by 3 and 5.
- ryanplant-au 10y agoThere doesn't need to be a separate test for 3 and 5, his example already handles it properly -- it's two separate if statements, not an if/elsif, so it'll just meet both conditions and print "fizz" then "buzz" to create "fizzbuzz". What's forgotten is printing the number alone if it's divisible by neither. Fizzbuzz is one of those problems where there's really no clever hidden golfy solution better than the plain old first-reaction naive approach: an iteration with if/elsif/elsif/else.
- wott 10y ago> Fizzbuzz is one of those problems where there's really no clever hidden golfy solution better than the plain old first-reaction naive approach: an iteration with if/elsif/elsif/else. There are. With a funky calculation. For example, taken from Rosetta C version: for (int i=0;++i<101;puts("")) { char f[] = "FizzBuzz%d"; f[8-i%5&12]=0; printf (f+(-i%3&4+f[8]/8), i); } You might say the calculations are hidden if/else, but well...
- jgh 10y agoIt's possible to do with a switch statement as well (in C). Edit: Would be nice if the original author of that code snippet threw in some parentheses for a little clarity with the operator precedence.
- wz1000 10y ago> Fizzbuzz is one of those problems where there's really no clever hidden golfy solution better than the plain old first-reaction naive approach: an iteration with if/elsif/elsif/else. There is if you exploit that monoid homomorphisms exist from any monoidal type to both the Optional and Function types. My favourite solution is this: let (m ~> str) x = str <$ guard (x `mod` m == 0) in map (fromMaybe . show <*> 3 ~> "fizz" <> 5 ~> "buzz") [1..100] This is extensible because you can stick as many rules as you want in there, or even factor them out and make it a function (m ~> str) x = str <$ guard (x `mod` m == 0) fizzbuzz rules = map (fromMaybe . show <*> mconcat rules) fizzbuzz [3 ~> "fizz", 5 ~> "buzz", 7 ~> "bazz"] [1..100]
- deleted 10y ago[deleted]
- kevin_thibedeau 10y ago> it's is a mythical interview question to see how well you can write code in an environment in which you will never actually write code. > The goal is to sufficiently intimidate junior developers so they will know to steer clear of your organization. We use fizzbuzz on senior devs claiming to be C++ experts and they stumble on it regularly.
- freework 10y ago> We use fizzbuzz on senior devs claiming to be C++ experts and they stumble on it regularly. This outcome can be evidence of either condition: 1. There are a lot of expert developers who are actually not experts 2. The test is giving false negatives Which do you think it is?
- junke 10y agoBoth
- mcbain 10y agoI wish we'd used it for a recent senior c++ dev hire. And this was an internal hire. They were just way too good at playing the game and it took us way too long to get rid of the person - fired, not just dumped.
- svckr 10y agoSaying one is a C++ expert is a pretty extraordinary claim and should require extraordinary evidence :) I'm regularly intimidated by positions looking for capital s Senior C++ developers, because no matter how deep my knowledge goes, memory model, templates substitution rules and all, I realize there's dragons lurking behind every corner. Now, C is a language that fits in my head, C++ … not so much, but maybe that's because it is not part of my daily routine. I'd suggest you look for _productive C++ developers_ that know their limitations. I think you might even get better candidates that way.
- flukus 10y ago> I'd suggest you look for _productive C++ developers_ that know their limitations. I think you might even get better candidates that way. It sounds like they are. The "expert" is a self described one.
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- rrobukef 10y agoI can't help but notice that it doesn't help when the order of the strings need to change. Consider the following problem: For multiples * of 105 print 'buzzfizzfuzz' * of 35 print 'buzzfuzz' * of 21 print 'fuzzfizz' * of 15 print 'fizzbuzz' * of 7 print 'fuzz' * of 5 print 'buzz' * of 3 print 'fizz'
- di 10y agoWhy would the order of strings need to change? I would assume that if 15=="fizzbuzz" than 105 would be "fizzbuzzfuzz", not "buzzfizzfuzz".
- vikiomega9 10y agoLoved it! I learnt something about compiler design today!!