2012-02-19 101 views
1

我是農民/新手數理論研究員。我碰巧發現了幾年前在質數分佈中出現的一種模式,這種模式將質數與運行300個斐波納契樣序列相關聯。那麼,作爲一個總是使用筆和紙的人,當我將方法轉換成計算機代碼時(我僱用程序員在Perl中實現我的代碼),我一直處於虧損狀態。該代碼有效,但這不是我現在需要的過程;我想問一個程序員社區他們認爲是使這個(Python)代碼工作的最佳方法。另外,作爲一名研究人員,我並不過分關心爲他們自己使用這些代碼的人 - 我只想看看你用它做了什麼!Python半素數分解方程求解器問題

Perl程序生成的結果發佈在整數序列的在線百科全書AT &中。 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

'raw_input('複製並粘貼上面的數字')' - wtf? – 2012-02-19 14:48:46

+0

@J。 W. Helkenburg:如果你能給我一個清晰的序列描述,我願意幫助你實施。試圖解釋你的代碼,或者任何名爲Perl的東西都浪費我的時間:)我可以在irc.freenode.org的#pygrafix上找到它。 – orlp 2012-02-19 14:51:02

+0

你僱傭了一個程序員來寫這個爛攤子? – 2012-02-19 15:32:11

回答

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是函數,否則您可能需要zn元素的列表。在這種情況下,您可以使用z[1], z[2], ... z[n]訪問這些元素。

這可能不是一切都是錯的,但它是一個開始。我建議您閱讀python.org上的python tutorial,並查看Python代碼示例以提高您的理解。

+0

代碼不會編譯,因爲它是僞代碼而不是Python。這是另一位用戶建議的內容。 P = 29 Q = 73 克= 180 #防止舊版條款的重新計算由記憶化 z_results = { 0:INT(((P + 90.0 * 0)*(Q + 90.0 * 0))/ 90.0), 1:INT(((p + 90.0 * 1)*(q + 90.0 * 1))/ 90.0), } DEF Z(x)的: 如果x在z_results: 返回z_results [X ] 結果= G + 2 * Z(X - 1) - Z(X - 2) z_results [X] =導致 返回結果 對於i在範圍(20): 打印(「%d:% d「%(i,z(i))) – 2012-02-20 15:17:29