9 ms·
Fizz Buzz in Tensorflow (2016)
- zeristor 9y agoThis 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.
- sametmax 9y agoMe neither. It reminds me a lot of http://discuss.joelonsoftware.com/default.asp?joel.3.219431.12 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.
- inglor 9y agoThis one is just on Joel's site though - it was written by http://www.benjismith.net/ http://www.benjismith.net/
- deleted 9y ago[deleted]
- razodactyl 9y agoThis 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.
- skrebbel 9y ago> 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.
- amelius 9y ago> 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.
- deleted 9y ago[deleted]
- anc84 9y ago(2016)
- rakoo 9y agoI thought aphyr's version was the original one, but dates don't match: https://aphyr.com/posts/340-acing-the-technical-interview https://aphyr.com/posts/340-acing-the-technical-interview I'm sure I've seen another version already.
- jxub 9y agoIt 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.
- netheril96 9y agoMaybe adding `layer_norm` would help training of the fully connected network. Especially since the input has a large range.
- Scea91 9y agoNice. 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.
- Q6T46nT668w6i3m 9y agoIt’s a joke. :-) Regarding your second point, it would’ve been less funny if they didn’t overfit. :D
- geraldbauer 9y agoLove 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 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
- LanceH 9y agoI took a wild stab at fizzbuzz and got lucky: https://play.golang.org/p/Q7Ek05QjOP https://play.golang.org/p/Q7Ek05QjOP
- dweekly 9y agoThis 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.
- buzer 9y agoSeems 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).
- ericfrederich 9y agoThis reminds me of enterprise fizz buzz. If you haven't seen it, it's great. https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...
- romaniv 9y agoThis 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.
- paulddraper 9y agoContributions welcome. Only superior quality codes accepted.
- vpmpaul 9y agoI 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....
- resonanttoe 9y agoThese 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.
- gregcoombe 9y agoSadly, 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.
- mywittyname 9y agoI 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.
- romaniv 9y agoIt 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.
- fatjokes 9y agoIf 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.
- bllguo 9y agoSeems 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.
- kahlonel 9y agoHere 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; }
- strong_silent_t 9y agoEverytime this question comes up I am powerless to resist re-implementing it. http://codepad.org/KKut69jV 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.
- msla 9y agoThis 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; }
- geraldbauer 9y agoHere'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
- rskar 9y agoAnd 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
- darepublic 9y agoEverytime 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.
- thenoblebuffalo 9y agoYou're not the only one.
- technofiend 9y agoI'm still waiting for some wag to just put a python module on github that solves fizzbuzz and import it in his interview. ;-)