- 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
You may say that I'm a cultist But I'm not the only one I hope someday you'll join us And the world will die as one!
Admin
Along the lines of those conceptual dreamers, I once posted a question to a perl discussion board. I said my boss had directed me that his web site must always appear at the top of every search result page, and would someone send me a perl function to do that. Oh boy did that ignite a fun flamefest.
Admin
That last one bugs me, and not for the usual WTF reasons.
A square root is easy to calculate, if you know anything at all about any of the standard algorithms you should have learned in college.
In fact, the algorithm is a simple game of "guess the number," and if you can't write a "guess the number" algorithm in less than 5 minutes, you should be coding CSS templates for cybersquatters, not developing enterprise software.
If you can't think on your feet enough to answer a question like that, perhaps you really are not the man for the job.
Admin
Since “maths” is the correct idiom in British English, it is arguably more correct than “math”.
Admin
Admin
If you ever, for any reason, find yourself in a situation where you your developers need to do complicated approximations of floating-point numbers, and you value their willingness to turn to a vaguely-recalled Newton's method as their first step, you have failed so completely that I can only hope that you aren't writing code for any crucial features of my life.
Admin
You write that in the language of your choice and then make a CORBA call in your Java.
Admin
The interview question sounds to me like one which would be fine for a job where you're likely to come across some mildly complicated mathematics, and the answer suggests that snoofle would not be comfortable with that.
Not sure why such a successful interview question found its way onto this site, though.
Admin
It's been really sad to read this thread. It gives me the impression that many programmers don't what their library functions actually do, or why the patterns they've memorized work.
Admin
Admin
You're cute. And also an idiot—unless you intentionally misunderstood the point of the interview question.
Come to think of it, you're an idiot either way.
FWIW, I've worked with various SOLAS equipment vendors. If I told you even half of the stuff I've seen, you'd never set foot on an ocean-going ship again.
Admin
Begging your pardon, but free of context there's no reason for the reader to conclude any of that. If you were interviewing to be a code monkey, then clearly a problem-solving question is a waste of yours and the interviewer's time, but the post provided no context. Free of context it's a natural assumption on the part of the reader that a problem-solving question was pertinent to the job.* The archetypal problem solving question asks the interviewee to solve a standard problem ab initio.
*"I went to an interview, and this guy asked me what programming languages I knew! WTF?!"
-beat-
"Wait, did I mention it was for Burger King?"
Admin
It's an interview, not a date. If you need time to think about your response, you can ask for it instead of sitting mutely. Heck, most places will let you go to town on their whiteboard while you figure out a problem.
Admin
Less wrong attempt in Java:
Admin
Unlike taking a square root, my job does involve some manipulation of pdfs - and I generally trust that our pdf library works without needing to know exactly what it does. Except when it fails, in which case, at that point, I look into why it's failing (which requires learning more about its code, and often the pdf specification, which is enormous.)
If I had to work out how to approximate a sqrt by myself, I could probably do that. If I had to tell someone right now how to approximate a sqrt, I wouldn't be able to. I don't think I even ever learned it, but there's a lot of math I have learned and then completely forgot because I haven't used it for anything in like 7 years - I took a semester of Linear Algebra, a semester of MultiVs and a semester of DEs, but I'm not an engineer and I don't do 3d graphics, so what good did that do me after I graduated? (And stuff I learned in high school, other than basic algebra with does come up daily in really any kind of programming, would have been forgotten even longer ago. Sad, but true.)
Admin
How would I calculate the square root of a number during the zombie apocalypse?
Use Newton Raphson's method for finding roots of x**2-n=0 Somewhere I should have some old 8080 assembly handy for that....if fixed point arithmetic is ok.
For the cyclist? Well I wouldn't want the interview to be proceeded by a programming test either... preceded I could live with.
Admin
Has anyone yet mentioned that the interviewer wasn't asking for an exact value? If not, I think we need someone to create thirty math-porn posts repeating the same thing over and over again...
Admin
I view the square root question as a valid problem solving question. No doubt you would encounter problems in actual work where there is no existing valid solution, or at least you can't find one. It's not going to be square root, of course, but the fact remains.
If you were a math wiz, of course, then there are two solutions I know of, one using a specific algorithm I won't describe now, the other involving manipulating exponents and logarithms.
BUT! If you asked, instead, what the tolerance was (only perfect squares have rational results, so no tolerance means no solution), you could use a binary search to find a square root that falls within it. This is the approach I would have used.
Admin
This is actually the point. I've run interviews similar to this, where I ask the candidate to implement a basic library function.
The point is NOT to reinvent the wheel, nor to encourage NIH behavior.
The point is to see how a candidate thinks. How they handle edge cases. How they respond when flaws are pointed out in their code.
I would expect a binary-search solution for anyone without a strong math background (there are algorithms for calculating square root, but I don't expect a candidate to know them offhand). As you've pointed out, there are problems with the first-pass implementation. When you point them out (what about negative numbers? What about numbers between 0 and 1?), you learn a lot about the candidate. How they respond to criticism of their code, how they would approach fixing their code to work, etc.
Again, the point is NOT to implement a production system in an interview. That would be silly, it's an interview. The point is to see how a candidate thinks and adapts.
The candidate was unnecessarily rude an obnoxious. I wouldn't want an arrogant jerk like that.
That said, the Interviewer should have approached it better, and simply said "We'd like you to implement a sqrt() function".
Admin
You're not asked these questions to demonstrate that you know the answer! You're asked them to show that you can think!
Okay, sure, some people don't want to do that kind of work, but don't expect a pat on the back for taking the attitude of "I don't know the answer, therefore the question is stupid". That attitude will get you doing grunt work for the rest of your life.
Admin
For the founders: http://www.escapistmagazine.com/articles/view/comics/critical-miss/9811-Steampunk-Feminists-Vs-Zombies
For the math Nerds (I don't have much time to elaborate):
while (x%2 == 0) {y =* x/2;} while (x%3 == 0) {y =* x/3;} ... continue loops using prime numbers until you are happy... ... repeat until you are at a high enough prime number to be happy. you answer will be y sqrt(x), with x being a prime number. ps... this is what I remember from high school so I may be wrong.
Admin
Step 1: Kill this "cloud" thing Step 2: ? Step 3: Profit
Admin
A bit esoteric, but not an outrageous question.
The interviewer was probably looking for the guy to tell him out to write an iterative program that approaches the value with an error tolerance for when it was reached.
Where X is the original value R' = (X + R / X) /2 Error= X - R'^2 While Error > some limit, let R = R', lather rinse repeat.
I'm sure there are good formulas out there and having access to google would help, but surely someone should be able to figure out a solution by taking convergent averages.
Admin
If I were conducting interviews for a hiring manager I'd immediately fail any candidate who took such an asinine position as you. I've been writing software for 24 years (professionally for 21) and the only time in my life I've ever had to use Newton's method was 23 years ago in a college course.
Knowing Newton's method, fully understanding Newton's method, being able to implement Newton's method... those are all things of limited value and more limited usefulness beyond very specific applications and positions. Even for specific positions working on specific applications which might make use of these concepts I wouldn't rule out a candidate just because he wasn't aware of them. Ideas can be taught and learned.
Admin
Before that question was asked, things were going fine. After that question was asked, the interviewer showed himself to be an idiot, plowing forward with his plan regardless of how stupid it sounded. In other words, pure PHB-ism. Since an interviewer is typically going to become your boss or co-worker, you had better be pretty damn desperate for employment to be subject yourself to months or years of that.
If he had laughed while asking that (telegraphing that he was joking), that would have been cool. But to seriously continue past a point where basic foundations of our civilization would have to fall apart first?
Admin
Feel free to fuck Akismet whenever you like.
Admin
Shouldn't you be able to come up with an algorithm to approximate a square root? That doesn't seem like that egregious of a question to me.
Admin
Admin
The point is, a programmer should be able to figure out how to compute a square root without using references. It was a perfectly legitimate question. He didn't ask, "How would you compute a square root as efficiently as possible," he asked for you to produce some method for computing the square root of a number.
Hell, you could have answered "I'd go in a loop and exhaustively check the square of every possible number and see which one is closest to the true root," and you would have technically solved the problem.
Maybe a lot of people don't know, off-hand, how to compute a square root, but what grade do they teach that in? 5th? 6th? Starting from first principles, i.e. the definition of what a "square root" is, you could have produced a solution by sheer brute force.
If you can't even do that, or can't be bothered to, why should anyone believe you can produce a solution to a novel problem for which there are no references already?
Admin
Math.sqrt() wont give you an exact value either.
If the candidate can't even blurt out binary search would be a really bad sign for me. That's somebody who knows nothing pf algorithms and only know how to combine library calls.
Admin
I disagree. Taking resources away from programmers for trivial tasks is a serious insult to the programmer if they've been writing software long enough. Also, interviews are two-way streets: You are evaluating them as much as they are evaluating you.
For programmers who have been writing software for more than 10 years, find a different avenue of evaluation such as looking at the source code they've published and systems they have built. I don't know who snoofle is, but I like his attitude toward this ridiculous question. Frankly, snoofle should have identified the "I'm going to restrict you to the exact answer I have in front of me" question sooner and walked away sooner. I certainly would. Then again, I would also hand the interviewer my business card and say something like, "Keep this card. When you are tired of hiring people who don't know how to actually write software, call me. I'll train your employees how to select and interview programmers and weed out the garbage from the good ones as well as train you on how to keep good programmers around. Programming jobs are different from most other jobs. My consulting rate is $200/hr, but well worth the cost."
Admin
Regardless, I feel like if you want an interviewee to answer a question with some other answer than "I'd implement this using an algorithm that I know exists on stackoverflow and/or a math textbook, but which I don't have memorized", you should ask a question whose exact answer is unlikely to exist on stackoverflow and/or a math textbook. (Even if it's related to one that is, you can still see how they think.)
Admin
Admin
Depending on the job the square root thing isn't that unreasonable. It is not that it demonstrates a useful piece of code you would normally write, but it demonstrates that you can look at a bit of math and do some numerics if necessary. My own ugly hack without looking at any references certainly wont win any prices, but I think it is a reasonable attempt during an interview:
It's no Newton-Rhapson, but I suspect it will work.
Admin
Admin
Hehe, I somehow failed to see the number of comments, so I am way late. Also one of the mistakes I make above has already been pointed out in an earlier try. You live and learn. But the more I look at it the better I like this interview question, just within the realm of things one can do on the fly, while being almost guaranteed to make some mistakes that one can then discuss (letting the interviewer see that you don't get rattled by such things).
Admin
To all who think I was rude/arrogant/whatever:
You weren't there and didn't hear this jerk and his condescending attitude. Yet you've made lots of assumptions about mine. Fascinating.
FWIW: I happen to be one of those folks who sometimes hears something and has a brain-software-glitch and gets flustered. I usually don't think quickly on my feet, so if thrown a question on something I don't happen to know, it takes me few minutes to reset. As I said above, I figured it out in a few minutes afterward.
For those of you who obviously missed it: I walked out because the guy was a jerk, not because of the question.
Admin
The sqrt() question is no worse than any of the "How Would You Move Mount Fuji?" type questions (which Microsoft is famous for featuring in their interviews). In this case, do you understand enough algebra & algorithms to put together a simple sensible function to solve a typical (albeit atypically-limited) problem?
Not a WTF. His response of walking out, however, was.
Admin
The thing with the square root question is that it filters out above a certain level of competence.
Obviously it filters out anyone without the wit to even try successive approximation. But it also filters out those who know just enough about numerical programming to know that rolling your own numerical algorithms is a really bad idea, not because of efficiency but because of the vagaries of floating point numbers.
If you want sqrt for any scientific purpose, you really need to know what it does with the last digits of precision. You want stable behavior - you want the last sig fig to increment at the right rate relative to the argument. Successive approximation will not give you that stable behavior.
If I were desperate enough for the job, I'd have proceeded beyond that point to ask the interviewer why I needed a square root, try to find out if they actually cared about square roots or if it was just Interview 2.0 crap. Only once I was satisfied that the interviewer would be comfortable with any old square root would I do successive approximation (and my first approximation would come from "shift right until it's 1, then shift left half as many times").
Admin
The correct answer to the Square root question is obviously:
How does having me re-implement standard library functions bring in revenue to this company?
You god damn geekass bastards.
Admin
Admin
Admin
Yep I agree. If not having access to technical books or the internet is a common occurrence here than I probably won't be very good at developing software for you. Perhaps you should remove calculators and computers from your accounting department too.
Admin
Windows 8 is full of messages like "slide your finger across the screen" even if you're using a desktop, not a tablet.
From what I've seen in this business, I can almost guarantee that is the quality work of a CS grad who is great at reimplementing basic math functions on the whiteboard during interviews.
For some types of programming jobs, you don't even need to know what a square root is, much less how to calculate one.
Admin
Then shit got real: What if there were no NUMBERS!?!?!
"First I'd create a number wheel function that could instantly calculate the square root of a given number. Then I would throw away that wheel and create a new wheel that does the exact same thing. Repeat for each project."
Do you have any questions for us: "How would you compensate me for the work I do here?.... Yeah, but what if there were no checks?....What if there were no banks?....what if money hadn't been invented? Sorry, I'm not convinced you are prepared to pay me in a timely manner."
Admin
That is what the article, as posted, describes. Whether the description in the article has any discernible relation to any real interview you or someone else has been in, is sort of beside the point.
When we hire developers, we expect them to be able to solve novel problems that are orders of magnitude more complex than approximating a square root. We also expect that they will need orders of magnitude more time than there's available in an interview to do so, however. So in order to get some kind of handle on how they'll handle actual problems, we ask them to solve some toy problems that (by experience) can usually be solved within the available time.
Good toy problems tend to be ones that have prepackaged solutions readily available, but it's not the solution the interviewer wants -- it's how the candidate constructs solutions.
A candidate who deliberately refuses to demonstrate his solution-construction skills during the interview is not one we'd want to hire.
Admin
Um, he was being judged on his prima donna attitude, his walking out on the interview, and his refusal to take a test. Nobody was judging him for his ability to find the place. In fact, he did find the place, he just left to never return. And the writer of the story noted how he understood why he looked lost.
Admin
I see on your resume that you have 6 years experience designing data structures. Before we get into that, could you recite the capital cities of New York, Maryland, and Vermont? Because I'm sure they talked about that one day in third grade.
No fair using the Internet. Or a map.
Anyway, if during an interview you're asked to code a math function, and that isn't the skill you're interested in marketing, it makes perfect sense to move along... either to the next question, or if they continue in the same vein, to the next job.
Admin
I'll second Nagesh's comment.
The description sounds like a perfectly normal interview, with a little normal confusion over the point of the question. The question itself represents the essence of the job: not everything you'll be required to develop has a cookbook solution ready for you to just look up, you'll have to conjure up your own solutions (imperfect but sufficient as they may be).
Yup, sometimes I'll glitch and get flustered too. Glitching and flustering on something which is perfectly normal for the job ("here's a simple but unsolved problem, go solve it") isn't a good sign; insofar as I've been known to do so at inopportune times is my problem, not the questioner's.
'tis good to develop the social skill of tactfully saying "your question is valid and I'm capable of answering it, but I'm suffering a brain fart right now - how 'bout we come back to this one." If you'd just redirected the discussion for a few minutes, you'd have given the answer. I had a notable case when interviewing at Microsoft years ago: given a comparable question and comparable "brain-software-glitch", I told the interviewer "I know I'm completely missing a simple solution that you're looking for, but I'm just gonna plow ahead with a line of reasoning and let's see where I end up." (Didn't get the job, but did seem in line as a final contender.) In another interview, I knew they'd pull the "write code on a whiteboard" line, so I brought a notebook computer, and explained "writing code on a whiteboard sucks and so does writing code while someone stares at me, so I'll just write it on this computer while you go ahead and ask me other questions and I multi-task". (Got an offer, but got a better offer elsewhere.) Learned to do those after completely blowing several otherwise successful interviews due to mental misfires.
The article says nothing about the guy being a jerk. The guy who walked out in response to a representative question typical of the work, well...
Admin
Heh yeah, I was pretty sure there was some glaring problem with it, but I also did try to come up with it as fast as possible.