mersenneforum.org  

Go Back   mersenneforum.org > Factoring Projects > Aliquot Sequences

Reply
 
Thread Tools
Old 2010-02-03, 22:34   #56
Mini-Geek
Account Deleted
 
Mini-Geek's Avatar
 
"Tim Sorbera"
Aug 2006
San Antonio, TX USA

426710 Posts
Default

I had made that added support for the other format myself and was almost ready to post it when I saw your post. (this was around the time you posted it, not around now) Oh well. They worked the same, and yours has better handling of saying No to the prompt, (I just exited) so I won't bother posting mine.

I'm not getting your issue of it hitting the DB regardless of if alq_###.elf exists. Are you sure the files in question not only exist, but aren't empty?

The only thing I see that it does that's a bit bad, which is in relation to skipping sequences that have already been finished, is that it sends the DB whatever data it has before moving on. I suppose that's an ignorable problem, though. After all, it ruins nothing, and costs the computer almost no CPU time. We aren't exactly expecting for people to keep a ton of long sequences in the alinum.txt file if they're going to be restarting the script often.

I did clean up yours, though. (including, most majorly: shortening and explaining the alinum file format example at the top) Here it is:
Code:
#!/usr/lib/perl
#
# aliperl.pl by Ed Hall, modified by Mini-Geek
# a perl script to automatically advance aliquot sequences
#
# Uses file $alinumfilename which holds the numbers to work with
# and the number of digits to work to for each.  $alinumfilename
# has the following format: (without the #s)
#
# 80 802200 802224
# 82 802300
#
# Which will run sequences 802200 and 802224 to 80 digits, and sequence 802300 to 82 digits.
#
# If the elf file already exists, it will skip downloading it.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

#config
$alinumfilename = 'alinum.txt';
$aliqueitname = 'aliqueit';
$k = 20; # every k lines, submit the lines to the DB and check for terminations
$interval = 3600; # time (in seconds) between db updates when new iteration(s) complete
$prompt = 1; # 1 to prompt that the sequence number and max digits are ok, 0 to just print what it's doing

# retrieve sequence number and digits
if (-s $alinumfilename) { # use alinumfilename values if file exists
   open(INFO, $alinumfilename);
      while (<INFO>){
         $lines = $_;
         chomp($lines);
         @inputvalues = split(/ /, $lines);
         push(@digit, $inputvalues[0]);
         push(@sequence, $inputvalues[1]);
         $inputcount = 2;
         while (length($inputvalues[$inputcount])>0){
            push(@digit, $inputvalues[0]);
            push(@sequence, $inputvalues[$inputcount]);
            $inputcount++;
         }
      }
   close(INFO);
}
else {
   input_values();
}


if ($prompt) {
   $count = 0;
   while ($digit[$count]){
      print "Take aliquot sequence $sequence[$count] to $digit[$count] digits.\n";
      $count++;
   }
 do { # verification of number and digits
   $yn = "";
   print "Run displayed values? (Y/n): ";
   $yn =  <STDIN>;
   chomp ($yn);
   if ($yn ne "y" && $yn ne "Y" && $yn ne ""){
      input_values();
      $yn = 'No';
      } 
 } while ($yn eq "No");
}

$inputcount = -1;

while (length($sequence[$inputcount+1])>0) {
$inputcount++;
$maxdigits = $digit[$inputcount];
chomp($maxdigits);
$number = $sequence[$inputcount];
chomp($number);

#more config
$elffilename = "alq_$number.elf";

print "Taking aliquot sequence $number to $maxdigits digits.\n\n";


print "\nAliqueit auto-script is running!\n";


# initialization
$counter = time; # time used to keep track of when to update db
$primeterm = 0;
$indextosend = 0;
$nomerge = 1;
$composite = $number;
$SIG{INT} = \&exit; # set up Ctrl+C handling (triggers sending the status to DB)


# retrieve last line of sequence from db
if (!(-s $elffilename)) { # if the elf file does not have data in it (nonexistent or empty)
   $wgetwhere = "http://factordb.com/search.php?se=1&aq=$number&action=last&text=Text&raw=1";
   system("wget \"$wgetwhere\" -O $elffilename");
}



# check length of composite from elf file
$compositelen = 0;
$file = "$elffilename";
open(INFO, $file);
while (<INFO>){      
   $lines = $_;
   @lengthtest = split(/ /, $lines);
   if ($compositelen < length($lengthtest[3])){
      $compositelen = length($lengthtest[3]);
   }
}
close(INFO);

# loop until number of digits is reached
while ($compositelen<$maxdigits && $composite>=$number && !$primeterm && $nomerge) {

   print "Starting Aliqueit...\n";
   system("./$aliqueitname -p -q $number");
   
   # retrieve last line of sequence file
   $file = "./$elffilename";
   open(INFO, $file);
   while (<INFO>){
      $indexfull = $_;}
   close(INFO);

   # parse last line
   @innums = split(/ /, $indexfull);
   $index = @innums[1]*1;
   $composite = @innums[3];
   $firstfactor = @innums[5];
   if ($composite == $firstfactor) {
       $primeterm = 1;
   }
   $compositelen = length($composite);
   $elapsed = time;
   if ($index % $k == 0 || ($elapsed - $counter) > $interval) {
      if (update_db()) {
         $nomerge = 0;
      }
      $indextosend = $index+1;
      $counter = time;
   }
}
if ($nomerge) { #if this is 0, then we definitely just submitted the status to the DB, so skip it
   system("./$aliqueitname $number -s $indextosend");
}

if ($composite <= $number){
   print "Sequence merges with $composite!\n\n";}
if ($compositelen >= $maxdigits){
   print "Sequence is at $compositelen digits!\n\n";}
if ($primeterm){
   print "Sequence terminates at prime $composite!\n\n";}
if (!$nomerge){
   print "Sequence merges $mergenote!\n(Go to http://factordb.com/search.php?se=1&aq=$number for more details)\n\n";}
   
}

# end script

sub input_values {
   print "How many digits: ";
   $tempdigit = <STDIN>;
   chomp ($tempdigit);
   @digit = $tempdigit;
   print "\nInput sequence to run: ";
   $tempsequence = <STDIN>;
   chomp ($tempsequence);
   @sequence = $tempsequence;
   return 0;
}

sub update_db {
   system("./$aliqueitname $number -s $indextosend");
   
   $wgetwhere = "http://factordb.com/search.php?se=1&aq=$number&action=last&text=Text";
   system("wget \"$wgetwhere\" -O temp_seq_check");
   return check_for_merge();
}

sub check_for_merge {
   $search = "Merge at n=";
   $file = "temp_seq_check";
   $endmark = '</b>';
   open(DAT, $file) || die("Could not open file!");
   @raw_data=<DAT>;
   close(DAT);
   unlink($file);
   foreach $line (@raw_data)
    {
     chomp($line);
     $location = index($line, $search);
     if ($location != -1) {
       $location2 = index($line, $endmark, $location);
       $sublen = $location2 - $location;
       $mergenote = substr($line, $location + 6, $sublen - 6);
       if (substr($mergenote, -2, 2) eq '=0') {
        $mergenote = $mergenote." (dropped below start)";
       }
       return 1;
     }
    }
   return 0;
}
   
sub exit { 
   system("./$aliqueitname $number -s $indextosend");
   print "Aborting at user's request.";
   exit;
}

Last fiddled with by Mini-Geek on 2010-02-03 at 22:38
Mini-Geek is offline   Reply With Quote
Old 2010-02-03, 23:20   #57
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

23·167 Posts
Default

Hi Mini-Geek,

I picked up your latest and did some indenting so parts make more sense to me.

I am having a merge issue. It appears that I'm getting a statement that the sequence merges with itself. It's probably just a setting/resetting of the $nomerge variable. I think I'm going to change it to 0 where it is now initialized and the alter it to 1 within the next level down.

There are a couple other things I need to look at. I think the db hit I was(am) seeing is possibly the one you mention and I was mistaking it. I think "another" variable can take care of that, but I need to check, because I was pretty sure it deleted a full elf file and replaced it with the last line only, which proved it was working with the correct value, but still not right.

Thanks for all the work. Sorry we sometimes collide. I think we're refining something pretty useful, though. I hope others will find that true.

Take Care,
Ed
EdH is offline   Reply With Quote
Old 2010-02-04, 01:47   #58
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

23×167 Posts
Default

OK, here's a little extra work. Let's hope I didn't carry anything too far. I think it is doing everything we wanted at this point. Let me know if there are any loose ends...anyone...

Code:
#!/usr/lib/perl
#
# aliperl.pl by Ed Hall, modified by Mini-Geek
# a perl script to automatically advance aliquot sequences
#
# Uses file $alinumfilename which holds the numbers to work with
# and the number of digits to work to for each.  $alinumfilename
# has the following format: (without the #s)
#
# 80 802200 802224
# 82 802300
#
# Which will run sequences 802200 and 802224 to 80 digits,
# and sequence 802300 to 82 digits.
#
# If the elf file already exists, it will skip downloading it.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

#config
$alinumfilename = 'alinum.txt';
$aliqueitname = 'aliqueit';
$k = 20; # every k lines, submit the lines to the DB and check for terminations
$interval = 3600; # time (in seconds) between db updates when new iteration(s) complete
$prompt = 1; # 1 to prompt that the sequence number and max digits are ok, 0 to just print what it's doing

# retrieve sequence number and digits
if (-s $alinumfilename) { # use alinumfilename values if file exists
   open(INFO, $alinumfilename);
      while (<INFO>){
         $lines = $_;
         chomp($lines);
         @inputvalues = split(/ /, $lines);
         push(@digit, $inputvalues[0]);
         push(@sequence, $inputvalues[1]);
         $inputcount = 2;
         while (length($inputvalues[$inputcount])>0){
            push(@digit, $inputvalues[0]);
            push(@sequence, $inputvalues[$inputcount]);
            $inputcount++;
         }
      }
   close(INFO);
}
else {
   input_values();
}


if ($prompt) {
 do { # verification of number and digits
   $count = 0;
   while ($digit[$count]){
      print "Take aliquot sequence $sequence[$count] to $digit[$count] digits.\n";
      $count++;
   }
   $yn = "";
   print "Run displayed values? (Y/n): ";
   $yn =  <STDIN>;
   chomp ($yn);
   if ($yn ne "y" && $yn ne "Y" && $yn ne ""){
      input_values();
      $yn = 'No';
      } 
 } while ($yn eq "No");
}

$inputcount = -1;

while (length($sequence[$inputcount+1])>0) {
   $inputcount++;
   $maxdigits = $digit[$inputcount];
   chomp($maxdigits);
   $number = $sequence[$inputcount];
   chomp($number);

   #more config
   $elffilename = "alq_$number.elf";

   print "Taking aliquot sequence $number to $maxdigits digits.\n\n";

   # initialization
   $counter = time; # time used to keep track of when to update db
   $primeterm = 0;
   $indextosend = 0;
   $nomerge = 1;
   $nomerge2 = 0;
   $SIG{INT} = \&exit; # set up Ctrl+C handling (triggers sending the status to DB)

   # retrieve last line of sequence from db
   if (!(-s $elffilename)) { # if the elf file does not have data in it (nonexistent or empty)
      $wgetwhere = "http://factordb.com/search.php?se=1&aq=$number&action=last&text=Text&raw=1";
      system("wget \"$wgetwhere\" -O $elffilename");
   }

   # check length of composite from elf file
   $compositelen = 0;
   $file = "$elffilename";
   open(INFO, $file);
   while (<INFO>){      
      $lines = $_;
      @lengthtest = split(/ /, $lines);
      $composite = $lengthtest[3];
      chomp($composite);
      if ($compositelen < length($lengthtest[3])){
         $compositelen = length($lengthtest[3]);
      }
   }
   close(INFO);

   # loop until number of digits is reached
   while ($compositelen<$maxdigits && $composite>=$number && !$primeterm && $nomerge) {
      print "Aliqueit is ";
      system("./$aliqueitname -p -q $number");
   
      # retrieve last line of sequence file
      $file = "./$elffilename";
      open(INFO, $file);
      while (<INFO>){
         $indexfull = $_;}
      close(INFO);

      # parse last line
      @innums = split(/ /, $indexfull);
      $index = @innums[1]*1;
      $composite = @innums[3];
      $firstfactor = @innums[5];
      if ($composite == $firstfactor) {
         $primeterm = 1;
      }
      $compositelen = length($composite);
      $elapsed = time;
      if ($index % $k == 0 || ($elapsed - $counter) > $interval) {
         if (update_db()) {
            $nomerge = 0;
         }
         $indextosend = $index+1;
         $counter = time;
      }
   }
   if ($nomerge && $nomerge2) { #if $nomerge is 0, then we definitely just submitted the status to the DB, so skip it
      print "nomerge call to aliqueit - ";
      system("./$aliqueitname $number -s $indextosend");
   }
   if (($composite <= $number) && $nomerge){
      print "Sequence merges with $composite!\n\n";}
   if ($compositelen >= $maxdigits){
      print "Sequence is at $compositelen digits!\n\n";}
   if ($primeterm){
      print "Sequence terminates at prime $composite!\n\n";}
   if (!$nomerge){
      print "Sequence merges $mergenote!\n(Go to http://factordb.com/search.php?se=1&aq=$number for more details)\n\n";}
}

# end script

sub input_values {
   print "How many digits: ";
   $tempdigit = <STDIN>;
   chomp ($tempdigit);
   @digit = $tempdigit;
   print "\nInput sequence to run: ";
   $tempsequence = <STDIN>;
   chomp ($tempsequence);
   @sequence = $tempsequence;
   return 0;
}

sub update_db {
   print "Submitting to db - aliqueit is ";
   system("./$aliqueitname $number -s $indextosend");
   
   $wgetwhere = "http://factordb.com/search.php?se=1&aq=$number&action=lastagree&text=Text";
   system("wget \"$wgetwhere\" -O temp_seq_check");
   return check_for_merge();
}

sub check_for_merge {
   $search = "Merge at n=";
   $file = "temp_seq_check";
   $endmark = '</b>';
   open(DAT, $file) || die("Could not open file!");
   @raw_data=<DAT>;
   close(DAT);
   unlink($file);
   foreach $line (@raw_data)
    {
     chomp($line);
     $location = index($line, $search);
     if ($location != -1) {
       $nomerge2 = 1;
       $location2 = index($line, $endmark, $location);
       $sublen = $location2 - $location;
       $mergenote = substr($line, $location + 6, $sublen - 6);
       if (substr($mergenote, -2, 2) eq '=0') {
        $mergenote = $mergenote." (dropped below start)";
       }
       return 1;
     }
    }
   return 0;
}
   
sub exit { 
   system("./$aliqueitname $number -s $indextosend");
   print "Aborting at user's request.";
   exit;
}
Take Care,
Ed

Last fiddled with by EdH on 2010-02-04 at 01:58
EdH is offline   Reply With Quote
Old 2010-02-04, 21:41   #59
Mini-Geek
Account Deleted
 
Mini-Geek's Avatar
 
"Tim Sorbera"
Aug 2006
San Antonio, TX USA

426710 Posts
Default

You went a bit overboard. With the code you posted, when you do normal work that doesn't terminate in any way, at the end where it should submit the last status to the DB, it skips it, because you added && $nomerge2 to that if (since $nomerge and $nomerge2 are never both 1, while you succeeded in keeping it from communicating any time it shouldn't, you also kept it from communicating when it should). Since $nomerge2 isn't used anywhere else, I've removed it completely. (keep in mind with the $nomerge logic that it's backwards from most other things there: a 1 means that no merge has been detected, a 0 means a merge was detected; maybe it should've been vice versa but by now it's probably more trouble than it's worth to switch it)
I think some of your other changes should help with eliminating duplicate messages (e.g. the script detects something and finds it from the DB at the same time) and inaccurate self-merges. Let me know if you still see anything like that with the current version.

Changes:
minor change in opening comment ("without the #s" to "without the # signs")
removed $nomerge2
added nice-looking messages just before all the aliqueit and wget calls (in place of some of yours)
when entering a new single sequence to run, it now asks for the sequence before the digits (I figured that makes more sense and so is easier to use)
for some reason the wget call to check the DB for merges had "action=lastagree" (which seemed, oddly, to act like "=all") instead of "=last" changed that back, since we don't even need the sequence at all there, just the merge info
Code:
#!/usr/lib/perl
#
# aliperl.pl by Ed Hall, modified by Mini-Geek
# a perl script to automatically advance aliquot sequences
#
# Uses file $alinumfilename which holds the numbers to work with
# and the number of digits to work to for each.  $alinumfilename
# has the following format: (without the # signs)
#
# 80 802200 802224
# 82 802300
#
# Which will run sequences 802200 and 802224 to 80 digits,
# and sequence 802300 to 82 digits.
#
# If the elf file already exists, it will skip downloading it.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

#config
$alinumfilename = 'alinum.txt';
$aliqueitname = 'aliqueit';
$k = 20; # every k lines, submit the lines to the DB and check for terminations
$interval = 3600; # time (in seconds) between db updates when new iteration(s) complete
$prompt = 1; # 1 to prompt that the sequence number and max digits are ok, 0 to just print what it's doing

# retrieve sequence number and digits
if (-s $alinumfilename) { # use alinumfilename values if file exists
   open(INFO, $alinumfilename);
      while (<INFO>){
         $lines = $_;
         chomp($lines);
         @inputvalues = split(/ /, $lines);
         push(@digit, $inputvalues[0]);
         push(@sequence, $inputvalues[1]);
         $inputcount = 2;
         while (length($inputvalues[$inputcount])>0){
            push(@digit, $inputvalues[0]);
            push(@sequence, $inputvalues[$inputcount]);
            $inputcount++;
         }
      }
   close(INFO);
}
else {
   input_values();
}


if ($prompt) {
 do { # verification of number and digits
   $count = 0;
   while ($digit[$count]){
      print "Take aliquot sequence $sequence[$count] to $digit[$count] digits.\n";
      $count++;
   }
   $yn = "";
   print "Run displayed values? (Y/n): ";
   $yn =  <STDIN>;
   chomp ($yn);
   if ($yn ne "y" && $yn ne "Y" && $yn ne ""){
      input_values();
      $yn = 'No';
      } 
 } while ($yn eq "No");
}

$inputcount = -1;

while (length($sequence[$inputcount+1])>0) {
   $inputcount++;
   $maxdigits = $digit[$inputcount];
   chomp($maxdigits);
   $number = $sequence[$inputcount];
   chomp($number);

   #more config
   $elffilename = "alq_$number.elf";

   print "Taking aliquot sequence $number to $maxdigits digits.\n\n";

   # initialization
   $counter = time; # time used to keep track of when to update db
   $primeterm = 0;
   $indextosend = 0;
   $nomerge = 1;
   $SIG{INT} = \&exit; # set up Ctrl+C handling (triggers sending the status to DB)

   # retrieve last line of sequence from db
   if (!(-s $elffilename)) { # if the elf file does not have data in it (nonexistent or empty)
      print "\nGetting ELF file from DB\n\n";
      $wgetwhere = "http://factordb.com/search.php?se=1&aq=$number&action=last&text=Text&raw=1";
      system("wget \"$wgetwhere\" -O $elffilename");
   }

   # check length of composite from elf file
   $compositelen = 0;
   $file = "$elffilename";
   open(INFO, $file);
   while (<INFO>){      
      $lines = $_;
      @lengthtest = split(/ /, $lines);
      $composite = $lengthtest[3];
      chomp($composite);
      if ($compositelen < length($lengthtest[3])){
         $compositelen = length($lengthtest[3]);
      }
   }
   close(INFO);

   # loop until number of digits is reached
   while ($compositelen<$maxdigits && $composite>=$number && !$primeterm && $nomerge) {
      print "Aliqueit is ";
      system("./$aliqueitname -p -q $number");
   
      # retrieve last line of sequence file
      $file = "./$elffilename";
      open(INFO, $file);
      while (<INFO>){
         $indexfull = $_;}
      close(INFO);

      # parse last line
      @innums = split(/ /, $indexfull);
      $index = @innums[1]*1;
      $composite = @innums[3];
      $firstfactor = @innums[5];
      if ($composite == $firstfactor) {
         $primeterm = 1;
      }
      $compositelen = length($composite);
      $elapsed = time;
      if ($index % $k == 0 || ($elapsed - $counter) > $interval) {
         if (update_db()) {
            $nomerge = 0;
         }
         $indextosend = $index+1;
         $counter = time;
      }
   }
   if ($nomerge) { #if this is 0, then we definitely just submitted the status to the DB, so skip it
      print "\nSubmitting to DB\nAliqueit is ";
      system("./$aliqueitname $number -s $indextosend");
   }
   if (($composite <= $number) && $nomerge){
      print "Sequence merges with $composite!\n\n";}
   if ($compositelen >= $maxdigits){
      print "Sequence is at $compositelen digits!\n\n";}
   if ($primeterm){
      print "Sequence terminates at prime $composite!\n\n";}
   if (!$nomerge){
      print "Sequence merges $mergenote!\n(Go to http://factordb.com/search.php?se=1&aq=$number for more details)\n\n";}
}

# end script

sub input_values {
   print "\nInput sequence to run: ";
   $tempsequence = <STDIN>;
   chomp ($tempsequence);
   @sequence = $tempsequence;
   print "How many digits: ";
   $tempdigit = <STDIN>;
   chomp ($tempdigit);
   @digit = $tempdigit;
   return 0;
}

sub update_db {
   print "\nSubmitting to DB\nAliqueit is ";
   system("./$aliqueitname $number -s $indextosend");
   
   print "\nChecking DB for merges\n\n";
   $wgetwhere = "http://factordb.com/search.php?se=1&aq=$number&action=last&text=Text";
   system("wget \"$wgetwhere\" -O temp_seq_check");
   return check_for_merge();
}

sub check_for_merge {
   $search = "Merge at n=";
   $file = "temp_seq_check";
   $endmark = '</b>';
   open(DAT, $file) || die("Could not open file!");
   @raw_data=<DAT>;
   close(DAT);
   unlink($file);
   foreach $line (@raw_data)
    {
     chomp($line);
     $location = index($line, $search);
     if ($location != -1) {
       $location2 = index($line, $endmark, $location);
       $sublen = $location2 - $location;
       $mergenote = substr($line, $location + 6, $sublen - 6);
       if (substr($mergenote, -2, 2) eq '=0') {
        $mergenote = $mergenote." (dropped below start)";
       }
       return 1;
     }
    }
   return 0;
}

sub exit { 
   print "\nSubmitting to DB before aborting\nAliqueit is ";
   system("./$aliqueitname $number -s $indextosend");
   print "Aborting at user's request.";
   exit;
}
Mini-Geek is offline   Reply With Quote
Old 2010-02-04, 23:54   #60
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

23·167 Posts
Default

Hi Mini-Geek

Thanks for fixing my overdo. I was understanding the logic, since it was called $nomerge, thus 1 = true for "nomerge." I did however, still have a little trouble tracing through the two-level sub call for the value.

You noticed how I was trying to be "cute" with the calls to aliqueit. They look good now. When I look this over, scrolling backwards through the console output, I find myself searching for a timestamp when aliqueit runs, and there isn't one. Do we want one or is that just more "stuff?"

Should I throw together some text for documentation? If so, should it be appended to the end, up front, or separate? I'm thinking of things like a list of applications needed, etc. Of course, I'm also looking toward my bootable OS project, which will have a bunch more documentation anyway.

How do we address the issue of lack of Internet connection or db response? Or, should we just expect it to be used with Internet/db connectivity?

Should we post a separate thread since this is now not just a Bootable CD/USB project? Or, maybe let it run for a little longer?

Thanks again for all the work.

Take Care,
Ed
EdH is offline   Reply With Quote
Old 2010-02-05, 00:43   #61
Mini-Geek
Account Deleted
 
Mini-Geek's Avatar
 
"Tim Sorbera"
Aug 2006
San Antonio, TX USA

17·251 Posts
Default

Quote:
Originally Posted by EdH View Post
When I look this over, scrolling backwards through the console output, I find myself searching for a timestamp when aliqueit runs, and there isn't one. Do we want one or is that just more "stuff?"
I think that's doable, useful, and not too much extra "stuff".
Quote:
Originally Posted by EdH View Post
Should I throw together some text for documentation? If so, should it be appended to the end, up front, or separate? I'm thinking of things like a list of applications needed, etc. Of course, I'm also looking toward my bootable OS project, which will have a bunch more documentation anyway.
I'm not sure how much documentation is necessary just for this script (e.g. the only applications needed are aliquiet, and all that implies, and wget; and also an Internet connection)...if it's not much longer than the current opening comment, I'd say put it up front, otherwise separate.
Quote:
Originally Posted by EdH View Post
How do we address the issue of lack of Internet connection or db response? Or, should we just expect it to be used with Internet/db connectivity?
I suppose we could make an offline option pretty easily, (it would just skip all the communication; I suppose it'd just exit if you didn't have an ELF file for the given sequence) but I'd say generally we don't need to worry too much about it.
Quote:
Originally Posted by EdH View Post
Should we post a separate thread since this is now not just a Bootable CD/USB project? Or, maybe let it run for a little longer?
This changed topics from "Are there any bootable aliqueit projects?" to "Let's make aliperl!" almost completely within a few posts. Maybe it'd be better to just change this thread's title and make a separate thread for actually making the bootable project.
Plus, a title change is far easier than picking which posts to split out, and makes more sense than doing something like ignoring this thread and making a new one for aliperl (to me anyway).
Mini-Geek is offline   Reply With Quote
Old 2010-02-05, 01:56   #62
Mini-Geek
Account Deleted
 
Mini-Geek's Avatar
 
"Tim Sorbera"
Aug 2006
San Antonio, TX USA

17×251 Posts
Default

Now with timestamps (such that the line is like this, with the local time zone: "[19:51:08] Aliqueit is Reading config file...") and an offline mode.
Code:
#!/usr/lib/perl
#
# aliperl.pl by Ed Hall, modified by Mini-Geek
# a perl script to automatically advance aliquot sequences
#
# Uses file $alinumfilename which holds the numbers to work with
# and the number of digits to work to for each.  $alinumfilename
# has the following format: (without the # signs)
#
# 80 802200 802224
# 82 802300
#
# Which will run sequences 802200 and 802224 to 80 digits,
# and sequence 802300 to 82 digits.
#
# If the elf file already exists, it will skip downloading it.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

#config
$alinumfilename = 'alinum.txt';
$aliqueitname = 'aliqueit';
$k = 20; # every k lines, submit the lines to the DB and check for terminations
$interval = 3600; # time (in seconds) between db updates when new iteration(s) complete
$prompt = 1; # 1 to prompt that the sequence number and max digits are ok, 0 to just print what it's doing
$offline = 0; # 1 to skip all Internet communication

# retrieve sequence number and digits
if (-s $alinumfilename) { # use alinumfilename values if file exists
   open(INFO, $alinumfilename);
      while (<INFO>){
         $lines = $_;
         chomp($lines);
         @inputvalues = split(/ /, $lines);
         push(@digit, $inputvalues[0]);
         push(@sequence, $inputvalues[1]);
         $inputcount = 2;
         while (length($inputvalues[$inputcount])>0){
            push(@digit, $inputvalues[0]);
            push(@sequence, $inputvalues[$inputcount]);
            $inputcount++;
         }
      }
   close(INFO);
}
else {
   input_values();
}


if ($prompt) {
 do { # verification of number and digits
   $count = 0;
   while ($digit[$count]){
      print "Take aliquot sequence $sequence[$count] to $digit[$count] digits.\n";
      $count++;
   }
   $yn = "";
   print "Run displayed values? (Y/n): ";
   $yn =  <STDIN>;
   chomp ($yn);
   if ($yn ne "y" && $yn ne "Y" && $yn ne ""){
      input_values();
      $yn = 'No';
      } 
 } while ($yn eq "No");
}

$inputcount = -1;

while (length($sequence[$inputcount+1])>0) {
   $inputcount++;
   $maxdigits = $digit[$inputcount];
   chomp($maxdigits);
   $number = $sequence[$inputcount];
   chomp($number);

   #more config
   $elffilename = "alq_$number.elf";

   print "Taking aliquot sequence $number to $maxdigits digits.\n\n";

   # initialization
   $counter = time; # time used to keep track of when to update db
   $primeterm = 0;
   $indextosend = 0;
   $nomerge = 1;
   $SIG{INT} = \&exit; # set up Ctrl+C handling (triggers sending the status to DB)

   # retrieve last line of sequence from db
   if (!(-s $elffilename)) { # if the elf file does not have data in it (nonexistent or empty)
      if (!$offline) {
         print "\nGetting ELF file from DB\n\n";
         $wgetwhere = "http://factordb.com/search.php?se=1&aq=$number&action=last&text=Text&raw=1";
         system("wget \"$wgetwhere\" -O $elffilename");
      } else {
         print "\nELF file $elffilename not found; start sequence from $number? (no to exit) (Y/n): ";
         $yn = "";
         $yn =  <STDIN>;
         chomp ($yn);
         if ($yn ne "y" && $yn ne "Y" && $yn ne ""){
            exit;
         } else {
            run_aliqueit();
         }
      }
   }

   # check length of composite from elf file
   $compositelen = 0;
   $file = "$elffilename";
   open(INFO, $file);
   while (<INFO>){      
      $lines = $_;
      @lengthtest = split(/ /, $lines);
      $composite = $lengthtest[3];
      chomp($composite);
      if ($compositelen < length($lengthtest[3])){
         $compositelen = length($lengthtest[3]);
      }
   }
   close(INFO);

   # loop until number of digits is reached
   while ($compositelen<$maxdigits && $composite>=$number && !$primeterm && $nomerge) {
      run_aliqueit();
      
      # retrieve last line of sequence file
      $file = "./$elffilename";
      open(INFO, $file);
      while (<INFO>){
         $indexfull = $_;}
      close(INFO);

      # parse last line
      @innums = split(/ /, $indexfull);
      $index = @innums[1]*1;
      $composite = @innums[3];
      $firstfactor = @innums[5];
      if ($composite == $firstfactor) {
         $primeterm = 1;
      }
      $compositelen = length($composite);
      $elapsed = time;
      if ($index % $k == 0 || ($elapsed - $counter) > $interval) {
         if (update_db()) {
            $nomerge = 0;
         }
         $indextosend = $index+1;
         $counter = time;
       }
   }
   if (!$offline && $nomerge) { #if $nomerge is 0, then we definitely just submitted the status to the DB, so skip it
      print "\nSubmitting to DB\nAliqueit is ";
      system("./$aliqueitname $number -s $indextosend");
   }
   if (($composite <= $number) && $nomerge){
      print "Sequence merges with $composite!\n\n";}
   if ($compositelen >= $maxdigits){
      print "Sequence is at $compositelen digits!\n\n";}
   if ($primeterm){
      print "Sequence terminates at prime $composite!\n\n";}
   if (!$nomerge){
      print "Sequence merges $mergenote!\n(Go to http://factordb.com/search.php?se=1&aq=$number for more details)\n\n";}
}

# end script

sub run_aliqueit {
   ($second, $minute, $hour) = localtime();
   @timedata = localtime(time);
   #print "@timedata[2]:@timedata[1]:@timedata[0]";
   $second = sprintf("%02d", $second);
   $minute = sprintf("%02d", $minute);
   print "[$hour:$minute:$second] Aliqueit is ";
   system("./$aliqueitname -p -q $number");
}

sub input_values {
   print "\nInput sequence to run: ";
   $tempsequence = <STDIN>;
   chomp ($tempsequence);
   @sequence = $tempsequence;
   print "How many digits: ";
   $tempdigit = <STDIN>;
   chomp ($tempdigit);
   @digit = $tempdigit;
   return 0;
}

sub update_db {
 if (!$offline) {
   print "\nSubmitting to DB\nAliqueit is ";
   system("./$aliqueitname $number -s $indextosend");
   
   print "\nChecking DB for merges\n\n";
   $wgetwhere = "http://factordb.com/search.php?se=1&aq=$number&action=last&text=Text";
   system("wget \"$wgetwhere\" -O temp_seq_check");
   return check_for_merge();
 }
}

sub check_for_merge {
   $search = "Merge at n=";
   $file = "temp_seq_check";
   $endmark = '</b>';
   open(DAT, $file) || die("Could not open file!");
   @raw_data=<DAT>;
   close(DAT);
   unlink($file);
   foreach $line (@raw_data)
    {
     chomp($line);
     $location = index($line, $search);
     if ($location != -1) {
       $location2 = index($line, $endmark, $location);
       $sublen = $location2 - $location;
       $mergenote = substr($line, $location + 6, $sublen - 6);
       if (substr($mergenote, -2, 2) eq '=0') {
        $mergenote = $mergenote." (dropped below start)";
       }
       return 1;
     }
    }
   return 0;
}

sub exit { 
   if (!$offline) {
      print "\nSubmitting to DB before aborting\nAliqueit is ";
      system("./$aliqueitname $number -s $indextosend");
   }
   print "Aborting at user's request.";
   exit;
}
Mini-Geek is offline   Reply With Quote
Old 2010-02-05, 03:07   #63
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

23·167 Posts
Default

Quote:
Originally Posted by Mini-Geek View Post
Now with timestamps (such that the line is like this, with the local time zone: "[19:51:08] Aliqueit is Reading config file...") and an offline mode.
Thank you!

How about something like the following for the intro:
Code:
#!/usr/lib/perl
#
# aliperl.pl developed by EdH and Mini-Geek (mersenneforum.org)
# 
# a perl script to automatically advance aliquot sequences by
# communicating with factordb.com (via wget) and running Aliqueit
# (and its associated packages).  For more details and latest version:
#      http://www.mersenneforum.org/showthread.php?t=13008
#
# Uses $alinumfilename to hold the numbers to work with
# and the number of digits to work to for each.  $alinumfilename
# has the following format: (without the # signs)
#
# 80 802200 802224
# 82 802300
#
# Which will run sequences 802200 and 802224 to 80 digits,
# and sequence 802300 to 82 digits.
#
# If the elf file already exists, it will skip downloading it.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
which adds the question, do we need something like this:
Code:
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
# POSSIBILITY OF SUCH DAMAGE.
Changing the title sounds good. Can you accomplish this? As for the original title, no one came forward with anything, but I now have a completely working USB version. I will probably play a bit more with it to see if it is possible to take it back to a CD and see if it is feasible to use it that way. After I see what I can and can't accomplish, I'll put together a "How to" and post it under that subject for anyone that's interested.

Take Care,
Ed
EdH is offline   Reply With Quote
Old 2010-02-05, 03:36   #64
axn
 
axn's Avatar
 
Jun 2003

5,087 Posts
Default

instead of posting the whole program as <code>, please post it as attachment.
axn is offline   Reply With Quote
Old 2010-02-05, 05:22   #65
mdettweiler
A Sunny Moo
 
mdettweiler's Avatar
 
Aug 2007
USA (GMT-5)

3·2,083 Posts
Default

Quote:
Originally Posted by EdH View Post
Code:
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
# POSSIBILITY OF SUCH DAMAGE.
I imagine that the following would suffice:
Code:
Copyright 2010 so-and-so, so-and-so, etc. Use this software at
your own risk; the authors are not responsible for any damage incurred by
its use.
Such simple license agreements are rather common in freeware software; since there's no payment needed for the software, there's not many terms that have to be specified besides the authors not being responsible for any damage incurred.
mdettweiler is offline   Reply With Quote
Old 2010-02-05, 18:20   #66
henryzz
Just call me Henry
 
henryzz's Avatar
 
"David"
Sep 2007
Cambridge (GMT/BST)

7×292 Posts
Default

Quote:
Originally Posted by mdettweiler View Post
I imagine that the following would suffice:
Code:
Copyright 2010 so-and-so, so-and-so, etc. Use this software at
your own risk; the authors are not responsible for any damage incurred by
its use.
Such simple license agreements are rather common in freeware software; since there's no payment needed for the software, there's not many terms that have to be specified besides the authors not being responsible for any damage incurred.
Wouldn't it be easier to just use something like GPL?
henryzz is online now   Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
P-1 discussion kladner GPU to 72 43 2012-01-27 20:43
AliWin.exe discussion EdH Aliquot Sequences 63 2010-11-22 14:03
10,375- LA discussion Raman Cunningham Tables 27 2008-12-04 21:17
P-1 discussion AntonVrba Prime Cullen Prime 5 2007-04-04 04:59
New .dat discussion VJS Prime Sierpinski Project 7 2006-07-25 14:31

All times are UTC. The time now is 23:27.


Fri Aug 6 23:27:23 UTC 2021 up 14 days, 17:56, 1 user, load averages: 3.71, 3.99, 4.02

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.