- 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
See, my issue with that reasoning is: "why not just ask for what you want?". I don't understand this whole "What if you don't have access to <basic resource>?" charade. If you want to know if I can make a decent stab at solving the problem, ask me to do that. Don't ask "How would you solve this easily-solvable problem under artificially constrained conditions?", just ask "Could you sketch out an algorithm for X?".
Beating around the topic doesn't help anybody. And to be honest, questions like this are useless anyway. For my current job as a web developer, the technical portion of my interview was that I had to write a very simple web application using the technology that they used. In one go, they knew that I was not lying about my skill set, could get a sample of code to judge and could see that I could interpret basic requirements effectively.
Admin
The last time I had to use Newton-Raphson was probably in a Numerical Methods class, well over 25 years ago. I recognized the name when it was mentioned here, but even after a perusal of the Wikipedia article on it, I'm not sure I could remember it well enough to do it in an interview. The last (and only, AFAICR) time I ever actually calculated square roots by hand was in Junior High; I don't even want to think about how long ago that was. I would have been clueless had this been sprung on me cold.
Admin
I wonder if I reply with midpoint subdivision algorithm, will it count as correct?
Certainly it's not the most effective one, but it does give good enough answer by approximation up to X decimal places.
Admin
Some people have no patience for peeling the onion.
The "moving" goal posts actually measure the candidate's knowledge of high-level libraries, and their ability to engage with a novel problem at multiple levels, which a good programmer can do.
At its core, the underlying problem (approximating square roots) can be solved with a real algorithm, as opposed to more ridiculous trick questions like estimating the tidal flow of an Unladen African River.
Is it really true that @snoofle was the one who walked out of this interview?
Admin
Square root: How about the "odd integer method". It was used on a computer I worked on (it was a while ago). It has the feature that it doesn't use multiplication or division.
Bonus points awarded for a nice program that uses this method.
Admin
https://en.wikipedia.org/wiki/Fast_inverse_square_root
Just use this and then run
pow(y, -1);
. Simple.Admin
Yes, that's the
from the article. Very good Ben, have a cookie. Or a cupcake.
Admin
Wait, @snoofle's next choice after "use Math.sqrt" was "use some code from Quake III for a purpose even less reasonable than what it was originally written for"?
Admin
Well, we don't know the purpose from what's written here. It seems that the interviewer never gave any purpose, and personally I think it's unlikely that the interviewer even had a purpose in mind outside the interview. So any approximation works as a first attempt until we find from better evidence that it's not appropriate.
Admin
Not sure how fast inverse square root is going to help you more than the part of it that actually computes a square root.
https://en.wikipedia.org/wiki/Newton%27s_method#Square_root_of_a_number
Admin
Perhaps Microsoft should use it...
Admin
What, you don't use zero-indexed months? :fire_engine:
Admin
I did. It's when the user starts using them as well that causes problems...
Admin
What if you don't have a client?
Admin
What if you don't have a 0.5?
Admin
Interesting point. Is double n = 1.0; double y = Math.pow(x,n/2); good enough? We could play this game all day. Though as Java was specifically requested, the person above who asked "what if you don't have a compiler" was onto something.
Admin
What if you don't have all day?
Admin
...quickly checks for possible NEO collisions in the next hours...
Admin
Admin
When it comes to domain-specific problems, "Ask someone handy" is always preferable to "wild-ass assumptions." That's as far as it should have gone.
I'd have been more patient than notoriously snippy snoofle, but shooting down every idea I have in favor of the one the interviewer's already decided on is going to get me out the door in a hurry. That tells me exactly what working there will be like.
Admin
If it does, it does so in the most annoying and possibly disrespectful way possible. So much so that it likely doesn't even measure that very well, because the interviewee just gets frustrated and tired.
Admin
Whatever happened to snoofle?
Admin
Probably hates Discurse too much to post here. I think he still posts front page articles.
Admin
Easy!
Admin
He had petered out before Discourse. I suspect he got a new job (contract) that just wasn't as much WTF as his old one.
Admin
I think you missed the
Assert(2 == -0.5);
Admin
He said he was leaving WTF Central, I remember. I just assumed he didn't have any more awesome stories for us at his new place, but I figured he'd stick around in the comments.
Admin
Admin
FTFY…
Admin
As the person who mentioned the compiler, I can neither confirm nor deny rumours about what substances I may or may not have been on. s However, I do find that when dealing with Java it helps to be on something
Admin
I have found that my desk chair works quite well. <Looks like i picked the wrong week to stop sniffing chairs.
Admin
Some quick research indicates that on a scale of @dhromed to @lucas, it's more the former than the latter
Admin
I seem to remember him saying that he had a bunch of really outrageous :wtf:s that he was waiting until he was no longer working at WTF, Inc. to post, but I don't remember seeing those. If he's too busy with RL that's one thing, but his new job not being :wtf: is no excuse. Come on, @snoofle, post the good stuff you've been holding out!
Admin
Admin
Wiktionary only lists one for math. It's not the one that is implied by "fast inverse square root", but at least you're wrong about there being two of them.
Admin
It's also the definition used in @grkvlt's post, but there it was used in reference to the square root operation.
The Wiktionary definition is the general case, of which there are two more or less reasonable interpretations in the context of the term "inverse square root" (one, admittedly, somewhat more reasonable than the other).
Really, though, it should have been called "fast reciprocal square root"; then there would be less scope for (creative) confusion.
Admin
When I started programming on ZX Specturm, there was no internet, no books (they were not alloweb into East Europe totalitarian countries), no people around. You have to figure everything out yourself. Some pirated games and programs from the black market and you could start trying. Later, on the first PC, there was still no internet, no books, no sources. And even with that, I was doing computer graphics and trying to do 3D seen in Doom! Today programmers? Just Google it. No Google? Get a book. No book? Impossible! Lazy stupid people, the interviewer was right! You can get good sqrt aproximation just with brute force numeric method, if everything else fails!
Admin
In Soviet Eastern Europe, sqrt() roots you!
... or something. I think I'm Doing It Wrong.
Admin
Did you at least have the Speccy's manual? That was actually a really good document. I wore mine out… :cry:
Admin
Heh.
Admin
Congratulations on a method which adds to the pile of fail. ;)
Here's something which about works.
TRWTF is the highlighter deciding that
float
isn't always a keyword, but thaty
sometimes is…Admin
So, the Newton-Raphson method people were hinting at? It looks elegant enough to work (i.e. simplified for stability and an initial guess which is well enough) but did you do it without looking up anything at all?
Admin
This is like one of those math gotcha algorithms, that some genius mathematician invents and us grubby engineers / handymen just implement without asking too many questions.
I did a binary search algorithm solution, but closed the fiddle before I realized this would turn into a coding epeen contest.
Admin
YMBNH
Admin
It's simplified form of 5 rounds of Newton-Raphson with an initial guess of 1 (which makes the first round spit out
x/2
). It actually works pretty well because this particular sequence converges fast; I think it's several decimal digits per iteration, which is very zippy indeed. I forget where I read that it's a very fast convergence. :smiley:Each round is actually this: xn+1 = xn - (xn2 - y) / (2xn)
That is, using a suitable function with a root at the value you want — in this case x2 - y — you get the next value in the sequence by subtracting the evaluation of the function divided by the evaluation of the first-order differential of the function. This particular form was known to Babylonians, but the generalisation was invented by Newton. Just how well things apply depends on a whole bunch of things: it gets complicated and you can jump down the Wikipedia rabbit hole yourself…
Admin
It's early-ish for us left-ponders...
What in heck does that do?
Looks for coffee..
Filed under: That don't look like no FORTRAN to me, Pilgrim.
Admin
IIRC anyway.
Admin
Other way round, at least in C#
output:
Assign to y, the value of x/=2
Admin
ah, so i missrememered.
Admin
Either way, it's a horrible way to write it, due to exactly this confusion