News for hackers. Stuff that matters.
Re:Ask HN: Why is it that so many people fail fizzbuzz? by boyter on Wednesday November 21, 2012 @08:21PM (#4817127)
I wonder if its because the modulus operator (the obvious way to solve it) isn't something you use all the time for basic CRUD applications?

As an example i'm working on a largish codebase (100,000 lines) right now now and a quick grep shows only 4 uses of it, all of which are in a jQuery plugin.

Re:Ask HN: Why is it that so many people fail fizzbuzz? by jholman on Wednesday November 21, 2012 @08:47PM (#4817171)
My new interview-screening question will be "solve fizzbuzz without using division or modulus". Because it's still so easy that you don't want to hire anyone who can't do it.
Re:Ask HN: Why is it that so many people fail fizzbuzz? by petethered on Thursday November 22, 2012 @03:52AM (#4818048)
Simple Perl Code

  my $i;
  my $fizz = 3;
  my $buzz = 5;
  for ($i = 1; $i <= 100; $i++) {
    if ($i ne $fizz && $i ne $buzz) {
      print "$i\n";
      next;
    }
    if ($i eq $fizz) {
      print "fizz";
      $fizz += 3;
    }
    if ($i eq $buzz) {
      print "buzz";
      $buzz += 5;
    }
    print "\n";
  }
Edit for formatting
Re:Ask HN: Why is it that so many people fail fizzbuzz? by ukoki on Thursday November 22, 2012 @11:33AM (#4819248)
or in stupidly terse Ruby... f,b=3,5;(1..100).each{|i|s='';(s,f='Fizz',3)if(f-=1)==0;(s,b=s+'Buzz',5)if(b-=1)==0;puts(s==''?i:s)}
Re:Ask HN: Why is it that so many people fail fizzbuzz? by Hannan on Wednesday November 21, 2012 @09:33PM (#4817273)
As a primarily CRUD developer, I use mod all the time. Primarily for zebra striping in browsers that don't support :even or related CSS.
Re:Ask HN: Why is it that so many people fail fizzbuzz? by pedalpete on Wednesday November 21, 2012 @10:37PM (#4817418)
I hadn't even thought of using a css based answer to fizzbuzz, but I guess it is possible now.
Re:Ask HN: Why is it that so many people fail fizzbuzz? by yen223 on Wednesday November 21, 2012 @08:51PM (#4817188)
Is there a non-mathematical version of the FizzBuzz test?
Re:Ask HN: Why is it that so many people fail fizzbuzz? by a_bonobo on Wednesday November 21, 2012 @09:14PM (#4817230)
I just googled around for that, and here's a brutish one in Ruby: https://gist.github.com/3230825

And because I had to fiddle around manually to understand it (not good at Ruby's inbuilt methods) here's how it works: It generates two long arrays, one containing "Fizz" every third element, and one containing "Buzz" every five elements, the rest is filled up with nils.

Then it iterates over 1 to 100 and zips the two arrays at that position together - if the "zipped together" sum of both arrays is nil, that number is printed, else the concatenated string of both arrays at that position is printed (example: "Fizz" + nil = "Fizz"). Neat!

Edit: I also found a great one using flip-flops: https://gist.github.com/3230984

Re:Ask HN: Why is it that so many people fail fizzbuzz? by yen223 on Wednesday November 21, 2012 @09:22PM (#4817255)
That is actually a rather clever solution. I guess you could do the same in Python, using itertools.

That said, I guess I should rephrase my question: Is there a simple programming test that can help weed out fakers quickly, which does not involve mathematics? Sort of like "Deploy a simple CRUD app in 15 mins" or something?

This is to address the parent's concern that a lot of web apps out there don't actually require much mathematics.

Re:Ask HN: Why is it that so many people fail fizzbuzz? by freework on Wednesday November 21, 2012 @10:30PM (#4817401)
I did a coding interview problem once where the company gave me an API endpoint that spat out JSON representing products, and told me to build a page that displays those objects onto a page with infinite scroll. As you scrolled down to the bottom of the page it would load more products.
Re:Ask HN: Why is it that so many people fail fizzbuzz? by a_bonobo on Wednesday November 21, 2012 @11:27PM (#4817494)
For completion's sake, yes you can do that in Python, it's just slightly uglier (as far as I know) using

''.join(filter(None, [a, b]))

and

itertools.cycle([None, None, 'Fizz'])

itertools.cycle([None, None, None, None, 'Buzz'])