?

Log in

No account? Create an account
February 14th, 2007 - Adventures in Engineering — LiveJournal
The wanderings of a modern ronin.

Ben Cantrick
  Date: 2007-02-14 18:10
  Subject:   In which we show several pictures of human/automotive drama.
Public
  Mood:schadenfreude
  Tags:  humor, reddit

Several images.Collapse )


http://www.theliberalblogger.com/forum/f3/oops-thread-56-k-warning-certain-pages-85/



Current Music: 12 Stones - Broken
7 Comments | Post A Comment | | Link



Ben Cantrick
  Date: 2007-02-14 22:37
  Subject:   In which Ben is evil to a poor little Haskell interpreter.
Public
  Mood:der uber-nerd
  Music:Type O: Gravitational Constant G = 6.67 x 10^8 Cm^3/Gm Sec^2
  Tags:  haskell, prime numbers, programming

The desktop screenshot. (80k PNG, 1024x768)Collapse )

So I decided I wanted to dork around with Haskell, just for grins. I downloaded WinHugs and started looking at a tutorial.

I got as far as the recursive definition of prime (a function to test if a number is prime or not) before my evil side manifested. You can see the code for this function in the lower-right of the screen shot. It probably isn't obvious to any non-Haskeller, but the algorithm the tutorial gave was:

"A number N is non-prime if there is another number K such that: 2 < K < N, and N is evenly divisible by K." In other words, the approach was to take your number, N, and try and integer divide it by every number from 2 to N-1 and see if any of them divided it evenly!

Now I quite understand this was only for tutorial purposes, and nobody would actually implement a prime test function this way. Still, it was screechingly obvious to me that this algorithm was no AKS primality test. Heck, it wasn't even a Sieve of Eratosthenes! I couldn't resist making the obvious optimization of only checking from 2 up to (N/2). (I know you only strictly need to check up to sqrt(N), but I don't know how to do integer square roots in Haskell yet.) Even so I was pretty sure this thing was going to be dog-slow. Unsure of exactly HOW slow it was going to be on my "mere" 850 MHz Pentium 3, and also unsure of what format Haskell uses internally for integers, I decided to start off with a few random tests.

Geeklarity ensued.Collapse )
7 Comments | Post A Comment | | Link






browse
May 2015