 Feature Articles
 CodeSOD
 Error'd
 Forums

Other Articles
 Random Article
 Other Series
 Alex's Soapbox
 Announcements
 Best of…
 Best of Email
 Best of the Sidebar
 Bring Your Own Code
 Coded Smorgasbord
 Mandatory Fun Day
 Off Topic
 Representative Line
 News Roundup
 Editor's Soapbox
 Software on the Rocks
 Souvenir Potpourri
 Sponsor Post
 Tales from the Interview
 The Daily WTF: Live
 Virtudyne
Admin
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"
Admin
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.)
Admin
Never ask Mr Spoke about warp drive, ask Scotty for a quote, then expect a miraculous reduction of the delay with enhanced boost power.
Admin
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.
Admin
Admin
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 "YYYYMMDD"'.
Admin
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 domainspecific, so this is just a roughandready way of simulating that in an interview with a simple problem.
Honestly if he couldn't even think of a binary searchtype 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.
Admin
Yeah, this. I mean, I'd probably take a swing at it: "Well, in this future postapocalyptic 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.
Admin
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 twoway 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.
Admin
You have 10 minutes to do it in C with no library functions.
Admin
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.
Admin
If you mean the original problem:
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.
Admin
You used Wikipedia... you cheated. Back in the day (showing my age) we had to do NewtonRaphson 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.
Admin
The time I did it was before wikipedia existed. I just linked there, because that's where one links stuff like that.
Yes, I've done that, too.
Indeed. Square roots are dead simple.
Admin
What if you don't have a compiler?
Admin
Mr. Spoke sounds like someone who can help you find your bicycle in the parking lot.
Admin
Admin
What if you don't have anything?
Admin
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?
Admin
Pull out the old relay based computing machine
Admin
Admin
"Are you sure that's the format you want? YearofWeek, Month, Day of Year? What is this, some weird Financial Julian calendar?"
Admin
Failing to check for d, m or y == 0 for starters...
In my defence I was only given 10 minutes.
Admin
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.
Admin
You had relays?
We had zombies in tanks with hand held switches (Wolfsbane, by Pohl and Kornbluth.)
Admin
FFS Jim Im a computerprogrammer, NOT a front door... bicycle.... parking lot... finder...
Admin
Simple! We use Redstone comparators instead! ... By gosh, Chrome just corrected "Red Stone" into "Redstone". What is this world coming to :interrobang:
Admin
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.
Admin
Right, so, I hope they manage to find Newton, so that they can hire a developer who can solve their problems.
Admin
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.
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.
Admin
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.
Admin
Well good thing you're here to whiteknight for this anonymous tech company with the horrible interview.
Admin
Given the context presented they clearly weren't. Why ask that series of questions for a Java implementation/job instead of, for simplistic example:
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?
Again, as presented  and presuming that's the case  it was the interviewer being stupid.
Admin
Because that's what the work environment is going to be like, so it's a way of seeing how the candidate responds to daytoday [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.
Admin
The interviewer was asking snoofle in an unclear (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 handcoded alternatives to standard library maths functions, instead!
Admin
Umm, isn't Math.pow(x, 0.5) the correct answer there?
Admin
Admin
I've just tested that with
sqrt(4.0)
and it works wonderfully!Admin
Preparation for real world exposure to "we don't really know what we want but we'll know it when we see it" clients?
Admin
I tested it with 0 and that works too! 2/2 test cases pass, Ship It!
Admin
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!
Admin
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.
Admin
Why didn't the interviewer simply come out and say what he wanted, instead of being obtuse?