Hacker News new | past | comments | ask | show | jobs | submit login
Fifty Fizzbuzzes (vihart.com)
143 points by Jakob on Nov 1, 2018 | hide | past | favorite | 57 comments



This is where the actual fizz buzzes are: https://github.com/vihart/fiftyfizzbuzzes/blob/master/Fifty%...


Note also that not all of them are correct :)


I like this idea. I find it fascinating how many developers I've interviewed who still have not come across FizzBuzz, and how many of those cannot solve the problem. Some of the more interesting interviews I've given though have been with people who know the FizzBuzz problem, where I ask them to make the worst possible version of it that they can. It turns out to be more difficult than they think it will be, and a deeper thinking and communicating exercise than solving the simple FizzBuzz problem itself.


  let tokens = [];
  tokens.push("Fizz", "Buzz", "Fizzbuzz");
  for (let i = 0; i <= 100; i++) { tokens.push(i); }

  function generateFizzBuzz(n) {
    if (n > 100) { return [[]]; }
    let result = [];
    for (let token of tokens) {
      for (let tail of generateFizzBuzz(n+1)) {
        tail.splice(0, 0, token);
        result.push(tail);
      }
    }
    return result;
  }

  let candidates = generateFizzBuzz(1);
  while (candidates.length > 1) {
    let candidateIndex = Math.floor(Math.random() * candidates.length);
    let candidate = candidates[candidateIndex];
    let checkIndex = Math.floor(Math.random() * 100);
    let expected = checkIndex % 3 == 0
      ? (checkIndex % 5 == 0 ? "Fizzbuzz" : "Fizz")
      : (checkIndex % 5 == 0 ? "Buzz" : checkIndex);
    if (candidate[checkIndex] !== expected) {
      candidates.splice(candidateIndex, 1);
    }
  }

  return candidates[0];


> the worst possible version of it that they can

Based on a true story, sadly:

  #! /usr/bin/tail -n+2
  1
  2
  Fizz
  4
  Buzz
  [...]
  98
  Fizz
  Buzz
On the other hand, there's also ones like:

  let{a="ssfsbfssfbsfssX"++a;x 's'=show;x 'f'=const"Fizz";x 'b'=const"Buzz";x 'X'=const"FizzBuzz"}in putStrLn$concat$map(\(i,f)->x f i++"\n")(zip[1..100]a)
(because who needs divisibility tests, right?)


Can't solve because they weren't actually programmers or more because of deer in headlights?


Yes.


octave

  a=[1:100];
  b=strcat({'','fizz'}([1+!mod(a,3)]),{'','buzz'}([1+!mod(a,5)]));
  a=num2cell(int16(cellfun(@isempty,b)).*a);
  b(cellfun(@isempty,b))=0;
  strcat(b,a)


The python notebook linked in the main post:

https://mybinder.org/v2/gh/quasiben/fiftyfizzbuzzes/master?f...


Vi's site is down from the onslaught.

In the meantime, enjoy the ever-classic Fizz Buzz Enterprise Edition:

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



Not sure whether to think "Damn!" or "Good, someone else has already had that dumb-but-fun idea, so now I don't have to do it!"


I wonder, and hope, that this really happened.


It's still entertaining enough, even if made up.


I opened the link thinking ”hah, what a gag!” But then I thought it’d be funny to try to find the core fizzbuzz logic. Turns out that it hits way too close to home, I just got really annoyed. Not sure what I expected.


As the original author, I apologize for your agony.

This is a common complaint from people I discussed the project with, and the obvious reason for the success of the project in terms of people contributing patches and issues.


But then I thought it’d be funny to try to find the core fizzbuzz logic.

The point is that there is no "core" logic anymore. It's been broken down and spread out over a dozen files, each of which does "one and only one (tiny) thing" according to the "best practices" of problem decomposition. Then all the pieces are glued together again using design patterns.


It does hit close to home. I've seen all that code in one form or another. The "adapter" that ignores exceptions made me chuckle though. But like enterprise code I've seen before I have no chance of finding that class again although I am sure it exists.


I think it's a work of art, and your feelings corroborate this opinion :)


Not too long ago I had to deal with C# in the same style, which reminded me of it; and not surprisingly, there's also a C# version:

https://github.com/jongeorge1/FizzBuzzEnterpriseEdition-CSha...


Or if you want to abuse dynamic and lambdas in C#:

https://github.com/tonyedgecombe/functionalfizzbuzz/blob/mas...


I feel like everyone leaving a fizzbuzz solution in the comments of this post is missing the point of this article...


Fizzbuzz does that to some people. It's a mind-control meme, and a very powerful one.



HN user aidenn0 won FizzBuzz a few years ago, with a Malbolge [1] version:

https://news.ycombinator.com/item?id=4922282

[1] https://en.wikipedia.org/wiki/Malbolge



Is this the same vihart of YouTube hexaflexagon fame?

https://youtu.be/VIVIegSt81k


Yes.


I didn't know that fizzbuzz was a children's game.

That explains a LOT. As in most descriptions of it are annoyingly ambiguous.

Whereas if you knew the game, you know it already.


> As in most descriptions of it are annoyingly ambiguous.

My very first interviewer (intentionally) didn't spec fizzbuzz correctly. The real test was whether the candidate listened to the customer's/lead engineer's spec instead of jumping to conclusions.

Fortunately, I was just entering college and hadn't heard of fizzbuzz before. I passed the "test" but for the wrong reason.


Being purposely misleading then penalising those who are misled doesn't seem like a good hiring strategy, but then again, I've never tried to hire someone.


Here's mine:

    Array.from(new Array(100)).forEach((_, i)=>++i&&console.log(((i%3?"":"Fizz")+(i%5?"":"Buzz"))||i))
https://twitter.com/tracker1/status/1045475226128007169


I just committed a version that works in my golang BASIC interpreter:

https://github.com/skx/gobasic/blob/master/examples/15-fizz-...

Perhaps not the cleanest, since I support neither `CASE` nor `ELSE IF`. But it seems to be correct.


We've killed it.



FYI: You find 20+ in the FizzBuzz by Example - There's More Than One Way To Do It (Free Online Book Edition) - http://yukimotopress.github.io/fizzbuzz



Here's my long-ago contribution. Scroll down for the visual. https://codepen.io/daphneokeefe/pen/Ayxlz


Vi Hart's YouTube channel is quite entertaining: https://www.youtube.com/user/Vihart


  #include <stdlib.h>
  #include <stdio.h>
  
  static const char str[] = "fizzbuzz";
  
  static inline void out(int i, size_t offset, size_t sz)
  {
  	if (sz) {
  		fwrite(str + offset, sz, 1, stdout);
  	} else {
  		fprintf(stdout, "%d", i);
  	}
  	putchar('\n');
  }
  
  int main(void)
  {
  	for (int i = 1; i <= 100; i++) {
  		int a = i % 3 == 0;
  		int b = i % 5 == 0;
  		out(i, 4*((a^b)&b), 4*(a+b));
  	}
  	exit(0);
  }
There's a way to remove that conditional, too. Probably.


This is called out in the post, but 32 is actually a really cool rhythmic (and accurate) fizzbuzz.


  {:[~x!15;"fizzbuzz";~x!3;"fizz";~x!5;"buzz";$x]}'1+!100
  {:[0<#w::[x!3;"";"fizz"],:[x!5;"";"buzz"];w;$x]}'1+!100


Are there any shorter programs than these two k3 ones?


In Dyalog APL:

    {∊(3↑(0=3 5|⍵)∪1)/'Fizz' 'Buzz'⍵}¨⍳100
https://tryapl.org/?a=%7B%u220A%283%u2191%280%3D3%205%7C%u23...


Neat!


A small exercise:

write Spectre/timing attacks resilient fizzbuzz.


[flagged]


> Please don't post shallow dismissals, especially of other people's work.

https://news.ycombinator.com/newsguidelines.html


Vi Hart isn't a guy.


And Vi Hart isn't just somebody either.


Why does static content need a database connection? #OverEngineering


The entire blog post is about how to over-engineer FizzBuzz for fun and learning.


Using WordPress is "over-engineering"?


Yes


WordPress should include a cache switched on by default then you have to turn it OFF as an advanced setting. That'd be good for performance and the environment :-)

But using Wordpress is no more overengineering than buying a car. (Versus building your own 2 stroke engine because it's simpler).


Wordpress is under-engineering. It's what you default to when you don't want to do any engineering and just deploy the standard blog solution that everyone's familiar with.


More or less so than running a static site generator that lives on one particular machine, and using Git to push your changes to the server?


More like use a static generator to push to S3, optionally with a Cloudfront distribution in front of it.




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

Search: