Fizz Buzz in Tensorflow (2016)
joelgrus.com
joelgrus.com
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....
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.
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.
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.
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...
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.
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.
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?"
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.
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.
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.
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.
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.
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.
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.
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".
https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...
- 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.
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.
Umm, no. He implemented all of Fizz Buzz except the loop in his "fizz_buzz_encode" function. Totally explicit.
He implements it explicitly but only to generate training data.
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.
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
Quick nit: FizzBuzz is supposed to print the number if not printing Fizz, Buzz, or FizzBuzz. So the output is not correct.
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).
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 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'm sure I've seen another version already.
#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;
} #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. #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;
}def fizzbuzz (1..100).map{|n|["%sBuzz"%x=["Fizz"][n%3]][n%5]||x||n} end
puts fizzbuzz.join
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 SubLooks like this was first posted two years ago, and has been posted a number of times since; but I never noticed any of them.
The data is conclusive : there is a strong correlation between those articles and the name joel.
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.
Regarding your second point, it would’ve been less funny if they didn’t overfit. :D