Skip to content

Instantly share code, notes, and snippets.

@arkenidar
Last active April 25, 2017 17:40
Show Gist options
  • Save arkenidar/85f54c39cbce3fbaa4a6aea9d4db561f to your computer and use it in GitHub Desktop.
Save arkenidar/85f54c39cbce3fbaa4a6aea9d4db561f to your computer and use it in GitHub Desktop.
python program about fields of primes
# python program about fields of primes
def divnr(a,b): # a/b , div.ide n.on r.repeating
la=[]
string=''
psum=0
idx=-1
while True:
a*=10
# if a in la: break
try:
idx=la.index(a)
break
except ValueError:
pass
la+=[a]
c=a//b
d=a%b
string+=str(c)
psum+=c; psum%=9
a=d
return idx,psum,len(string),string
def field(n):
for i in range(1,n):
# print(i/n)
print(divnr(i,n))
prime_table=[7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109]
def fields(prime_table):
for n in prime_table:
field(n)
def is_prime(n):
length_a=-1
for i in range(1,n):
idx, psum, length_b, string=divnr(i,n)
if length_a!=length_b:
if length_a==-1: length_a=length_b
else: return False
if psum!=0: return False
if idx!=0: return False
return True
def is_prime_simple(n):
for i in range(2,n):
if n%i==0: return False
return n not in (2,3,5)
def calc_primes(max):
primes=[]
for n in range(2,max+1):
if is_prime(n): primes+=[n]
return primes
if __name__=='__main__':
# fields(prime_table)
print('field of 91:')
field(91)
print('is 91 prime? ', is_prime(91))
print('91 is not a prime number but is is detected as a prime number, based on its field. I see in the field references to number 11 and its multiples.')
print('prime table: ', prime_table)
print('calculated primes: ', calc_primes(109))
print('calc_primes(109)==prime_table: ', calc_primes(109)==prime_table)
print('however a good approximation. fixing this little imperfection should make it fine.')
for n in range(1000):
print(n, end=' ')
if is_prime(n)!=is_prime_simple(n): print((n, is_prime(n), is_prime_simple(n)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment