I am a farmer / novice number theory researcher. I happened to discover some years back a pattern that emerged in the distribution of the prime numbers that related the number of primes to the operation of 300 Fibonacci-like sequences. Well, as a person who has always used pen and paper I was at a loss when it came to converting my methods into computer code (so I hired a programmer to implement my code in Perl). That code worked but it was not the process that I now need; I wish to ask a community of programmers what they think is the best approach to making this (Python) code work. Also, as a researcher I am not overly concerned with people appropriating this code for their own uses - I would just like to see what you do with it!
The results generated by the Perl program were published in the AT&T Online Encyclopedia of Integer Sequences. https://oeis.org/search?q=helkenberg&language=english&go=Search
The program below is my recent effort but I cannot for the life of me figure out how to get certain parts of the code to work.
For instance (from the larger program below),
print"""THIS CODE WILL NOT COMPILE (example p*q = 29*73)
print [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90 #example 23
print [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90 #example 215
z(0) = [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90
z(1) = [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90
#This defines a new process, a Fibonacci-like sequence:
a = z(1) - z(0) #example (192=215-23)
g = 180 #think the unit circle, clock cycles
m_0 = a + g #example 192+180 = 372
z(2) = m_0 + z(1) #example 587 = 372 + 215
m_1 = m_0 + g #example 552 = 372 + 180
z(3) = z(2)+ m_1 #example 1139 = 587 + 552
m_2 = m_1 + g #example 732 = 552 + 180
z(4) = z(3) + m_2 #example 1871 = 1139 + 732
I am teaching myself how to code and I cannot for the life of me figure out how to implement this!!!
Lastly, I need to use those values (of the z term) to solve an equation of the form:
0 = r - [(((90*n))+29)*y) + z_n]
0 = r - [(((90*n))+73)*y) + z_n]
where the z term is used for both 29 and 73 (as an example)
Here is what I have so far.
print "1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139"
variable = raw_input('copy and paste the above number')
#This valuable function reduces an arbitrarily large number to the SUM OF ITS DIGITS
new_variable = sum(map(int, str(variable)))
print new_variable
next_step = sum(map(int, str(new_variable)))
print next_step
new_step = sum(map(int, str(next_step)))
print "The digital root of our test number is", new_step, "A fine answer."
if int(new_step) > 9:
print "We cannot have a two digit digital root!Enter the sum of those two numbers here!"
newest_data = raw_input ('>enter the digital root here')
#newest_data = raw_input ()
if new_step == 3:
print "This number is divisible by 3."
if new_step == 6:
print "This number is divisible by 3."
if new_step == 9:
print "This number is divisible by 3 and 9."
if newest_data == 3:
print "This number is divisible by 3."
if newest_data == 6:
print "This number is divisible by 3."
if newest_data == 9:
print "This number is divisible by 3 and 9."
print "What is the last digit of our number?"
last_digit = raw_input("Last digit here")
print last_digit
if int(last_digit) == 0:
print "This number is divisible by 2 and 5."
if int(last_digit) == 2:
print "This number is divisible by 2."
if int(last_digit) == 4:
print "This number is divisible by 2."
if int(last_digit) == 6:
print "This number is divisible by 2."
if int(last_digit) == 8:
print "This number is divisible by 2."
digital_root = int(new_step)
new_digit = int(last_digit)
if digital_root == 1 and new_digit == 1:
print "your primitive is 91"
elif digital_root == 1 and new_digit == 3:
print "your primitive is 73"
elif digital_root == 1 and new_digit == 7:
print "your primitive is 37"
elif digital_root == 1 and new_digit == 9:
print "your primitive is 19"
elif digital_root == 2 and new_digit == 1:
print "your primitive is 11"
elif digital_root == 2 and new_digit == 3:
print "your primitive is 73"
elif digital_root == 2 and new_digit == 7:
print "your primitive is 47"
elif digital_root == 2 and new_digit == 9:
print "your primitive is 29"
elif digital_root == 4 and new_digit == 1:
print "your primitive is 31"
elif digital_root == 4 and new_digit == 3:
print "your primitive is 13"
elif digital_root == 4 and new_digit == 7:
print "your primitive is 67"
elif digital_root == 4 and new_digit == 9:
print "your primitive is 49"
elif digital_root == 5 and new_digit == 1:
print "your primitive is 41"
elif digital_root == 5 and new_digit == 3:
print "your primitive is 23"
elif digital_root == 5 and new_digit == 7:
print "your primitive is 77"
elif digital_root == 5 and new_digit == 9:
print "your primitive is 59"
elif digital_root == 7 and new_digit == 1:
print "your primitive is 61"
elif digital_root == 7 and new_digit == 3:
print "your primitive is 43"
elif digital_root == 7 and new_digit == 7:
print "your primitive is 7"
elif digital_root == 7 and new_digit == 9:
print "your primitive is 79"
elif digital_root == 8 and new_digit == 1:
print "your primitive is 71"
elif digital_root == 8 and new_digit == 3:
print "your primitive is 53"
elif digital_root == 8 and new_digit == 7:
print "your primitive is 17"
elif digital_root == 8 and new_digit == 9:
print "your primitive is 89"
primitive = raw_input("enter primitive here")
new_value = int(variable) - int(primitive)
stored_data = new_value/90
print "this is our new number, the position of our test number in a dr,ld index.", stored_data
print "This number above is our test number (r)."
tuple = [73,91,19,37,11,23,29,77,47,59,83,41,13,61,31,43,49,7, 67,79,17,89,53,71]
print tuple
print " the example is based on 29*73"
p = raw_input("p from tuple (to be defined)") # example 29
q = raw_input("q associated with p") #example 73
#def make_incrementor (n): return lambda x: x + n
#cannot figure this one out
#notice x_0 and then x_1:
print"""THIS CODE WILL NOT COMPILE (example p*q = 29*73)
print [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90 #example 23
print [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90 #example 215
z(0) = [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90
z(1) = [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90
#This defines a new process, a Fibonacci-like sequence:
a = z(1) - z(0) #example (192=215-23)
g = 180 #think the unit circle, clock cycles
m_0 = a + g #example 192+180 = 372
z(2) = m_0 + z(1) #example 587 = 372 + 215
m_1 = m_0 + g #example 552 = 372 + 180
z(3) = z(2)+ m_1 #example 1139 = 587 + 552
m_2 = m_1 + g #example 732 = 552 + 180
z(4) = z(3) + m_2 #example 1871 = 1139 + 732
"""
print "seed values for sequence z = [23, 215]"
print "set of z terms [23, 215, 587, 1139, 1871,.....] "
print "notice the last-digit pattern for the z term means that every term of z will end in a [3, 5, 7, 9, 1], in that order, but also IN A POWER SERIES. Also notice that our test number (r) ends with the last digit 8. So prior to computing w, we know that none of the solutions represented by z (where z = r) are possible."
print """
there are 24 equations (posed as alternatives):
r = stored_data test number, RSA-100 clock position
print "RSA-100 = 19 + (90*16917833643583704005951315312584860330200756832904229873976761050890255147321698862822226118800068)"
Startng at 19 degrees, RSA100 is 169..... 1/4 rotations from the 0 position on the clock face.
#special case: where r-z = 0, factor found.
0 = r - [(((90*n))+19)*y) + z_n]
0 = [(((r-z_n)/y)-19)]/x - 90]
0 = r - [(((90*n)+91)*y) + z_n]
0 = [(((r-z_n)/y)-91)]/n - 90]
0 = r - [(((90*n)+37)*y) + z_n]
0 = [(((n-z_n)/y)-37)]/n - 90]
0 = r - [(((90*n)+73)*y) + z_n]
0 = [(((r-z_n)/y)-73)]/n - 90]
0 = r - [(((90*n)+11)*y) + z_n]
0 = [(((r-z_n)/y)-11)]/n - 90]
0 = r - [(((90*n)+59)*y) + z_n]
0 = [(((r-z_n)/y)-59)]/n - 90]
0 = r - [(((90*n)+29)*y) + z_n]
0 = [(((r-z_n)/y)-29)]/x - 90]
0 = r - [(((90*n)+41)*y) + z_n]
0 = [(((r-z_n)/y)-41)]/n - 90]
0 = r - [(((90*n)+47)*y) + z_n]
0 = [(((r-z_n)/y)-47)]/n - 90]
0 = r - [(((90*n)+77)*y) + z_n]
0 = [(((r-z_n)/y)-77)]/n - 90]
0 = r - [(((90*n)+83)*y) + z_n]
0 = [(((r-z_n)/y)-83)]/n - 90]
0 = r - [(((90*n)+23)*y) + z_n]
0 = [(((r-z_n)/y)-83)]/n - 90]
0 = r - [(((90*n)+13)*y) + z_n]
0 = [(((r-z_n)/y)-13)]/n - 90]
0 = r - [(((90*n)+43)*y) + z_n]
0 = [(((r-z_n)/y)-43)]/n - 90]
0 = r - [(((90*n)+31)*y) + z_n]
0 = [(((r-z_n)/y)-31)]/n - 90]
0 = r - [(((90*n)+79)*y) + z_n]
0 = [(((r-z_n)/y)-79)]/n - 90]
0 = r - [(((90*n)+49)*y) + z_n]
0 = [(((r-z_n)/y)-49)]/n - 90]
0 = r - [(((90*n)+61)*y) + z_n]
0 = [(((r-z_n)/y)-61)]/n - 90]
0 = r - [(((90*n)+67)*y) + z_n
0 = [(((r-z_n)/y)-67)]/n - 90]
0 = r - [(((90*n)+7)*y) + z_n]
0 = [(((r-z_n)/y)-7)]/n - 90]
0 = r - [(((90*n)+17)*y) + z_n]
0 = [(((r-z_n)/y)-17)]/n - 90]
0 = r - [(((90*n)+53)*y) + z_n]
0 = [(((r-z_n)/y)-53)]/n - 90]
0 = r - [(((90*n)+71)*y) + z_n]
0 = [(((r-z_n)/y)-71)]/n - 90]
0 = r - [(((90*n)+89)*y) + z_n]
0 = [(((r-z_n)/y)-89)]/n - 90]
"""
#Here is the OLD PROGRAM in Perl
#!/usr/bin/perl
use strict;
use warnings;
use Math::BigInt;
use POSIX;
use Getopt::Long;
my $rsa = '';
my $p = '';
my $q = '';
my $digit_root_chart = '';
GetOptions(
'rsa|r=s' => \$rsa,
'p=s' => \$p,
'q=s' => \$q,
'digit|d=i' => \$digit_root_chart,
) or die "Problem with command";
# /*
# * General algorithm goes here.
# *
# */
my $length_of_semiprime = length($rsa);
my $digit_root = &digit_root($rsa);
print "digit root: $digit_root\n";
$rsa = Math::BigInt->new($rsa);
print "rsa: $rsa\n";
my $new_rsa = $rsa->copy();
$new_rsa -=
$digit_root_chart; # need to figure out a way to tablize the digit root table
$new_rsa /= 90;
print "new_rsa: $new_rsa\n";
$p = Math::BigInt->new($p);
$q = Math::BigInt->new($q);
my $y = &first_two_calcs( $p, $q );
print "p = $p, q = $q\n";
&check_for_factor( $p, $q, $y );
$p += 90;
$q += 90;
my $z = &first_two_calcs( $p, $q );
print "p = $p, q = $q\n";
&check_for_factor( $p, $q, $z );
$p += 90;
$q += 90;
print "p = $p, q = $q\n";
my @r = &second_calcs( $y, $z );
$y = $r[0];
$z = $r[1];
&check_for_factor( $p, $q, $z );
while (1) {
$p += 90;
$q += 90;
my @t = &third_calc( $y, $z );
$y = $t[0];
$z = $t[1];
if ( $z <= $new_rsa ) {
&check_for_factor( $p, $q, $z )
if ( ( length($p) || length($q) ) >=
( ( $length_of_semiprime / 2 ) - 1 ) );
}
else {
last;
}
}
# This sub() is used for the first two calculations
sub first_two_calcs {
my ( $p, $q ) = @_;
my $z = $p * $q;
my $x = $z / 9;
# if its a whole number we move along
if ( ( $z % 9 ) == 0 ) {
print "($p * $q) / 9 = $x\n";
}
else {
print "num doesn't div evenly: ($p * $q) / 9 = $x\n";
$x = int( $x / 10 );
print "new num: (($p * $q) / 9) / 10 = $x\n";
}
return $x;
}
# /*
# * This sub() checks to see if it is a factor.
# *
# */
sub check_for_factor {
my ( $p, $q, $z ) = @_;
print "Check_for_factor(p = $p, q = $q, z = $z)\n";
for ( $p, $q ) {
my $temp = $new_rsa - $z;
my $y = ( $temp / $_ );
if ( ( $temp % $_ ) == 0 ) {
print "\n******* factor found: $_ for $rsa *******\n";
exit(0);
}
elsif ( ( int( $y / 10 ) ) == $new_rsa ) {
print "\n******* factor found: $_ for $rsa *******\n";
exit(0);
}
else {
print "factor NOT found: ($new_rsa - $z) / $_ = $y\n";
}
}
}
# This sub() is used for the rest of the calculations
sub second_calcs {
my ( $y, $z ) = @_;
my $j = $z - $y;
my $k = $j + 180;
my $l = $z + $k;
print "$z - $y = |$j|\n";
print "$j + 180 = $k\n";
print "$k + $z = $l\n";
return ( $k, $l );
}
sub third_calc {
my ( $y, $z ) = @_;
my $k = $y + 180;
my $l = $z + $k;
return ( $k, $l );
}
# /*
# * This sub() calcs the digit root:
# * example: $rsa = 12345
# * 1 + 2 + 3 + 4 + 5 = 15 and 1 + 5 = 6 (digit root)
# */
sub digit_root {
my $rsa = shift;
$rsa = Math::BigInt->new($rsa);
return ( 1 + ( ( $rsa - 1 ) % 9 ) );
}