News for hackers. Stuff that matters.
Re:"River" detection in text by mistercow on Saturday February 23, 2013 @12:51AM (#5268718)
I wonder how hard it would be, given the detection algorithm, to fix this automatically. Seems like simulated annealing would be a pretty good fit, where you perturb the word spacing on each iteration and the energy function is the total river length. The fitness landscape is rich enough with good solutions that you should rarely need more than a few iterations to arrive at one.

Still, that's a pretty expensive fitness test, and I wonder if there's a more elegant and efficient approach than Monte Carlo methods.

Re:"River" detection in text by kordless on Saturday February 23, 2013 @01:38AM (#5268794)
Thanks for this. I just spent 30 minutes reading up on calculating pi with a simple Monte Carlo algo. Thinking about doing it d3.js...
Re:"River" detection in text by mistercow on Saturday February 23, 2013 @01:50AM (#5268818)
It's an entertaining exercise, especially when you watch your computer chew away for several minutes before telling you that π is probably somewhere around 3.26.
Re:"River" detection in text by graue on Saturday February 23, 2013 @02:58AM (#5268942)
Huh? You should get as close as 3.14 in less than a second if your random number source is decent.
Re:"River" detection in text by kordless on Saturday February 23, 2013 @11:23AM (#5270164)
I was wondering about this. Evidently the more random, the more accurate. Wacky!
Re:"River" detection in text by mistercow on Saturday February 23, 2013 @03:06AM (#5268954)
Perhaps. I may be misremembering, or may have been using a particularly crappy RNG when I last did it. It was a long time ago.
Re:"River" detection in text by Someone on Saturday February 23, 2013 @04:16AM (#5269091)
How long ago? How much faster is current hardware?

If it was, say, a 4MHz machine, you both could be right.

Re:"River" detection in text by petercooper on Saturday February 23, 2013 @08:36AM (#5269600)
Just for fun, and because I'd never done it before, I just threw together some Ruby to do this: https://gist.github.com/peterc/5019760

It gets to 3.14 within a second, about 30 seconds to 3.1415.. and Ruby is surely doing this in 100x the time C or Java would.

Update: Also did it for JavaScript - https://gist.github.com/peterc/5019804

Re:"River" detection in text by mistercow on Saturday February 23, 2013 @08:17PM (#5272273)
You can optimize that JS code a lot by using the unit circle, limiting yourself to the first quadrant, and using multiplication instead of Math.pow(). Then you can make it branchless using a little bitwise trickery. The result is this: https://gist.github.com/osuushi/5022143 .

OK, so I was going to just do the unit circle thing. Then I got stuck in optimization mode. God I miss performance graphics programming.

Re:"River" detection in text by mistercow on Saturday February 23, 2013 @12:39PM (#5270542)
It would have probably been on an 450 MHz G4, maybe 6-7 years ago, and if I had to guess, I'd say I probably did it in Python.
Re:"River" detection in text by raverbashing on Saturday February 23, 2013 @06:34AM (#5269376)
Calculating Pi with Monte Carlo is equivalent to calculating the Fibonacci series with the recursive formula.

It's a nice example but almost useless in practice.

Re:"River" detection in text by AndreasFrom on Saturday February 23, 2013 @05:36AM (#5269268)
I did it in Clojure once[1]. It's quite fun, I recommend it as well.