I Think I’m Crazy!

February 23, 2018

In a recent exercise I wrote about a shell script I am writing at work. Development of the shell script continues, as I work my way through the various requirements of the script. At one point, I decided to use Awk to process a piece of the task, and I had to look something up in the Awk manual, and while I was there I noticed that Gawk has a -M option to use gmp for the arithmetic, giving Awk a big-integer capability. So it occurred to me: awk big integers … prime numbers … awk big integers … prime numbers … and so a project was born.

I decided to write a prime number generator in Awk, based on this previous exercise. Never mind that Awk doesn’t provide iterators, I ought to be able to figure this out. And I did; the result is on the next page. For the record, it works. But it’s horribly slow; generating the 78498 primes less than a million takes about four-and-a-half seconds, which is at least four seconds too long. Am I crazy?

Your task is to tell us about something crazy you have done, writing a program in a language that doesn’t provide what you need, either because you were forced to do so by circumstances or because you wanted to be crazy, as I did. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.


Pages: 1 2

2 Responses to “I Think I’m Crazy!”

  1. Zack said

    Back in the pre-Julia era, when I was still a student, I created an encryption system using Quick Basic (QB). It was embarrassingly slow (though part of it was due to the computing power of the time). The algorithm was sound but it would take forever to run on a large file.

    Also, a few years later, still in the pre-Julia era, I created a new statistical framework using MATLAB. It worked well, but only for data up to 500 data points or so, making it quite impractical.

    I wouldn’t say that I was crazy to try out these things, but I was definitely ignorant!

  2. Sandy Roman said

    AWK! I am soo happy to see this mentioned here and used. I learned it while working in the Unix environment at a particle accelerator.

    We had dipoles to bend the beam around and of course we had syncrotron radiation from the acceleration required to bend the beam. So we imaged the syncrotron light and put it on a video monitor. The image had information about the beam’s physical bunch length. So I took a background image, then subtracted it from the beam image. Summing all pixels in the vertical gave us an intensity profile. That could be fit to a 5 degree of freedom hyperbola using Cramer’s rule. I did most of the video work in AWK. I might have used it for the fit as well, or done it longhand.

    It was proof of principle and it worked great. I liked AWK, because it is a compact language and you can keep the whole thing in your head. Programs are small and easy to get things done with, great for small projects, small datasets and one line programs.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: