Hacker News new | comments | show | ask | jobs | submit login
Fizz Buzz in Tensorflow (2016) (joelgrus.com)
186 points by sametmax 6 months ago | hide | past | web | favorite | 53 comments



I know people consider it condescending if they are actually a competent programmer. However as a person that has done hiring I can't tell you how many people have a CS degree that they supposedly attended school and passed(as in their credentials check out) but can't even do the FizzBuzz test.

Once time for fun I used one of those online code collaboration tools. I had a couple of "programmers" that were still actively working on the Fizzbuzz question 4 hours later. I went to lunch and forgot about it after I came back until the end of the day and realized there were still people working....


It is condescending. Asking people to do FizzBuzz indicates that you expect a large portion of your candidates to be completely clueless. That's not a good message to send.

Think about the following. FizzBuzz filters out some extreme cases of incompetence, but tells you nothing of value about the people who passed. You can use the same chunk of interview time to ask a more challenging question that will still filter out the extremely incompetent, but also give you some level of confidence in the people who passed. So why would you prefer to ask a question that gives you less useful information?

It's not unlike a sorted array search algorithm. To maximize your efficiency you start in the middle, not at some arbitrarily chosen low point.


Maybe I'm missing something or it's a personality trait, but I think if you're an expert, being asked to do a FizzBuzz isn't condescending: it's an opportunity to play in speedrun mode.

I deeply dislike the job interview culture and whiteboard trickery, but I'm also wary of people who see themselves above mundane requests. That's how you hire someone who leaves code undocumented ("who needs it? I can understand it perfectly"), adopts clever but inscrutable techniques, etc.


>I'm also wary of people who see themselves above mundane requests.

Let me give you an analogy from another domain.

"My company requires excellent communication and writing skills, so would you mind talking a 5h grade spelling and grammar test?"


> "My company requires excellent communication and writing skills, so would you mind talking a 5h grade spelling and grammar test?"

That's not comparable. A total whiteboard interview might take several hours, but it increases significantly in complexity from basic FizzBuzz.

A more comparable analogy would be asking them to merely edit a few paragraphs for grammatical mistakes, or something similarly trivial in whatever domain you'd like that should take fewer than 10 minutes if the person has literally any meaningful facility with the work.

Like the person you're responding to, I'll say this: I deeply dislike whiteboard coding culture. But of the things I dislike about whiteboard coding, I dislike dead simple sanity checks the least.


I think they meant to say "5th", not "5h" as in "5 hour".


This is misplaced ego. A 5 th gramar test is alright. Fizzbuzz is alright.

Chill out, life has real problems in store when it's about job hunting (or anything). A 2 minutes exercice bellow your skill level is not one of them.


It is condescending (though as an applicant, my reaction is more of a sigh ok, then I waste 30 seconds) and a large portion of applicants aren't the right fit.

From my experience interviewing candidates, I find the most effective are multi-part questions where difficulty increases exponentially from step to step.

Someone who doesn't do well may only get past the first part (a less clear fizzbuzz) and feel great about it, maybe even learn something. A good person may move onto the much more challenging parts and hopefully teach you something along the way. It's a difficult balance, though I've got a few well-seasoned questions I like to use. Its always cool as an interviewer who has seen hundreds of answers to the question be shown a new and creative way of approaching it.


When interviewing I find that you can't start by asking a really challenging question if you're towards the beginning of the loop. If the candidate happens to bomb that one interview and gets flustered, it can easily tilt them for the remaining interviews which kills the signal you get from those later interviews.

So ideally you ask a question that on the surface can be simplified to about fizzbuzz level, but can be seamlessly scaled up to higher difficulty.

So yea literal fizzbuzz is bad 'cus it doesn't scale up at all. But a similarly easy question to start with...


> It is condescending. Asking people to do FizzBuzz indicates that you expect a large portion of your candidates to be completely clueless. That's not a good message to send.

I think it's a fairly honest message. Regardless of how you feel about demanding data structure implementation and asymptotic analysis on a whiteboard in an interview, there are many people interviewing who literally cannot code. I don't believe you can find a heuristic to filter them out that won't come across as condescending.

The problem is that interviewers cannot usefully distinguish between people who are protesting FizzBuzz because they can't do it and people who are protesting it because it's actually beneath them. On the other hand, candidates can reframe their attitude. I don't think they should put up with all the nonsense hazing of whiteboard interviews, but FizzBuzz can literally be done in the time it's taken me to write this comment. If a candidate pushed back against doing it, I'd actually point that out.

I've interviewed people who were "senior" engineers, yet couldn't actually complete FizzBuzz problems in their areas of expertise. It's not a trick question or testing for something abstract and far removed from the job - it's testing for, "Have you flipped through a book, compiled a program, and ran it before?" I'm sure some of the people I asked found it condescending as well, in particular the ones who couldn't complete it. But it saved me an hour of second-hand embarrassment.

> Think about the following. FizzBuzz filters out some extreme cases of incompetence, but tells you nothing of value about the people who passed. You can use the same chunk of interview time to ask a more challenging question that will still filter out the extremely incompetent, but also give you some level of confidence in the people who passed. So why would you prefer to ask a question that gives you less useful information?

You are talking about 5 - 10 minutes of interviewing time here. If I weed out some nontrivial percentage of applicants using a benchmark that doesn't rely on trickery and actually tests for facility with the domain, I'm happy! That's a great result - I don't want to be condescending, so if you have a better suggestion, I'd love to hear it. But like I said, sooner or later you're going to insult people with these mundane questions. You can spend the rest of the entire interview on whatever sexy signaling material you'd like, it's not like the FizzBuzz problem really ate into your time budget (unless, of course, they actually cannot code).

To give you a concrete comparison: I'm very competent in cryptography (up to and including research and protocol cryptanalysis). If someone were to ask me in an interview, "Hey, what's the difference between symmetric cryptography and asymmetric cryptography", I wouldn't respond with, "Haven't you read my resume? Ask me something real." If they asked me to, I don't know, draw a diagram of a Feistel network, I wouldn't roll my eyes and take offense. I'd just do it. I might have a lesser view of their recruiting pipeline after the fact, but I'd sympathize with the necessity of the question overall and hope the interview picks up in the next ten minutes.


>I don't want to be condescending, so if you have a better suggestion, I'd love to hear it.

Almost every interviewee has a git(hub/lab) account with code they're written, that should suffice to determine if they can FizzBuzz. You could also ask them for a coding sample prior to the interview if they have no public code.

The solution is simple, nobody does it because it asks the interviewer to do more than skim the resume before walking into the room. I think this comes from the perception that the interviewee's time is cheap compared to that of the interviewer's.


> Almost every interviewee has a git(hub/lab) account with code they're written, that should suffice to determine if they can FizzBuzz.

No, almost every interviewee does not have public code, and what's more, that should be irrelevant to your process. Your proposal here selects for people who have a lot of free time or few hobbies outside of work (or a combination thereof). It's not selecting for ability. Ideally each candidate should receive the same interview; having public code shouldn't bypass what candidates without public code have to do.

> You could also ask them for a coding sample prior to the interview if they have no public code.

I could, and I'm personally a fan of that. But it has its own problems:

1. The assignment can still be perceived as condescending by prospective candidates. Are their feelings about this less valid than if I asked the question directly on a phone interview? Where is the line between reasonable and unreasonable contempt for a mundane task in an interview process?

2. You're still selecting for people who have free time. They either don't currently have a job, or they have free time outside of work to complete your assignment. Unless your assignment takes a trivial amount of time, in which case we're right back where we started.

> The solution is simple, nobody does it because it asks the interviewer to do more than skim the resume before walking into the room. I think this comes from the perception that the interviewee's time is cheap compared to that of the interviewer's.

The solution is emphatically not simple, or it would have been done in the industry already. Many people want it to be solved on both sides of the table. Your perception appears to be that interviewees' time is so valuable it's reasonable for them to be offended by a programming question so far below their (apparently vast) level of ability. You're asserting a hypothesis that interviewers are not respectful of time and saying they can't be bothered to review a resume, but it's fair if an interviewee can't be bothered to answer a simple programming question in an interview? Moreover, people lie or exaggerate on their resumes, which diminishes their absolute utility - like I said, I've seen senior engineers fail FizzBuzz.

Alternatively, both sides can simply acknowledge that there isn't a simple solution and that everyone's time is valuable, then excuse the other for asking questions that are specifically designed to save everyone time. You're free to ask such questions and apply your own filters, too.


This doesn't work, because candidates can (and apparently do) lie.

I've interviewed people who have a pointer to a github account that has reasonable code, who then cannot code something basically as easy as fizzbuzz.

I assume it's because they lie about that being their github account, though maybe it's because they need an IDE to code a single stateless loop.

Edit: or maybe they just haven't coded in >years, and have forgotten how? I don't know.


>This doesn't work, because candidates can (and apparently do) lie.

I have not found this to be the case. I ask people about specific projects they have posted and sometimes look through the code together and ask them about the time-space complexity of function they've written.

Maybe you're just encountering test-anxiety.


Sadly, your experience is not uncommon. I've run across the same thing too many times to count.

We tried for a little while to have an online test (HackerRank) before we interviewed, but we removed it when we got feedback that the really good people (who probably already had a job and/or existing offers) just didn't bother.


I can attest to doing this.

It's really unfortunate, because a lot of companies that go through great lengths to ensure they pick good candidates do so because they are small and one bad hire could really hurt the company. But the fact is, larger companies are less discriminant with their hiring, and usually pay better too. So when faced with the option of doing yet another programming quiz for a company or accepting the job offer I have in hand, it makes sense to just accept.


These types of write ups (though sometimes very technically interesting) always have the "Don't you know who I am?" about them, which is very annoying.


I spent part of my academic career working on 3SUM. When I was recently asked to solve a subset sum problem in an interview, I completely froze. It was horrible. I couldn’t, for whatever reason, remember how-to loop. Needless to say, I didn’t get the job (and I appreciate the trade-off between true positives and false positives). You don’t need to hire them, but I’d ask you to take the most charitable interpretation of their work.


It is condescending and it says more about your company than anything else.

It roughly says "we are so hopeless with the quality of our pipeline of candidates and assessments that we have to make sure you can do FizzBuzz".


This reminds me of enterprise fizz buzz. If you haven't seen it, it's great.

https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...


This legitimately looks like some legacy apps I had to deal with in real life. The language and the framework of choice were different, but the principle was the same.


Contributions welcome. Only superior quality codes accepted.


If this actually happened the only signal I would get from this interview is that the candidate is a egotistical asshole. No hire.

- It's always good to not assume that the candidate is familiar with a given question, no matter how well known it may be. Maybe they're from a different country, maybe they're from a different industry altogether making a transition.

- I bet if the question was difficult or complex the interviewer would say "omg that's not realistic, would never use this in real job".

Then again, I'm also in the minority of HN users who like coding/problem solving interviews so what do I know.


Seems obvious to me that the guy wasn't interested in the job when he was told to do fizzbuzz, hence the stunt. Being "egotistical" was kinda the whole point.


This was fun, I did a live demo at work a few months ago on this, got stuck on getting the model to predict with enough accuracy to be useful then came across this post, my activation function was slightly off.

Most people understand Fizz Buzz, building up and solving the problem with a neural network shows that a bit of ML code can solve the problem without being programmed explicitly to do so, quite a good example.


> ML code can solve the problem without being programmed explicitly to do so

Umm, no. He implemented all of Fizz Buzz except the loop in his "fizz_buzz_encode" function. Totally explicit.


That’s the joke!

He implements it explicitly but only to generate training data.


That's just code to generate the examples, an example of synthetic data. He could just have written down the expected output instead of doing that.


> Most people understand Fizz Buzz, building up and solving the problem with a neural network shows that a bit of ML code can solve the problem without being programmed explicitly to do so, quite a good example.

If you train your model with completely different data than you use for inference, there is absolutely no guarantee that it will work as expected. In this case, they trained with numbers >= 1024, where numbers <= 100 were used for inference.


Love the write-up. FYI: I've published a (free online) book(let) about FizzBuzz titled "FizzBuzz by Example - There's More Than One Way To Do It" [1] in the Yuki & Moto Press Bookshelf series. [1] http://yukimotopress.github.io/fizzbuzz

PS: My favorite FizzBuzz version - the gold standard with constant lookup:

def fizzbuzz [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz", "Fizz", 52, 53, "Fizz", "Buzz", 56, "Fizz", 58, 59, "FizzBuzz", 61, 62, "Fizz", 64, "Buzz", "Fizz", 67, 68, "Fizz", "Buzz", 71, "Fizz", 73, 74, "FizzBuzz", 76, 77, "Fizz", 79, "Buzz", "Fizz", 82, 83, "Fizz", "Buzz", 86, "Fizz", 88, 89, "FizzBuzz", 91, 92, "Fizz", 94, "Buzz", "Fizz", 97, 98, "Fizz", "Buzz"] end


Seems like all of the examples (short of precomputed table) use modulo. There are couple of other ways to deal with it as well. Two that I came up with at one point:

1. Create your own mod function (you can most likely leave out dealing with negatives and overflows as long as you just point that out). Given dividend X and divisor Y, while X>=Y: X=X-Y and finally return X.

2. Take human approach and convert the number to string. Skip 0/print it depending on definition. If the last character is 0 or 5, it's dividable by 5. For dividable by 3, you loop thru the string and sum the numbers. Repeat until the length of string is 1. Now compare it to 3, 6 and 9 (you can convert it back to number or just compare the string of those). If it's true, it's dividable by 3.

Not nearly as optimized as mod-based solution or precomputed tables, but they show it's possible to solve it even if you are not familiar with modulo (it's not very commonly used in some higher level languages).


Good point. Another example without modulo in the FizzBuzz by Example book is using cycle e.g.:

def fizzbuzz

  fizzy = [nil, nil, :Fizz].cycle
  buzzy = [nil, nil, nil, nil, :Buzz].cycle

  (1..100).map do |n|
     "#{fizzy.next}#{buzzy.next}"[/.+/] || n
  end
end


Hah, you beat me to it, I just wrote this up in Rust.

    fn main() {
        let mut seq_mod_3 = [false,false,true]
            .into_iter()
            .cycle();
        let mut seq_mod_5 = [false,false,false,false,true]
            .into_iter()
            .cycle();
        for i in 1..101 {
            let divisible_by_3 = *seq_mod_3.next().unwrap();
            let divisible_by_5 = *seq_mod_5.next().unwrap();
            
            match (divisible_by_3, divisible_by_5) {
                (true , true ) => println!("fizzbuzz"),
                (true , false) => println!("fizz"),
                (false, true ) => println!("buzz"),
                (false, false) => println!("{}", i),
            }
        }
    }


I took a wild stab at fizzbuzz and got lucky:

https://play.golang.org/p/Q7Ek05QjOP


This is brilliant and evil: LuckyFizz!

Quick nit: FizzBuzz is supposed to print the number if not printing Fizz, Buzz, or FizzBuzz. So the output is not correct.


That's the test suite, isn't it?


I thought aphyr's version was the original one, but dates don't match: https://aphyr.com/posts/340-acing-the-technical-interview

I'm sure I've seen another version already.


Here is a C version of fizzbuzz if anyone has an interview tomorrow:

  #include <stdio.h>
  int main(void)
    {
      int i = 0;
      for(i=1; i<=100; i++)
      {
        unsigned int f = 0;
        if(i % 3 == 0)
        {
          f = 1;
        }
        if(i % 5 == 0)
        {
          f |= 2;
        }
        if(f == 0)
        {
         printf("%d\n",i);
        }
        else if(f == 1)
        {
          puts("fizz");
        }
        else if(f == 2)
        {
          puts("buzz");
        }
        else if(f == 3)
        {
          puts("fizzbuzz");
        }
      }
      return 0;
  }


This is the shortest non-clever version I can come up with:

    #include <stdio.h>

    int main(void)
    {
        int i;

        for (i = 1; i <= 100; i++) {
            if ((i % 3) == 0) {
                printf("Fizz");
            }

            if ((i % 5) == 0) {
                printf("Buzz");
            }

            if ((i % 3) && (i % 5)) {
                printf("%d", i);
            }

            puts("");
        }

        return 0;
    }


Here's the short ruby version from code golfing in 54 bytes:

def fizzbuzz (1..100).map{|n|["%sBuzz"%x=["Fizz"][n%3]][n%5]||x||n} end

puts fizzbuzz.join


Everytime this question comes up I am powerless to resist re-implementing it.

http://codepad.org/KKut69jV

  #include <stdio.h>
  
  int main() {
    int i;
    for (i = 1; i < 101; i++) {
  
      int div3 = 0 == i % 3;
      int div5 = 0 == i % 5;
  
      if (div3 || div5) {
        printf("%s%s\n", 
          div3 ? "fizz" : "", 
          div5 ? "buzz" : "");
      } else {
        printf("%d\n", i);
      }
    }
    return 0;
  }
I will admit, it took me 4 tries to get this to compile.


And now, in VBA:

    Sub Main()
    
        Dim i As Integer
        For i = 1 To 100
            Dim f As Integer
            f = IIf(i Mod 3, 0, 1) Or IIf(i Mod 5, 0, 2)
            Dim buf As String
            If f = 0 Then
                buf = Format(i)
            Else
                buf = IIf(f And 1, "fizz", "") + IIf(f And 2, "buzz", "")
            End If
            Debug.Print buf
        Next i
    
    End Sub


Everytime I am reminded of these fizz buzz stories I can't help but bust out console and write a quick implementation of this to reassure myself I'm not utterly incompetent. I guess I have a bad case of impostor syndrome.


You're not the only one.


This is excellent.

Looks like this was first posted two years ago, and has been posted a number of times since; but I never noticed any of them.


Me neither. It reminds me a lot of http://discuss.joelonsoftware.com/default.asp?joel.3.219431....

The data is conclusive : there is a strong correlation between those articles and the name joel.


This one is just on Joel's site though - it was written by http://www.benjismith.net/


I'm still waiting for some wag to just put a python module on github that solves fizzbuzz and import it in his interview. ;-)


Maybe adding `layer_norm` would help training of the fully connected network. Especially since the input has a large range.


It seems we can already train a neural network to outperform an average JavaEE programmer. For many of them, his is the start of an era of gloom.


(2016)


Nice. He built an overcomplicated algorithm that is wrong. FizzBuzz was created to also identify this kind of candidates apart from those that can't program at all.

Nevertheless, if I was an interviewer I would have several questions that were unanswered in this iamverysmart writeup:

1) Why did you choose to encode 1 dimensional input as 10 dimensional input with the binary encoding?

2) Do you think that one source of error could be using different underlying distribution for the training and testing dataset? You are basically trying to extrapolate the training dataset.

3) Since this problem can be easily visualized, plot the learned function.


It’s a joke. :-)

Regarding your second point, it would’ve been less funny if they didn’t overfit. :D




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: