Better HN
topnewbestaskshowjobs
Log inSign up

igoros

24 karma · joined May 25, 2010 (16y ago) · 6 submissions

Submissions

comment 14y ago · link · parent

Nice approach!

It's O(1) to find a candidate solution, but of course it will still be O(N) to verify that the solution really works.

comment 14y ago · link · parent

Here is an O(N) functional solution in C# LINQ: http://pastebin.com/fvdmQBFC

Making the solution "functional" was by far the most time-consuming part of the exercise.

comment 15y ago · link · parent

Answer in rot13:

Gur grpuavdhr vf pnyyrq "qlanzvp cebtenzzvat". Naq, guvf cnegvphyne ceboyrz vf pnyyrq gur "pbva punatr ceboyrz".

comment 15y ago · link · parent

... a little too obvious?

Funny how all those accounts saying nice things about hyperpublic have been created within the last hour.

comment 15y ago · link · parent

I got their answer. Note that there is a wrong "solution" to this problem that looks like it might be right.

It is a very standard problem, by the way. Most books on algorithms will have the solution.

comment 16y ago · link · parent

Any piece of information can be abused.

The article simply explains what branch prediction is and why CPUs implement it. No part of the article advocates that you attempt to optimize your code to exploit branch prediction. In fact, the conclusion of the article is that in the majority of real-world cases, the branch predictor will automatically do the right thing.