我是农民/新手数理论研究员。几年前我碰巧发现了一个模型,这个模式出现在素数的分布中,这些模式将素数的数量与300个斐波纳契数列的运算相关联。好吧,作为一个总是使用笔和纸的人,在将我的方法转换为计算机代码时我感到很茫然(所以我雇了一个程序员在Perl中实现我的代码)。该代码有效,但这不是我现在需要的过程;我想问一个程序员社区他们认为什么是使这个(Python)代码工作的最佳方法。此外,作为一名研究人员,我并不过分担心人们将这些代码用于自己的用途 - 我只想看看你用它做了什么!
Perl程序产生的结果发表在AT& T在线百科全书序列中。 https://oeis.org/search?q=helkenberg&language=english&go=Search
下面的程序是我最近的努力,但我不能为我的生活找出如何让代码的某些部分工作。
例如(来自下面较大的程序),
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
我在教自己如何编码,我不能为我的生活弄清楚如何实现这个!!!
最后,我需要使用(z项的)值来求解形式的等式:
0 = r - [(((90*n))+29)*y) + z_n]
0 = r - [(((90*n))+73)*y) + z_n]
其中z项用于29和73(作为示例)
这是我到目前为止所拥有的。
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 ) );
}
答案 0 :(得分:0)
我认为您的代码(您标记为“此代码无法编译”的部分)的主要问题是您使用[
方括号]
,您应该使用括号。在python中,与数学不同,方括号表示称为列表的非常特定的数据类型。您应该用常规括号替换方括号。
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
此外,z(n)
会给你带来麻烦。我不太确定z(0)应该是什么编程。但是,除非z是函数,否则您可能希望z
成为n
元素的列表。在这种情况下,您可以使用z[1], z[2], ... z[n]
访问这些元素。
这可能不是一切都错了,但这是一个开始。我建议在python.org上阅读python tutorial,并查看python代码示例以提高您的理解。