SQL database of primes

September 3rd, 2006

So, I’m generating a SQL database of the first million primes as part of one of those random side tangents that I go off on occasionally. So far I’m up to half a million, and I’ve made several optimizations. I don’t know that my primefinder is actually valid, so I’m including it for you all to critique:

#!/usr/bin/perl

# version: 0.06
$debug = 1;

use DBI;
use Time::Local;

$dbh = DBI->connect(“dbi:mysql:db=primes”,undef,undef) || die “Failed to connect to database”;

$SIG{INT} = \&shutdown;

# first, locate our current position

($current) = $dbh->selectrow_array(“SELECT loc FROM current_location”);

$counter = $current;

#$lastprime = 1;

($lastprime) = $dbh->selectrow_array(“SELECT MAX(prime_number) FROM primes”);

$counter = ($lastprime + 1) if($lastprime > $counter);

while(1) {

if(is_prime($counter)) {
$span = $counter – $lastprime;
$lastprime = $counter;
log_prime($counter, $span);
print “$counter ($span)\n” if($debug);
}

if(! ($counter % 1000)) {
$dbh->do(“UPDATE current_location SET loc = $counter, ts = now()”);
}

$counter++;

}

sub is_prime {

my $number = shift;

# could use much improvement

return 0 if ($number == 1);
return 0 if (($number != 2) && (($number % 2) == 0));

# $maxprime = (int($number / 2) + 1);
$maxprime = (int(sqrt($number)) + 1);

# test against all known primes thus far

$sth = $dbh->prepare(“SELECT prime_number FROM primes WHERE prime_number < $maxprime"); $sth->execute();

while(($pp) = $sth->fetchrow_array()) {
# return 0 if(($number != $pp) && (int($number / $pp)) == ($number / $pp));
return 0 if(($number != $pp) && (($number % $pp) == 0));
}

$sth->finish();

return 1;
}

sub log_prime {
my $number = shift;
my $span = shift;

$dbh->do(“INSERT INTO primes VALUES (NULL,$number,$span,now())”);
}

sub shutdown {

$dbh->do(“UPDATE current_location SET loc = $counter, ts = now()”);
exit(0);
}

Nuts.

September 1st, 2006

Fun little page I found:

http://www-groups.dcs.st-and.ac.uk/~history/HistTopics/Prime_numbers.html

Is it a bad sign that as I get older, I increasingly enjoy things like this?

Grr grr

August 30th, 2006

According to the tail end of http://en.wikipedia.org/wiki/Flash_memory, this article is ‘too technical’. Personally, I think it’s just the right amount of technical – any less technical and it wouldn’t get all of the ideas across. Chances are if you’re looking up flash memory specifically, you’re not scared by technical details. The wikipedia people shouldn’t scare away their more technical authors, IMHO.

Oh well. Nothing’s perfect.

you all will be pleased to know…

August 23rd, 2006

that my backup of my laptop completed with 0 errors.

Boy, do I feel sheepish..

August 22nd, 2006

1) The location to download WinZip 9 is in the FAQ.
2) My laptop seems to be backing up happily. Just to be sure, though, I will try to avoid using it until the backup completes.
3) I have got to do something about my negative attitude.

August 22nd, 2006

This day just gets better and better – I set the date forward on the wintel I’m using temporarily while my laptop is backing up, and it now will not run the WinZip eval version. So, I grab my winzip unlock code that I actually purchased from WinZip, and type it in.. and no dice. Oops, it was for V9.

Go to look for V9 on the web.. and it’s not there, except from people I wouldn’t download from on a bet. Winzip took it down to force people to buy V10, apparently.

Fight the urge to program my fax machine to send them 10,000 faxes saying ‘You Suck’.

Email their tech support. We’ll see what they say.

August 22nd, 2006

I gave up smoking many months ago, but this is one of those times when I really wish I had a cig.

My computer has gotten further along the backup process this time, and hasn’t crashed yet, but I’m chewing on my fingernails hoping that this situation continues. Currently, it’s estimating the job at about 4 hours. I have a somewhat slower but still acceptably fast Wintel desktop that I just fixed a few days ago that I can use instead.. although the focus on the monitor is nowhere near as good as the laptop – I wish that my super-hyper-excessive video card had a DVI port..

I may have to go computer-parts-shopping this afternoon. I’m really unhappy about this – I really didn’t need this today. The question is, do I deal with blurry video that will hurt my eyes, or do I go buy a fix?

LJ feature request

August 22nd, 2006

I really think that LJ should allow Anonymous posters to include a psuedonym. Then I’d have some idea who to thank for finding those matching transformers for me…

Oh, dear…

August 22nd, 2006

Started backup, went for about 10 minutes and then system went down, *hard*. BSOD, kernal panic, yada yada dumping memory have a nice day.

So I don’t know what to think. Drive made similar clicking noise before crash. Upon reboot, system did not come up cleanly or usably. Turned power off at switch, turned back on, system seems normal now, trying another backup. Fingers crossed.

&(#% laptop hard drives..

August 22nd, 2006

Woke up and wandered in to start work for the day, and noted that my laptop’s hard drive was again making the ‘click-click-click’ that so many IDE hard drives make right before they find a new occupation as paperweights.

So, drop everything and configure samba on my 2T system so that I can back up my laptop to it. Start MS backup, cross my fingers that the 2G file limit fix on Samba actually works. (We’ll see, heh) Backup starts.

Ever watch a system back up over a 100 megabit link? At Epoch, we thought 100 megabits was blazingly fast, but guess what – we had systems with <40G disks! I wonder if anyone makes a gigabit PCMCIA card, and if so, what it might set me back.. I'm sure Google could answer that question, but I'm also sure that it won't be somewhere I can get it today. So stick it on the list of things to fix someday and leave backup running in the background.. Gigabit ethernet is pretty cool, though. It starts to make network-attached storage make sense even for moderately demanding tasks. I doubt if you could, you know, edit video over it - and in fact I don't have a clue what the performance is like on my LAN as I've only got one machine with a gig card (the 2T system aforementioned) I did order 3 gig cards today so I can put gig cards in all of my desktops. I'm starting to run low on Ethernet ports again.. might be time to get another switch. (I have a bad habit of just cascading 8 port switches to get wherever I want to go. Actually, it's worked so far...)