Live data from Hacker News

Fizzbuzz, Interviews, And Overthinking

dave.fayr.am

21–30 of 115 posts

Re: Fizzbuzz, Interviews, And Overthinking

#21
post #7

Earlier quoted context omitted.

Just as you can write FORTRAN or COBOL in any language, you can write functional code in any language.

No you can't, as you need the language to provide a few basic building blocks, such as lambdas, and the ability to pass functions as arguments.

You can generally approximate higher order functions in almost every OOP language. See C++ before it got lambdas, they have a pattern. See also java's anonymous inner classes, which are often used with the Runnable interface for that rule.

Re: Fizzbuzz, Interviews, And Overthinking

#22

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.

I wonder what kind of answers he gets for that. I think I would probably answer that verbally as "sixteen, spelled one-zero".

Re: Fizzbuzz, Interviews, And Overthinking

#23
post #13

Earlier quoted context omitted.

I honestly don't understand why that's crazy. Empty string evaluates as falsey, so the "or" picks the 10, which is obviously equal to 10. Or am I missing something?

It just seems like a bad choice. The empty string being falsey is... very arbitrary to me. It seems like it's strictly a perl legacy thing that should be (but cannot be) reconsidered. About as far as I am willing to go is nil punning.

FWIW - it has been reconsidered in Ruby - all values are truthy except nil and false.

Re: Fizzbuzz, Interviews, And Overthinking

#24
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.

60 character solution in LiveScript[0], without using 'if's, also easily extensible!

[1 to 100]map(->[s for s,n of{Fizz:3,Buzz:5}|it%n[0]http://gkz.github.com/LiveScript/

Re: Fizzbuzz, Interviews, And Overthinking

#25

  cases = (
    (3, 'Fizz'),
    (5, 'Buzz'),
    (7, 'Bazz'),
    (11, 'Boo'),
    (13, 'Blip'),
  )

  for i in range(1, 101):
      out = []
      for c in cases:
          if i % c[0] == 0:
              out.append(c[1])
      if out:
          print ''.join(out)
      else:
          print i

Edit: not to detract from the post's point, I think it's valid. Monoids are cool and all but simple counting arguments can take you a long, long, long, way when case analysis fails you.

Re: Fizzbuzz, Interviews, And Overthinking

#26
post #18

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…

My "I'm going to hell, but that's okay" C version: #include #include #define when(mod, msg) do { if((i mod) == 0) { fputs(#msg, stdout); *hit = true; } } while(0) #define through ; i Super extensible!

I'm not sure even hell will take you after doing what you just did. There is no metaphysical consequence great enough save to have experienced the writing of that.

Re: Fizzbuzz, Interviews, And Overthinking

#27
post #25

cases = ( (3, 'Fizz'), (5, 'Buzz'), (7, 'Bazz'), (11, 'Boo'), (13, 'Blip'), ) for i in range(1, 101): out = [] for c in cases: if i % c[0] == 0: out.append(c[1]) if out: print ''.join(out) else: print i Edit: not to detract from the post's point, I think it's valid. Monoids are cool and all but simple counting arguments can take you a long, long, long, way when case analysis fails you.

I agree. Same thing in JS. Also, this is precisely what I thought to do when he started asking about 7 and 11.

    (function fizzbuzz(n, cases) {
      var i = 0;
      while (i++ 
Excuse the terseness, I didn't want to make this post too lengthy, but it's still quite readable, IMO. Array.reduce was designed to solve problems like this.

Re: Fizzbuzz, Interviews, And Overthinking

#28

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.

I'm not sure asking what comes after 0x000F is high-pressure.

Re: Fizzbuzz, Interviews, And Overthinking

#29
For more on monoids, see Brent Yorgey's paper _Monoids: Theme and Variations (Functional Pearl)_ at http://www.cis.upenn.edu/~byorgey/pub/monoid-pearl.pdf> (there's also a video of his talk at the Haskell Symposium at " rel="nofollow">http://www.youtube.com/watch?v=X-8NCkD2vOw>).

Re: Fizzbuzz, Interviews, And Overthinking

#30
post #25

cases = ( (3, 'Fizz'), (5, 'Buzz'), (7, 'Bazz'), (11, 'Boo'), (13, 'Blip'), ) for i in range(1, 101): out = [] for c in cases: if i % c[0] == 0: out.append(c[1]) if out: print ''.join(out) else: print i Edit: not to detract from the post's point, I think it's valid. Monoids are cool and all but simple counting arguments can take you a long, long, long, way when case analysis fails you.

Precisely.

The Ruby solution author quotes as ideal and impressive seems way overblown to me. And I don't buy that ,,it would probably be dismissed as “overly complex” by younger programmers'' because it is exactly what I would consider perfect approach... few years ago. Since then I learned the value of simplicity, and abstractions with adequate flexibility.

That Ruby code exhibits neither.

Post reply on HN