![]() |
|
|
#56 |
|
Account Deleted
"Tim Sorbera"
Aug 2006
San Antonio, TX USA
426710 Posts |
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 |
|
|
|
|
|
#57 |
|
"Ed Hall"
Dec 2009
Adirondack Mtns
23×167 Posts |
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 |
|
|
|
|
|
#58 |
|
"Ed Hall"
Dec 2009
Adirondack Mtns
74018 Posts |
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;
}
Ed Last fiddled with by EdH on 2010-02-04 at 01:58 |
|
|
|
|
|
#59 |
|
Account Deleted
"Tim Sorbera"
Aug 2006
San Antonio, TX USA
102538 Posts |
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 infoCode:
#!/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;
}
|
|
|
|
|
|
#60 |
|
"Ed Hall"
Dec 2009
Adirondack Mtns
23·167 Posts |
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 |
|
|
|
|
|
#61 | ||||
|
Account Deleted
"Tim Sorbera"
Aug 2006
San Antonio, TX USA
17·251 Posts |
Quote:
Quote:
Quote:
Quote:
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). |
||||
|
|
|
|
|
#62 |
|
Account Deleted
"Tim Sorbera"
Aug 2006
San Antonio, TX USA
17·251 Posts |
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;
}
|
|
|
|
|
|
#63 | |
|
"Ed Hall"
Dec 2009
Adirondack Mtns
23·167 Posts |
Quote:
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. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 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. Take Care, Ed |
|
|
|
|
|
|
#64 |
|
Jun 2003
5,087 Posts |
instead of posting the whole program as <code>, please post it as attachment.
|
|
|
|
|
|
#65 | |
|
A Sunny Moo
Aug 2007
USA (GMT-5)
3×2,083 Posts |
Quote:
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. |
|
|
|
|
|
|
#66 | |
|
Just call me Henry
"David"
Sep 2007
Cambridge (GMT/BST)
588710 Posts |
Quote:
|
|
|
|
|
![]() |
| Thread Tools | |
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 |