SQL Challenge vs. Progress 4GL

One of the newsletters I subscribe to is the SQLCentral solutions. A couple of weeks ago they issued the Summer SQL Stumpers 2009, asking for the fastest way to calculate all the primes 1000 or lower. The fastest solution they came up with runs in about 7 seconds, which I thought was terribly slow for the algorithm used (Sieve of Atkins and Aristophanes), and I thought I’d give Progress a try. I came up with the following:


DEFINE TEMP-TABLE ttPrime
FIELD prime AS INTEGER
INDEX prime prime.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE test-val AS INTEGER NO-UNDO.

ETIME(TRUE).

DO i = 1 TO 1000:
CREATE ttPrime.
ASSIGN
ttPrime.prime = i.
END.

DO i = 2 TO 499:
ASSIGN test-val = i * 2.
REPEAT WHILE test-val < = 1000:
FOR FIRST ttPrime
WHERE ttPrime.prime = test-val
EXCLUSIVE-LOCK:
DELETE ttPrime.
END.
ASSIGN test-val = test-val + i.
END.
END.

MESSAGE "Etime" ETIME
VIEW-AS ALERT-BOX INFO.

FOR EACH ttPrime
NO-LOCK:
DISPLAY ttPrime.
END.

On my machine the procedure runs in about 93 milliseconds, and as far as I can see the results are accurate. Progress 4GL FTW!

Top 5 posts for July 2009

Hot on the heels of the first half of 2009 articles, here are the top 5 articles for July 2009:

  1. Ubuntu 8.10 connect to Cisco VPN through vpnc
  2. Nagios – how to determine the name of a service in Windows
  3. Kensington Bluetooth 2.0 under Windows Vista 64-bit
  4. Ubuntu 8.10 installation – GRUB error 18
  5. Blackberry Desktop crashes when reading Outlook calendar

Top 10 articles of first half of 2009

It’s been a while since I posted a top 5. To catch up, I’ll post the top 10 of the first half of 2009:

  1. Ubuntu 8.10 connect to Cisco VPN through vpnc
  2. Kensington Bluetooth 2.0 under Windows Vista 64-bit
  3. Blackberry Desktop crashes when reading Outlook calendar
  4. Ubuntu 8.10 installation – GRUB error 18
  5. Nagios – how to determine the name of a service in Windows
  6. Blackberry not syncing with BES
  7. Cursor keys not working in Ubuntu 8.10 VMWare client
  8. Wow64: How to get the Progress Debugger to run in Vista 64-bit
  9. Firefox equivalent of Internet Explorer’s Every Time I visit the Web page
  10. Cursor keys not working in Ubuntu Terminal Services client