Prime directive

I was quite excited at the prospect that 2011 might be a prime number. I happened to be at my computer, but not on the internet, so I wrote a little computer program to run through the factors of 2011. If a number has no factors other than itself and 1, then it is prime.

Sure enough, my program told me that 2011 is indeed a prime year. Yay!

Of course the moment I got on-line, I could just Google it, using 2011 and prime as the search words. Sure enough, 2011 pops up on the very first hit (Wikipedia’s list of the first 1000 prime numbers).

The program was very simple (it took maybe 30 seconds to write), but I find it sad that I can’t easily share my joy of discovery, since unless you already know Java, the code I wrote will look to you like gobbledygook:

    for (int i = 1 ; i <= 2011 ; i++)        if (2011 % i == 0)            System.out.println(i);

If I translate this into a friendlier looking programming language, it might look like this:

    for every I from 1 through 2011
       if 2011 mod I is 0
          print I

That’s almost ok, except that people who don’t already know programming will get stuck at that second line. So let’s replace it with something even friendlier:

    for every I from 1 through 2011
       if 2011 is divisible by I
          print I

Ah, that’s more like it! Meanwhile, if you’re a more advanced programmer, you can peek to see how the computer is told what “is divisible by” means, again in this friendly computer language:

    A is divisible by B means
       the remainder of A divided by B is 0

Now we have something that anybody reading this blog can understand. And in my mind that was actually the program I wrote — except that as I typed the program, I automatically changed it into Java programming, sort of the way a pianist might transpose music from one key to another.

Maybe it would be a good idea to make it very easy to create these sorts of conversational programming Mad Libs (such as: “for every — from — to — ” or “the remainder of — divided by — “). Then it would be easy to write a program that anybody at all could read (or maybe even write), but which would still run on a computer.

Maybe we should hurry up and do that, while it’s still a prime numbered year. 🙂

One Response to “Prime directive”

  1. Andras says:

    Such a nice and gentle post.

Leave a Reply