• (cs)

    That frist one? All I'm thinking is about how the dreamer will chase the coder around the moons of Nibia... What? There was a nebula involved during that, and that's the cloud.....

  • (cs)

    I'm not taking the Star Trek job unless I get a free trip to TechEd on Risa.

  • coder guy (unregistered)

    It seems to me that anyone who can't even come up with a lame attempt at successive approximation to figure out a square root without running to a reference isn't fit for a programming job.

  • vwiggins (unregistered)

    The second one has made me really sad. I get lost all the time, especially if I'm nervous. If someone judged my ability as a developer based on my inability to learn left from right or find my way around a place I've never been before I'd be horrified.

  • (cs) in reply to coder guy
    coder guy:
    It seems to me that anyone who can't even come up with a lame attempt at successive approximation to figure out a square root without running to a reference isn't fit for a programming job.
    Then again, if you don't have access to the internet, don't have anyone to ask and there's no other source of information around...

    ... then it's most likely the time of the Zombie Apocalypse, in which case I'd ask myself as to why in the seven frozen hells I'd need to calculate the square root of two.

    Some smart guy once said: “I don't need to know everything, I just need to know where to find it, when I need it”

  • (cs) in reply to coder guy
    coder guy:
    It seems to me that anyone who can't even come up with a lame attempt at successive approximation to figure out a square root without running to a reference isn't fit for a programming job.
    Why? The guy wanted an exact value, not an approximation.

    If I asked you to come up with a formula for something you honestly didn't know how to calculate, you might approximate, but you won't get it exact.

  • Rodnas (unregistered)

    M: So, there is no one around. The people that aren't around have not invented the book yet or the internet, but trough some magic occurence there is a computer... I guess would get completely naked run around town, get drunk and destroy random objects. I would certainly not go solve some stupid programming problem

  • Dim (unregistered)

    square root.

    Asking someone to solve a problem using the most creative,original or complicated solution is clearly the best way to hire programmers who will create the worst thing possible to solve everyday problems.

    Leaving the interview is clearly the best approach to that kind of question, your clearly don't want to work with people who answer "correctly"

  • Niels (unregistered)

    An iterative approximation for a square root shouldn't be hard to come up with.

    private static double EPSILON = 0.00001;
    public static double sqrt(double x)
    {
      if (x <= EPSILON) return 0; // should error
      double lower = 0, upper = x;
      while (upper - lower > EPSILON)
      {
        double guess = (upper - lower) / 2;
        if (guess * guess > x)
          lower = guess;
        else
          upper = guess;
      }
      return lower;
    }
  • myke (unregistered)

    the real wtf is to consider Carmack's formula for solving sqrt.

  • Michael (unregistered)

    I have been in one of those "Square Root of Stupid" before. I once interviewed with a bank, when the interviewer asked: He: So, imagine our data center in London goes down, what are you going to do? Me: We hopefully automatically fall over to NYC. He: What if NYC also goes down? Me: We hopefully automatically fall over to Tokyo. He: What if Tokyo also goes down? Me: I will go to the nearest supermarket, grab all the cans of food and drinks I can get and drive up North as fast as I can.

  • asdbsd (unregistered)

    That last one was awful. Although you don't get to write square root formulas often, in real life not all answers are readily available. Being a programmer means that sometimes there's no site, no person, no book with the answer, and you have to patch something up by yourself. It is this ability which the interviewer obviously wanted to test. Walking away at this point is just stupid.

    I know no formula for square root calculation, but I'd suggest some variation of binary search for instance. Take (a+b)/2, check it's square, if it's bigger than x then a:=(a+b)/2 else b:=(a+b)/2, repeat until you have the required precision. This probably sucks in terms of speed, but hey, at least it works.

  • Matt (unregistered)

    I: What if there were no bookstore?

    I'd ask you as you obviously seem to know all the answers...

    captcha : secundum (but not fristum...)

  • asdbsd (unregistered) in reply to snoofle
    snoofle:
    Why? The guy wanted an exact value, not an approximation.

    If I asked you to come up with a formula for something you honestly didn't know how to calculate, you might approximate, but you won't get it exact.

    Just to remind you, there's no such thing as "exact" with floating point numbers. So they didn't ask him to give "exact" value. They asked to do his best at approximation.

  • (cs) in reply to Niels
    Niels:
    An iterative approximation for a square root shouldn't be hard to come up with.
    private static double EPSILON = 0.00001;
    public static double sqrt(double x)
    {
      if (x <= EPSILON) return 0; // should error
      double lower = 0, upper = x;
      while (upper - lower > EPSILON)
      {
        double guess = (upper - lower) / 2;
        if (guess * guess > x)
          lower = guess;
        else
          upper = guess;
      }
      return lower;
    }
    What if you can't use the multiplication operator to square a number?
  • Andrew (unregistered)
    What if there were no square root function?
    This tells me that I am not working in a language I know, as all of them require sqrt implementations in their libraries. I wouldn't look for an approximation; I'd look for another job.

    It's funny how it's always Carmack's approximation, when in fact it was done by someone else at SGI. I wonder if that guy did it in 640k of RAM?

  • Studley (unregistered) in reply to TheRider

    What if there were no numbers?

  • Anonymous Coward (unregistered) in reply to snoofle
    1. How do you know he wanted an exact value? You left without offering a non-exact solution.

    2. Successive approximation WILL give you an exact value. You just repeat it until it converges. You know when it has converged because either square(x)==y or square(x)<y && square(Math.nextAfter(x))>y .

    3. The problem is that the interviewer didn't portray it very well as a brainteaser and/or mathematical aptitude type question. If he'd started out by asking, "How would you calculate a floating-point square root without using the library function? (or the whole math library, depending on how easy you want to make the problem)", hopefully you wouldn't have given silly answers like, "ask someone".

    Calculating a square root isn't something where you either know it or you don't. If you ask someone the arguments to an API function, they have to either know it, say they don't know, or walk out or whatever. For a square root, there are a large number of solutions of varying degrees of quality. Obviously it is not a hugely relevant question for upgrading a legacy system, but neither is asking how many golf balls would fill the Washington Monument or something. Giving up a feasible problem without attempting it is not going to help your job prospects.

  • Ron Moses (unregistered)

    ...although I do agree with the guy's assessment of THE CLOUD. Pure marketing cr*p.

    This morning I commuted to work on this new thing called THE GRID. It's a nationwide network of interconnected asphalt lanes - it really is the future of personal and commercial transportation. We have an IPO coming up if you're interested...?

  • Fool (unregistered)

    If I was writing java code and there were no Math.sqrt function i would try to figure out what what jar file is missing, where and then contact IT to fix it.

  • (cs) in reply to asdbsd
    asdbsd:
    That last one was awful. Although you don't get to write square root formulas often, in real life not all answers are readily available. Being a programmer means that sometimes there's no site, no person, no book with the answer, and you have to patch something up by yourself. It is this ability which the interviewer obviously wanted to test. Walking away at this point is just stupid.

    I know no formula for square root calculation, but I'd suggest some variation of binary search for instance. Take (a+b)/2, check it's square, if it's bigger than x then a:=(a+b)/2 else b:=(a+b)/2, repeat until you have the required precision. This probably sucks in terms of speed, but hey, at least it works.

    True, one can approximate, but coming up with an algorithm usually requires a little thought (aka: time), and in an interview, you don't get to take the required time to think things out; you either know it or you don't.

    After that interview, I had time to think about it and I came up with:

    Start squaring numbers from 1 up until you exceed the target value, then back up one, and start incrementing the next smaller digit (1's, then tenths, then hundredths, etc) until you arrive at the required precision. Big deal; I can come up with a crappy algorithm for calculating something for which there are known formulas. I make no claims of being a mathematician. nor would I even want a job where I was responsible for coming up with such formulas.

    A more sensible question might be to ask me: we've got A amount of data, B amount of storage, C transaction rate and D throughput. There is a problem xxx. How would you diagnose this? What are the likely causes and possible solutions?

    That tells the interviewer how I think in terms of things pertinent to the job.

  • (cs) in reply to Studley
    Studley:
    What if there were no numbers?

    That's easy!

    function sqrt() { return NaN; }
  • Chris P. Peterson (unregistered) in reply to snoofle

    There is no way the guy wanted an exact answer. He was trying to see the candidate's thought process when the answer was not available. The interviewer could've done a better job at asking the question and the candidate should've done a better job at realizing what was being asked and made an attempt.

  • John (unregistered) in reply to snoofle
    snoofle:
    ... The guy wanted an exact value, not an approximation. If I asked you to come up with a formula for something you honestly didn't know how to calculate, you might approximate, but you won't get it exact.

    Hey, where can I get a computer like yours, that can represent sqrt(2) exactly? I could really use a computer with infinite-precision reals.

  • The REAL WTF (unregistered) in reply to snoofle
    snoofle:
    coder guy:
    It seems to me that anyone who can't even come up with a lame attempt at successive approximation to figure out a square root without running to a reference isn't fit for a programming job.
    Why? The guy wanted an exact value, not an approximation.

    If I asked you to come up with a formula for something you honestly didn't know how to calculate, you might approximate, but you won't get it exact.

    Without commenting on the value of the question for the interview, the above is simply wrong, at least for square root. Your approximation function should either find the exact value (what's the square root of 25?) or there IS no exact value (what's the square root of 2?) and it should be able to calculate it to any desired precision.
  • Anonymous Coward (unregistered) in reply to snoofle
    snoofle:
    That tells the interviewer how I think in terms of things pertinent to the job.
    Do you walk out of interviews whenever posed any problem to solve that's not directly pertinent to your job?
  • Anoldhacker (unregistered) in reply to Niels
    Niels:
    An iterative approximation for a square root shouldn't be hard to come up with.
    private static double EPSILON = 0.00001;
    public static double sqrt(double x)
    {
      if (x <= EPSILON) return 0; // should error
      double lower = 0, upper = x;
      while (upper - lower > EPSILON)
      {
        double guess = (upper - lower) / 2;
        if (guess * guess > x)
          lower = guess;
        else
          upper = guess;
      }
      return lower;
    }

    This should be considered a good example of precisely why you don't do things like this yourself. The square root of x for small x is much larger than x. The quick return is not needed for non-negative numbers, and if it were, the boundary would be EPSILON * EPSILON. (And no, the square root of -1.0 is NOT even close to 0.0.)

    Yes, my degrees are in mathematics, and I did floating point validation in the '90s. Seriously, don't try this at home, kids.

    (The way that we actually compute floating point square roots is fun. We look up the first several digits for the inverse square root, and then refine it based on polynomials designed to cancel the error term, usually quadratically. Once there is enough precision, you multiply back the original value to get the square root. Yes, you want a real proof that the algorithm works.)

  • AGray (unregistered)

    Snoofle's tale of the interview is probably the most alarming - you apply for a job where apparently the boss expects you to work with zero resources?

    I think Snoofle was right - the employer was totally wasting his time, and did a great job of letting Snoofle know that that was totally the wrong place to be, let alone work. The place next door that lets developers use Internet is a vast improvement!

  • Wide Awake (unregistered)
    we're dreamers, we're entirely conceptual
    Wow! That is one refreshing level of honesty there! I know there are at least a hundred million "business leaders" who should stand up to the same admission, but I never thought any of them actually would!
  • foo (unregistered) in reply to vwiggins
    vwiggins:
    The second one has made me really sad. I get lost all the time, especially if I'm nervous. If someone judged my ability as a developer based on my inability to learn left from right or find my way around a place I've never been before I'd be horrified.
    That's not what happened. The candidate walked away.

    The way I read it, he "pimped up" his CV and was trying to cheat his way through the interview. When he learned there'd be a technical test, he was "not prepared for" cheating it, so he made up a lame excuse to leave.

  • DES (unregistered)

    If I was conducting interviews for a programmer position, I'd immediately fail any candidate who didn't know Newton's method and was unable to come up with it (or a similar successive approximation method) on the spot. It is blindingly obvious, and trivial to implement.

    I'd probably also fail any candidate who didn't, at some point, suggest Math.exp(Math.log(x) / 2). And even if Math.log() isn't available, you can easily compute a rough lower bound of log(x) through successive division, as an initial guess for successive approximation.

    (to those who complained that Newton's method does not give an exact value: where does it say that the interviewer expected an exact value? in any case, with a few exceptions, the floating-point representation of a number will always be an approximation of the actual value.)

    As for Carmack's method: assuming it can be implemented in Java (it can't—not without a lot of contortions), it can easily be derived from first principles if you know basic algebra and the layout of IEEE 754 floating-point numbers. If you don't know the layout, you can easily figure it out by looking at the binary representation of a handful of test values.

    So TRWTF is that the candidate refused to even try to think of an answer, then blamed the interviewer for asking him a question he should have been able to answer but wasn't.

  • emaNrouY-Here (unregistered) in reply to TheRider
    TheRider:
    Niels:
    An iterative approximation for a square root shouldn't be hard to come up with. <SNIP>
    What if you can't use the multiplication operator to square a number?
    And What if you can't use addition?

    (It's a flipping adding machine!!!)

  • Spastic Weasel (unregistered) in reply to snoofle

    Newtons method of iterative approximation would be doable off the top of my head.

  • Sebastian Buchannon (unregistered)

    double Sqrt(double val) { double ret; while (true) { ret = rand() * double.Max; if (double.Equals(ret,val)) return ret; } }

    He never said he wanted it quick

  • snoofle++ (unregistered)

    When you give an amateur programmer a problem, their first impulse is to roll their own solution.

    A pro goes to the language libraries first, the in-house code base second, the world of pre-written solutions third, then asks "has anyone else poured some thought into this problem" before inventing his own wheel.

    Snoofle, I think you bailed 5 seconds early. Based on your answers I would have been offering you a job in the next breath.

  • Helpfull (unregistered)

    If you answer ARM and Intel have built in assembly squareroot instructions the next question will be what if you don't have a processor :)

  • (cs) in reply to snoofle
    snoofle:
    coder guy:
    It seems to me that anyone who can't even come up with a lame attempt at successive approximation to figure out a square root without running to a reference isn't fit for a programming job.
    Why? The guy wanted an exact value, not an approximation.

    If I asked you to come up with a formula for something you honestly didn't know how to calculate, you might approximate, but you won't get it exact.

    Fail. You can't get it exact because square roots are (in all cases except when all the prime factors are to an even power) irrational.

    Granted that you may not be able to come up with: guess, divide your number by that guess, take mean of result with guess, and repeat, IMO it's something that you might be expected to be able to work out.

    Depends on whether your expertise is borne of a lot of experience or a combination of that and the ability to figger things out from scratch. Fair enough, though, it certainly appears that you and your prospective employer would not have been a good match.

  • foo (unregistered) in reply to John
    John:
    snoofle:
    ... The guy wanted an exact value, not an approximation. If I asked you to come up with a formula for something you honestly didn't know how to calculate, you might approximate, but you won't get it exact.

    Hey, where can I get a computer like yours, that can represent sqrt(2) exactly? I could really use a computer with infinite-precision reals.

    Ever heard of computer algebra systems? Representing sqrt(2) exactly isn't hard, yet outputting it in decimal (or any other base) will take ... some time ...

  • foo (unregistered) in reply to emaNrouY-Here
    emaNrouY-Here:
    TheRider:
    Niels:
    An iterative approximation for a square root shouldn't be hard to come up with. <SNIP>
    What if you can't use the multiplication operator to square a number?
    And What if you can't use addition?

    (It's a flipping adding machine!!!)

    If you need anything more than NAND gates, you're not qualified.

  • Joe (unregistered) in reply to DES
    DES:
    I'd probably also fail any candidate who didn't, at some point, suggest Math.exp(Math.log(x) / 2).
    I've been programming for 30 years and I can guarantee you I've never had the slightest use for Math.exp or Math.log. Some programming jobs aren't about math, despite what your Computer Science teacher told you. And I'm talking real code, not drag-and-drop crap.

    Hell, half the stuff I see CS grads crank out barely works. But I suppose it's mathematically sound, so there's that.

  • foo (unregistered) in reply to Sebastian Buchannon
    Sebastian Buchannon:
    double Sqrt(double val) { double ret; while (true) { ret = rand() * double.Max; if (double.Equals(ret,val)) return ret; } }

    He never said he wanted it quick

    I know you just forgot to square, but this way it's even more ridiculous. :)

  • Anonymous Coward (unregistered) in reply to snoofle++
    snoofle++:
    When you give an amateur programmer a problem, their first impulse is to roll their own solution.

    A pro goes to the language libraries first, the in-house code base second, the world of pre-written solutions third, then asks "has anyone else poured some thought into this problem" before inventing his own wheel.

    Snoofle, I think you bailed 5 seconds early. Based on your answers I would have been offering you a job in the next breath.

    I think it was poorly posed, but it's a legitimate question. If I started off the way snoofle's interviewer did, after the "Google" response I would have said something like: "Of course, we would never want a programmer to try to implement their own square root. However, as an interview puzzle, I'd like to know how you'd calculate a square root without the library." Hopefully that would rule out answers like, "buy a book".

  • Zecc (unregistered) in reply to John
    John:
    snoofle:
    ... The guy wanted an exact value, not an approximation. If I asked you to come up with a formula for something you honestly didn't know how to calculate, you might approximate, but you won't get it exact.

    Hey, where can I get a computer like yours, that can represent sqrt(2) exactly? I could really use a computer with infinite-precision reals.

    I'm no expert, but I believe Mathematica can probably represent the exact value of 2, even if "only" symbolically.

  • robert (unregistered) in reply to Anonymous Coward

    [quote user="Anonymous Coward"]1. How do you know he wanted an exact value? You left without offering a non-exact solution.

    1. Successive approximation WILL give you an exact value.

    That's impossible. Most square root functions return an irrational number, i.e.: their digits repeat endlessly without a recurring pattern. There is no representation for the number in a digit-based system.

  • onitake (unregistered)

    I remember our math teacher showing us what Wikipedia calls Digit-by-digit calculation, just for the fun of it. But I totally forgot how it went, so I probably would have failed that interview too.

  • (cs)

    If you want a clever programmer that's exactly what you're going to get. Why use the built-in square root function when you can create your own version that somehow only works 50% of the time? Any way, I would just pre-compute trillions of square roots.

  • Schmitter (unregistered)

    The square root issue is easy. Just convert the whole system to HTML5, put it on network 3.0 (the cloud) where every number automatically shows it square root next to it. 9(3)

    P.S. Why can't I copy/paste the CAPTCHA?

  • (cs) in reply to coder guy

    Anyone who comes up with a lame attempt at approximation to figure out a square root without checking a reference, and puts that code in production with the obvious zombie apocolypse going on, isn't fit for a programming job.

  • Jeff (unregistered)

    Me: How does my ability to pontificate about unrealistic problems in an artificially constrained setting under unusual pressure relate to the projects for which you are hiring?

    Interviewer: I want to see how you think.

    Me: I think I want to work somewhere that is evaluating me for my technical skills, not my game show skills.

  • Graham Dunn (unregistered)
    also, you should really not suggest coding up one of the most advanced data analytics programs in a markup language.

    Unless Apple is now shuffling their Siri searches off to Deep Blue, maybe you should not refer to a wrapper around a voice to text system + search engine as "one of the most advanced data analytics programs"

Leave a comment on “Trouble With Founders, the Lost Candidate, and More”

Log In or post as a guest

Replying to comment #:

« Return to Article