This site is supported by donations to The OEIS Foundation.

User:J. W. Helkenberg

From OeisWiki
Jump to: navigation, search
  • Python Program to Produce Primes



I wish to publish this sequence, which I think is interesting.

1, 4, 5, 8, 10, 12, 14, 15, 16, 19, 21, 22, 23, 27, 27, 27, 29, 30, 32, 35, 36, 38, 40, 42, 43, 43, 44, 46, 48, 49 ,50, 52, 53, 56, 57, 58, 59, 60, 61, 61, 63, 64, 66, 67, 71, 71, 71, 75, 77, 78, 78, 78, 79, 80, 81, 82, 82, 83, 85, 87, 88, 92, 92, 92, 92, 93, 95, 99, 99, 99, 103, 104, 104, 104, 105, 106, 106, 106, 111, 112, 113, 114, 115, 116, 118, 118, 118, 120, 122, 126, 127, 127, 127, 128, 129, 131, 132, 134, 135, 137, 137, 137, 141, 141, 141

This program generates one sequences and derives a second sequence. The first sequence it generates lists all composite numbers of the form 90n+1 (beneath a limit) and then sorts these values ascending. The second list is generated by an algorithm that identifies numbers missing from the first list. It returns these numbers as a separate output. You will be prompted for the output.

The first list is contradistinct from the second list. The second list = Sloane's A181732. See https://oeis.org/A181732

The limits in the program are set to extend terms to match the largest member of the bfile for A181732. See https://oeis.org/A181732/b181732.txt


#!/usr/local/env python #python 2.7
import sys
import csv
import time
import subprocess

dump = open("composite1.csv", "w")
new_test = 40000 #this is a limit

def dr1_ld1_91_91(x):
..y = 90*(x*x) + 2*x 
..#print "91", y
..dump.write(str(y) + "\n")
..for n in range(1, new_test):
....new_y = y+((91+(90*(x-1)))*n)
....#print "91", new_y  
....dump.write(str(new_y) + "\n")
....if new_y > new_test: 
......return
....else:
......pass

def dr1_ld1_19_19(x):
..y = 90*(x*x) - 142*x + 56 
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+ ((19+(90*(x-1)))*n)
....dump.write(str(new_y) + "\n")
....if new_y > new_test: 
......return
....else:
......pass

def dr1_ld1_37_73(x):
..y = 90*(x*x) - 70*x + 10
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((37+(90*(x-1)))*n)
....new2_y = y+((73+(90*(x-1)))*n)   
....dump.write(str(new_y) + "\n")  
....dump.write(str(new2_y) + "\n")    
....if new_y > new_test: 
......return
....else:
......pass
    
def dr1_ld1_11_41(x):
..y = 90*(x*x) - 128*x + 43
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((11+(90*(x-1)))*n)
....new2_y = y+((41+(90*(x-1)))*n)   
....dump.write(str(new_y) + "\n")   
....dump.write(str(new2_y) + "\n") 
....if new_y > new_test: 
......return
....else:
......pass
    
def dr1_ld1_29_59(x):
..y = 90*(x*x) - 92*x + 21 
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((29+(90*(x-1)))*n)
....new2_y = y+((59+(90*(x-1)))*n) 
....dump.write(str(new_y) + "\n")   
....dump.write(str(new2_y) + "\n") 
....if new_y > new_test: 
......return
....else:
......pass
    
def dr1_ld1_47_23(x):
..y = 90*(x*x) - 110*x + 32
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((23+(90*(x-1)))*n) 
....new2_y = y+((47+(90*(x-1)))*n) 
....dump.write(str(new_y) + "\n")  
....dump.write(str(new2_y) + "\n") 
....if new_y > new_test: 
......return
....else:
......pass
    
def dr1_ld1_77_83(x):
..y = 90*(x*x) - 20*x + 1
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((77+(90*(x-1)))*n)
....new2_y = y+((83+(90*(x-1)))*n)  
....dump.write(str(new_y) + "\n")   
....dump.write(str(new2_y) + "\n") 
....if new_y > new_test: 
......return
....else:
......pass
    
def dr1_ld1_7_13(x):
..y = 90*(x*x) - 160*x + 71
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((7+(90*(x-1)))*n) 
....new2_y = y+((13+(90*(x-1)))*n)
....dump.write(str(new_y) + "\n")   
....dump.write(str(new2_y) + "\n") 
....if new_y > new_test: 
......return
....else:
......pass
    

def dr1_ld1_31_61(x):
..y = 90*(x*x) - 88*x + 19
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((31+(90*(x-1)))*n)
....new2_y = y+((61+(90*(x-1)))*n)  
....dump.write(str(new_y) + "\n")   
....dump.write(str(new2_y) + "\n") 
....if new_y > new_test: 
......return
....else:
......pass
    
def dr1_ld1_49_79(x):
..y = 90*(x*x) - 52*x + 5 
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((49+(90*(x-1)))*n) 
....new2_y = y+((79+(90*(x-1)))*n)  
....dump.write(str(new_y) + "\n")   
....dump.write(str(new2_y) + "\n") 
....if new_y > new_test: 
......return
....else:
......pass
    

def dr1_ld1_43_67(x):
..y = 90*(x*x) - 70*x + 12 
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((43+(90*(x-1)))*n)
....new2_y = y+((67+(90*(x-1)))*n) 
....dump.write(str(new_y) + "\n")  
....dump.write(str(new2_y) + "\n") 
....if new_y > new_test: 
......return
....else:
......pass
    
def dr1_ld1_17_53(x):
..y = 90*(x*x) - 110*x + 30 
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((17+(90*(x-1)))*n)
....new2_y = y+((53+(90*(x-1)))*n)   
....dump.write(str(new_y) + "\n")  
....dump.write(str(new2_y) + "\n") 
....if new_y > new_test: 
......return
....else:
......pass
    
def dr1_ld1_71_71(x):
..y = 90*(x*x) - 38*x + 4  
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((71+(90*(x-1)))*n)   
....dump.write(str(new_y) + "\n") 
....if new_y > new_test: 
......return
....else:
......pass
    
def dr1_ld1_89_89(x):
..y = 90*(x*x) - 2*x 
..dump.write(str(y) + "\n")
..for n in range (1, new_test):
....new_y = y+((89+(90*(x-1)))*n) 
....dump.write(str(new_y) + "\n")
....if new_y > new_test: 
......return
....else:
......pass
    
for x in xrange(1, 90): #This is a limit. 
 
....dr1_ld1_7_13(x) #1 @xrange(x) = 22, y = 1814 
....dr1_ld1_19_19(x) #4 
....dr1_ld1_11_41(x) #5 
....dr1_ld1_17_53(x) #10
....dr1_ld1_47_23(x) #12
....dr1_ld1_29_59(x) #19
....dr1_ld1_31_61(x) #21
....dr1_ld1_37_73(x) #30
....dr1_ld1_43_67(x) #32 
....dr1_ld1_49_79(x) #43
....dr1_ld1_71_71(x) #56
....dr1_ld1_77_83(x) #71
....dr1_ld1_89_89(x) #88
....dr1_ld1_91_91(x) #92

def bash_command(cmd):
....subprocess.Popen(cmd, shell=True)
bash_command('sort -n composite1.csv -o composite2.csv')
time.sleep(0.2) #make sure subprocess has finished

z=890
f=open("composite2.csv")
for i in range(z):
..line=f.next().strip()
..print line
..#print "not prime", line
f.close()

proceed = raw_input("Shall we print the prime sequence for 90n+1? "yes" or "no"")
if proceed == "yes":
..pass
if proceed == "no":
..quit("goodbye")

#run this code to compare to https://oeis.org/A181732/b181732.txt
with open("composite2.csv") as f:
....rd=f.readlines()
....x=[t.strip("\n") for t in rd]
....for i in range(0, 37188):
........if str(i) not in x:
............print ("{} is prime".format(i))