Live data from Hacker News

Fizzbuzz, Interviews, And Overthinking

dave.fayr.am

71–80 of 115 posts

Re: Fizzbuzz, Interviews, And Overthinking

#71
post #67

This seems overcomplicated. Why wrap String (which is already a monoid) inside Maybe? You can just use concat; if the result is the empty string then print the number. If you want it to work for any monoid, then use mconcat, and test for equality to mempty. And why introduce monad comprehensions if you're just introducing monoids?

> Why wrap String (which is already a monoid) inside Maybe?

Because it's a bit easier to write the tail end of the logic in generic terms. You can go talk to c_wraith on Freenode#haskell if you want.

> You can just use concat; if the result is the empty string then print the number. If you want it to work for any monoid, then use mconcat, and test for equality to mempty.

You can find other discussions about why flexibility is important.

> And why introduce monad comprehensions if you're just introducing monoids?

Because it's a really nice syntax? Compared to explicitly using guard, anyways.

Re: Fizzbuzz, Interviews, And Overthinking

#72

I agree that Fizzbuzz can be a more interesting example of how to write code without repetition. While the author suggests that languages such as Haskell provide a unique advantage, the deciding question seems to be the availability of pre-built abstractions. Consider the following solution in Python: for i in xrange(1,101): print (('' if i%3 else 'Fizz')+('' if i%5 else 'Buzz')) or i or the even more general: mappin…

Breaks the spec: 'Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.' Actually, this spec is ambiguous, too. For multiples of five, do we print the number AND "Buzz" or just "Buzz" ? Similarly for multiples of 15. I thought the OP was a…

> I thought the OP was a joke, BTW.

Well balls to you too, I guess? Or not. We're all just trying to have a good time here. And from the look of this thread, people are having fun.

I think golfing fizzbuzz into an unreadable mess sorta misses the point, but most people here are software engineers because they love to code and build stuff. So let's enjoy the moment.

> why on earth would one want to hire somebody who loves complexity for its own sake?

You remind me of: http://wondermark.com/333/

It's not complexity for its own stake. I daresay the functional patterns tend to be simpler. Certainly moreso than things like Visitor or AbstractFactory.

> To me, the following is the clearest way to express this (in C anyway). I suppose it says a lot about me!

Your version is almost identical to the Ruby version I listed. And it's an appropriate solution for C.

Re: Fizzbuzz, Interviews, And Overthinking

#73

Forget Fizzbuzz, we get candidates that cannot reverse a string (in their language of choice). A friend of mine just told me he uses the question "What is the hex number that comes after 'F'" as his first "weed-out" technical question. It boggles the mind.

Because I tend to get really nervous in interviews and consequently don't interview all that well most of the time, I try to be sensitive to people like me. I prefer to start very simple and sort of gradually increase the pressure until I can find a backing off point.

Bless you. I get extremely nervous in interviews as well. One that came right out of the gate with difficult questions (not saying string reversal is) would crush me.

Re: Fizzbuzz, Interviews, And Overthinking

#74
post #59

Earlier quoted context omitted.

This can be edited down to six lines with a simple trick: a Python string multiplied by True will return itself, and multiplied by False will return the empty string. for i in range(110): pr = "" pr += "Fizz" * (i%3 == 0) pr += "Buzz" * (i%5 == 0) pr += "Bazz" * (i%7 == 0) print (pr if pr else i) I iterated over range(110) to show that it handles the "FizzBuzzBazz" case correctly. EDIT: Or we could use lambdas as OP'…

Just for fun, another variant - separating logic from data and trying to be pretty stock python. cases = [(3, "Fizz"), (5, "Buzz"), (7, "Bazz")] for i in range(110): pr = ''.join([v[1] * (i % v[0] == 0) for v in cases]) print pr or i

It should be possible in a single line of Python..

  pip install fizzbuzz
And then:

  import fizzbuzz
  print fizzbuzz.fizzbuzz()
Or for the second solution:

  print fizzbuzz.fizzbuzzbazz()

Re: Fizzbuzz, Interviews, And Overthinking

#75
post #62
post #14

I recently challenged people to codegolf fizzbuzz ( http://swizec.com/blog/fizzbuzz-without-ifs-in-90-char-i-wil... ) The Haskell solution was really cool: [max(show x)(concat[n|(f,n) This is much simpler and it looks easier to extend as well.

Python: under 90 characters and no explicits if statements for i in range(100):print ''.join([s*(i%m==0)for m,s in[(3,"Fizz"),(5,"Buzz")]])or i

66 characters:

    " ".join(i%3/2*"Fizz"+i%5/4*"Buzz"or str(i+1) for i in range(100))

Re: Fizzbuzz, Interviews, And Overthinking

#76

    subs = {3 => "Fizz", 5 => "Buzz", 7 => "Bazz"}
    (1..100).map{|n| subs.keys.inject(nil) {|a,k| n % k == 0 ? (a||"")+subs[k] : a} || n.to_s}
Kind of boggles the mind sometimes to realize the crappy code people will write without thinking things through.

Re: Fizzbuzz, Interviews, And Overthinking

#77
post #57

Earlier quoted context omitted.

Explain. If you can't produce a god damned string reversal function in 10 minutes, why would I believe you can produce a bug fix to your own, complex code in a few hours? That's what interviewers are considering: the interview is a proxy to see if you can come close to the requirements of the job.

Can you get in the zone with people watching and judging you intently? If you can't get into the zone with only a couple of people watching you, how will you get into the zone when the whole company is depending on your bug fix? The pressure of judgement is not the same as the work pressure of a stressful scenario. It's why public speaking and job interviews are among the most feared activities people go through, but…

Easy, the company that is depending on me is not physically there, watching and judging me. Sure they probably are watching and judging me, but as long they're not physically present that makes all the difference to my mind...

Re: Fizzbuzz, Interviews, And Overthinking

#78
Great article. The title is a bit misleading though. I thought this was sort of a counter-argument to the 'programmers cannot program', but introduces monoids right at the end.

Anyway, FizzBuzz and the like are the kinds of questions you would probably ask to a new graduate because frankly, there is nothing else to ask from them. They have no related experience for the most part.

For experienced ones, the way our company (http://aelogica.com) identifies good candidates is via a day of pair-programming. Technical knowledge is just part of the package, and any kind of problem solving will not address that.

Re: Fizzbuzz, Interviews, And Overthinking

#79
I've always liked the \r-trick:

    a=b=c=d=(e=1..100).each do |num|
      print num, ?\r,
        ("Fizz" unless (a = !a) .. (a = !a)),
        ("Buzz" unless (b = !b) ... !((c = !c) .. (c = !c))),
        ("Bazz" unless ((d = !d) .. (d = !d)) ... (e = !e)),
        ?\n
    end

Re: Fizzbuzz, Interviews, And Overthinking

#80
post #43

Earlier quoted context omitted.

Because I tend to get really nervous in interviews and consequently don't interview all that well most of the time, I try to be sensitive to people like me. I prefer to start very simple and sort of gradually increase the pressure until I can find a backing off point.

If you cannot reverse a string under pressure, you are likely unqualified for the job you are applying for. At least in my job, there is often more pressure than "write a string reverse function in any language you like in 10 minutes."

What a load of bollocks. If your job is to write methods to reverse strings then you are unqualified, otherwise I wouldn't give a shit whether a candidate can reverse a string. Why would I want to know if someone can reverse a string if the job is to maintain a web app?

A few questions for you. How old are you? Have you hired developers before? Truthfully, have you ever had to reverse a string under pressure at your current job.

Post reply on HN