• lcrawford (disco)

    Re: What's the Square Root of Stupid?

    The interviewer was looking for the candidate to say "I'd roll my own successive approximation square root function".

    Next question: What if there was no "Date" class?

    Desired answer: "I'd roll my own Date class"

  • kupfernigk (disco)

    I don't see the point about the square root one. Early in my career, before Google and the rest, I had to implement a 32 bit square root in assembler on a processor which was new to me and for which, at the time, we had no math libraries. It took me a day but it wasn't that difficult. The answer to the question is, of course, "I'd sit down and figure out how to do it." Assuming I start with a 32 bit integer and no knowledge other than basic arithmetic, it's pretty obvious that if I find the leftmost 1 and right shift by half its position, that's my first guess. I square it, I then just need a means of successive approximation. If I'm asked "what if your processor doesn't have multiply", then I say, OK first of all I work out a multiply. I'm going to need that sometime anyway. Same for divide. If I'm on a desert island as described, I'd better start with a fixed point library and then work out how to build a floating point one. The interviewer might have been an idiot; or he might have been someone who wants to find out if the interviewee is actually an engineer (someone who can think out a solution from scratch) or a technician (someone who can implement a solution given all the building blocks and manuals.)

  • Jerome_Grimbert (disco)

    Never ask Mr Spoke about warp drive, ask Scotty for a quote, then expect a miraculous reduction of the delay with enhanced boost power.

  • PJH (disco) in reply to kupfernigk
    kupfernigk:
    I don't see the point about the square root one.

    If that's the sort of questions you're being asked at an interview (while (true) {what if your previous answer is unavailable?} to stupid extremes) then the implication is that your potential future employment with them is going to be similarly painful; either because that's what you'll actually end up doing, or that's the mindset of management there.

    Either way, it's not a promising indication of a future with that company.

  • JBert (disco) in reply to kupfernigk
    1. The interviewer should then ask for it instead of playing a game of :moving_goal_post: .
    2. He started out with Java which is known to possess such a function, so the goal post is immediately moved out of the field.
  • kupfernigk (disco) in reply to PJH
    PJH:
    Either way, it's not a promising indication of a future with that company.

    To be fair, I have been asked genuinely stupid interview questions which have caused me to terminate an interview. But context is everything. Is the job a straight programmer role or is there actual CS involved? I have known people to be taken on who had full Java certification but who were incapable of the slightest creative thought. The result; huge documented classes without the slightest business logic (that they are being paid for). That question would surely catch one of those people. He'd probably start "Well, first I'm going to create a class called SquareRoot, then I'm going to have some methods for doubles, floats and longs..." and you'd know here was someone who was focussing on the language lessons, not the problems to be solved. City & Guilds in the UK used to have first stage programming exams designed with exactly this in mind, with examples like 'How would you validate a date presented in the format "YYYY-MM-DD"'.

  • PJH (disco) in reply to kupfernigk
    Comment held for moderation.
  • Ben (disco)

    The square root one is pretty bizarre. I do understand the argument for not coming up with arbitrary "puzzle"-type questions, but as an approximation they seem like a reasonable way to test whether somebody can think through a problem.

    Sure, you'll never need to implement square root without looking it up, but there will be things you do need to implement without looking them up because they're domain-specific, so this is just a rough-and-ready way of simulating that in an interview with a simple problem.

    Honestly if he couldn't even think of a binary search-type approach by checking the square (obviously not an efficient algorithm, but the interviewer didn't ask for one), I'd consider that a red flag.

  • Yamikuronue (disco) in reply to Ben

    Yeah, this. I mean, I'd probably take a swing at it: "Well, in this future post-apocalyptic world with no reference material, I'd probably start naive: count up integers until I reach half the target and multiply them by themselves to see if I get the target. If not, I'll probably throw an error. That ought to tide us over until a bookstore can be located or the formula rediscovered by mathematicians."

    Thus demonstrating that I can BS a simple algorithm off the top of my head, that I'm aware it's a naive algorithm and would prefer to use an established one, and that I understand basic loops and simple math.

  • Nutster (disco)

    Sometimes this is what needs to happen. If HR or management are showing themselves to be a bunch of tools, end the interview. Sometimes the company people lose sight of the fact that this is a two-way interview. They have to pass it too and are representing their company, so must put a good impression as well. This one clearly did not pass the interview.

  • boomzilla (disco) in reply to Yamikuronue
    Comment held for moderation.
  • kupfernigk (disco) in reply to PJH
    PJH:
    Well first you convert it to Mayan Long Count, via the Jewish Calender first of course..

    You have 10 minutes to do it in C with no library functions.

  • kupfernigk (disco) in reply to boomzilla
    boomzilla:
    Newton's method! I've actually done this before.

    We had to do this in depth in my day at U, because we had only recently emerged from the era when "computers" were (mostly women) with pencil, paper and Brunswiga machines, and then the era when problems had to be fitted onto the electronic computers of those days. Nowadays numerical methods are pretty niche, not something every aspiring physicist and engineer had to be able to do.

  • PJH (disco) in reply to kupfernigk
    kupfernigk:
    You have 10 minutes to do it in C with no library functions.

    If you mean the original problem:

    int main(int argc, char** argv){
            int m_d[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
            int y=0, m=0, d=0, i=0, j=0;
            if (argc != 2){
                    return -1;
            }
            while (argv[1][i]){
                    if (argv[1][i] == '-'){
                            ++j;
                            ++i;
                            continue;
                    }
                    if (argv[1][i]<'0'|| argv[1][i]>'9'){
                            return -1;
                    }
                    switch (j){
                            case 0:
                                    y*=10;
                                    y+=(argv[1][i]-'0');
                                    break;
                            case 1:
                                    m*=10;
                                    m+=(argv[1][i]-'0');
                                    break;
                            case 2:
                                    d*=10;
                                    d+=(argv[1][i]-'0');
                                    break;
                            default:
                                    return -1;
                    }
                    ++i;
            }
            if (m == 2){
                    int l=0;
                    if ( !(y%4) ){
                            l = 1;
                            if (!(y%100)){
                                    l = 0;
                                    if (!(y%400)){
                                            l = 1;
                                    }
                            }
                    }
                    if (d > (28+l))
                            return -1;
            }
            return d>m_d[m-1];
    }
    
    

    If you mean the Mayan/Jewish stuff - no ta.


    Edited to add the aforementioned checking. Only rough QA performed - I've probably fscked up somewhere.

  • RFoxmich (disco) in reply to boomzilla

    You used Wikipedia... you cheated. Back in the day (showing my age) we had to do Newton-Raphson method root finding by hand...after walking to school through knee deep snow up hill --- both ways.

    If you can get an analytical derivative of f(x) it's pretty easy, and pretty damned intuitive.

  • urkerab (disco) in reply to kupfernigk
    Comment held for moderation.
  • boomzilla (disco) in reply to RFoxmich
    RFoxmich:
    You used Wikipedia... you cheated.

    The time I did it was before wikipedia existed. I just linked there, because that's where one links stuff like that.

    RFoxmich:
    Back in the day (showing my age) we had to do Newton-Raphson method root finding by hand...after walking to school through knee deep snow up hill --- both ways.

    Yes, I've done that, too.

    RFoxmich:
    If you can get an analytical derivative of f(x) it's pretty easy, and pretty damned intuitive.

    Indeed. Square roots are dead simple.

  • PJH (disco) in reply to boomzilla
    Comment held for moderation.
  • boomzilla (disco) in reply to PJH
    Comment held for moderation.
  • Jaloopa (disco) in reply to boomzilla
    boomzilla:
    What if you don't have a slide rule?

    What if you don't have a compiler?

  • operagost (disco) in reply to Jerome_Grimbert

    Mr. Spoke sounds like someone who can help you find your bicycle in the parking lot.

  • Jaloopa (disco) in reply to operagost
    Comment held for moderation.
  • Gaska (disco) in reply to Jaloopa
    Jaloopa:
    What if you don't have a compiler?
    You don't really need a compiler to write in assembler. Better question is, what if you don't have processor?
  • Vault_Dweller (disco) in reply to Gaska

    What if you don't have anything?

  • Dragnslcr (disco) in reply to Gaska
    Gaska:
    Jaloopa:
    What if you don't have a compiler?
    You don't really need a compiler to write in assembler. Better question is, what if you don't have processor?

    This seems like a good place to put in my intended response to the post that said the square root question is fine:

    What if you don't have any transistors?

  • Jaloopa (disco) in reply to Dragnslcr

    Pull out the old relay based computing machine

  • Gaska (disco) in reply to Vault_Dweller
    Vault_Dweller:
    What if you don't have anything?
    Then there's no problem!
  • hiromasaki (disco) in reply to kupfernigk
    kupfernigk:
    How would you validate a date presented in the format "YYYY-MM-DD"

    "Are you sure that's the format you want? Year-of-Week, Month, Day of Year? What is this, some weird Financial Julian calendar?"

  • PJH (disco) in reply to PJH
    PJH:
    Only rough QA performed - I've probably fscked up somewhere

    Failing to check for d, m or y == 0 for starters...

    In my defence I was only given 10 minutes.

  • kupfernigk (disco) in reply to urkerab
    urkerab:
    There's a square root algorithm that uses no multiplication or division (except by 2, so it's a shift)

    I should have remembered that, because that's how I did it (on an RCA 1802...)- I also had to implement multiply and divide. There was supposed to be a library...which in the end never materialised. Multiply and divide on an 1802 was groaning slow but the nature of the embedded application was such that they were only needed every 5 minutes.

  • kupfernigk (disco) in reply to Jaloopa
    Jaloopa:
    Pull out the old relay based computing machine

    You had relays?

    We had zombies in tanks with hand held switches (Wolfsbane, by Pohl and Kornbluth.)

  • Mats_Svensson (disco)

    FFS Jim Im a computer-programmer, NOT a front door... bicycle.... parking lot... finder...

  • Tsaukpaetra (disco) in reply to Dragnslcr

    Simple! We use Redstone comparators instead! ... By gosh, Chrome just corrected "Red Stone" into "Redstone". What is this world coming to :interrobang:

  • Samuel_Schoenberg (disco) in reply to PJH

    The Interviewer was clearly asking for him to come up with a square root implementation on his own. If the interviewee was either too stupid to realize what he was being asked, or too obstinate to actually answer the question that was asked, then that company dodged a bullet.

  • boomzilla (disco) in reply to Samuel_Schoenberg
    Comment held for moderation.
  • Magus (disco) in reply to Samuel_Schoenberg

    Right, so, I hope they manage to find Newton, so that they can hire a developer who can solve their problems.

  • Samuel_Schoenberg (disco) in reply to Magus

    The interviewer didn't say that he had to use an algorithm as efficient as Newton's method.

    It's really not that hard to come up with a rough solution to approximate a square root, especially if you don't care about efficiency.

    here's an example. It doesn't cover all of the edge cases, but for the sake of an interview question it should be able to communicate the basic concept.

    float sqrt(num)
    {
        for(float i = 1; i<num; i+=0.01)
            {
                if(i*i > num)
                    return i;
            }
        //throw an exception
    }
    

    If you have a degree in CS you should at least be able to do it with bisection, If you have some experience, you should probably know to handle special cases such as num < 1.
    It doesn't require a genius to figure out.

  • Samuel_Schoenberg (disco) in reply to Magus

    And the bigger problem with snoofle is didn't even understand what he was being asked, and judging by the thread posted last time this was uploaded, he still doesn't understand.

    It's one thing to not be able to come up with a solution. It does require you to think in a way that typical math classes don't force you to think in. But to refuse to attempt a solution is just ridiculous.

  • blakeyrat (disco) in reply to Samuel_Schoenberg

    Well good thing you're here to white-knight for this anonymous tech company with the horrible interview.

  • PJH (disco) in reply to Samuel_Schoenberg
    Samuel_Schoenberg:
    The Interviewer was clearly asking for him to come up with a square root implementation on his own.

    Given the context presented they clearly weren't. Why ask that series of questions for a Java implementation/job instead of, for simplistic example:

    Presuming you have no access to research materials and no libraries that could do it natively, how would you naively implement a function to calculate the square root of a number?

    Why go all round the houses trying to elicit what the questioner wants, instead of - as we'd all like in our jobs - a CLEAR SPECIFICATION instead of playing 20 questions with the client?

    Samuel_Schoenberg:
    If the interviewee was either too stupid to realize...

    Again, as presented - and presuming that's the case - it was the interviewer being stupid.

  • DCRoss (disco) in reply to PJH
    PJH:
    Why go all round the houses trying to elicit what the questioner wants, instead of - as we'd all like in our jobs - a CLEAR SPECIFICATION instead of playing 20 questions with the client?

    Because that's what the work environment is going to be like, so it's a way of seeing how the candidate responds to day-to-day [s]idiocy[/s] excellence.

    It looks like he chose the correct answer.

    There are a few things you need to remember about interviews. Part of it is for the interviewer to size up a potential coworker. Part is for the interviewee to do the same. And sometimes it's all about the interviewer making sure that nobody ever accepts a job with a horrible company while still providing plausible deniability.

  • grkvlt (disco) in reply to Samuel_Schoenberg

    The interviewer was asking snoofle in an un-clear (obfuscated, roundabout) way to come up with a square root impl. Maybe if he had just asked, then we would have a story about all the WTFs generated by hand-coded alternatives to standard library maths functions, instead!

  • byteflush (disco)
    Interviewer: How would you calculate a square root (java)? Me: Math.sqrt(double) I: What if there were no square root function?

    Umm, isn't Math.pow(x, 0.5) the correct answer there?

  • FullPointerException (disco)
    float sqrt(num)
    {
        // I am bad at math.
        return num / 2.0;
    }
    
  • dkf (disco) in reply to FullPointerException

    I've just tested that with sqrt(4.0) and it works wonderfully!

  • kupfernigk (disco) in reply to PJH
    PJH:
    Why go all round the houses trying to elicit what the questioner wants, instead of - as we'd all like in our jobs - a CLEAR SPECIFICATION instead of playing 20 questions with the client?

    Preparation for real world exposure to "we don't really know what we want but we'll know it when we see it" clients?

  • Protoman (disco) in reply to dkf
    dkf:
    I've just tested that with sqrt(4.0) and it works wonderfully!

    I tested it with 0 and that works too! 2/2 test cases pass, Ship It!

  • Jonathan_Harston (disco)

    If it's integer square root when I needed to knock one up in assembler years ago I remembered noticing that squares increase by increasing odd numbers, so as a first attack I progressively subtracted increasing odd numbers until less than zero. That gives the integer root. (eg 10 -1 =>9 -3 =>6 -5 => 1 -7 => underflow, 3 subtractions, sqr(10)=3 remainder 1) 6502, z80 and pdp11 versions on my website!

  • s73v3r (disco) in reply to kupfernigk

    If there was actual CS involved, then why didn't the interviewer simply ask the candidate to create a square root algorithm? The constant and ludicrous "What ifs" don't do anything.

  • s73v3r (disco) in reply to Samuel_Schoenberg

    Why didn't the interviewer simply come out and say what he wanted, instead of being obtuse?

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

Log In or post as a guest

Replying to comment #:

« Return to Article