Humm,
Looks like Garo (not sure) already made one of these in perl.
#! /usr/bin/perl
use strict;
use warnings;
my $kval;
my $current_n;
my $count;
my @tests;
if ($#ARGV != 3) {
print("Usage: make_worktodo.pl <n_low> <n_high> <B1> <B2>\n");
print("$#ARGV\n");
exit(-1);
}
my $n_low = $ARGV[0];
my $n_high = $ARGV[1];
my $b1 = $ARGV[2];
my $b2 = $ARGV[3];
open(DATFILE, "<sob.dat") or die "Couldn't open dat file\n";
# Remove the first 3 lines
<DATFILE>;
<DATFILE>;
<DATFILE>;
my $line;
while ($line = <DATFILE> ) {
chomp $line;
if ($line =~ /^k=(\d+)/) {
$kval=$1;
$current_n = <DATFILE>;
} else {
$line =~ m/\+(\d+)/;
$current_n += $1;
}
if (($current_n < $n_high) and ($current_n >= $n_low)){
push @tests,{ 'k' => $kval, 'n' => $current_n };
$count++;
}
}
close(DATFILE);
print "$count numbers with $n_low <= n < $n_high\n";
my $removed = 0;
my $factor_k;
my $factor_n;
my $test;
print "Searching for known factors in results.txt...\n";
open(RESULTSFILE,"<results.txt") or die "Failed to open factor file!\n";
<RESULTSFILE>;
while ($line = <RESULTSFILE> ) {
next unless $line =~ m/^\d+\s+(\d+)\s+(\d+)/;
$factor_k = $1;
$factor_n = $2;
next if (($factor_n >= $n_high) or ($factor_n < $n_low));
for(my $i = 0; $i < $count; $i++) {
next unless (defined($tests[$i]));
if (($tests[$i]{'k'} == $factor_k) and ($tests[$i]{'n'} == $factor_n)) {
print "Removed $factor_k * 2^ $factor_n +1";
delete $tests[$i];
$count--;
$removed++;
$removed++;
}
}
}
close(RESULTSFILE);
print "Removed $removed numbers using the factor file\n";
print "$count numbers with $n_low <= n < $n_high\n";
@tests = sort { $$a{'n'} <=> $$b{'n'}; } grep { defined } @tests;
open(WORKFILE,'>>worktodo.ini');
foreach $test (@tests) {
print WORKFILE "Pminus1=$$test{'k'},2,$$test{'n'},1,$b1,$b2\n";
}
close(WORKFILE);
If anyone want's to make an exe for windows etc I could add it to a sticky.