mersenneforum.org A stab at Twin Primes, Pour on the Steak Sauce
 Register FAQ Search Today's Posts Mark Forums Read

 2020-11-09, 07:25 #1 ONeil   Dec 2017 24·3·5 Posts A stab at Twin Primes, Pour on the Steak Sauce Warning: if you wish to be a prime number theorist, then you have to realize, as the integers grow the prime gaps increase too! So predicting prime numbers is near impossible at the very large scale! So for most prime number formulas, this one works best at the lower scale. User beware. You must enter a Prime to find the twin prime! I built this twin prime finder for speed so enjoy it kicks ass for speed I mean just check the times and you will scratch your head. Now if you must find your twin prime then input its twin ok on the lower end! It will find the higher integer Twin Prime guaranteed. Also for you seekers out there I built in a modular search for this code and when all zeros come up, check the prime window for at least a prime. For Huge prime who can guarantee it, I'm just saying Code: print('''Warning: if you wish to be a prime number theorist, then you have to realize, as the integers grow the prime gaps increase too! So predicting prime numbers is near impossible at the very large scale! So for most prime number formulas, this one works best at the lower scale. User beware. You must enter a Prime to find the twin prime!''') import time start_time = time.time() while True: n = int(input("Enter a prime number: ")) if n % 2 != 0: t = (((2*n)//2)) + ((3*(n+2)//3)) ttl = (((2*n)//2)) + ((3*(n+2)//3)) + (((2*n+3))) - ((3*(n+2)//3)) ta = (((2*n)//2)) tb = ((3*(n+2)//3)) print('____________') print(ttl%6,'When all Zero likely twin primes or one prime') print(t%3) print(t%8) print('____________') print(ta,tb,"Prime numbers show here") e = int(time.time() - start_time) print('{:02d}:{:02d}:{:02d}'.format(e // 3600, (e % 3600 // 60), e % 60))
 2020-11-09, 08:08 #2 retina Undefined     "The unspeakable one" Jun 2006 My evil lair 32×23×29 Posts It might be fast, but it is wrong. There is no sense in driving at lightning speed when you are driving in the wrong direction.
2020-11-09, 08:10   #3
ONeil

Dec 2017

3608 Posts

Quote:
 Originally Posted by retina It might be fast, but it is wrong. There is no sense in driving at lightning speed when you are driving in the wrong direction.
it works for me show me the error I'm picking off many twin primes

2020-11-09, 08:17   #4
ONeil

Dec 2017

24·3·5 Posts

Quote:
 Originally Posted by retina It might be fast, but it is wrong. There is no sense in driving at lightning speed when you are driving in the wrong direction.
t = (((2*n)//2)) + ((3*(n+2)//3))

Are you suggesting I should just do this retina?

t = (( n ) + (n+2))

2020-11-09, 08:36   #5
ONeil

Dec 2017

24010 Posts

Quote:
 Originally Posted by retina It might be fast, but it is wrong. There is no sense in driving at lightning speed when you are driving in the wrong direction.
Your wrong, and here is why the modular arithmetic is great for prediction and helps when its all zero so the approach is to to check when all is zero or 2 zero's and the last is a 4.

2020-11-09, 10:15   #6
Viliam Furik

"Viliam Furík"
Jul 2018
Martin, Slovakia

1010011102 Posts

Quote:
 Originally Posted by ONeil Your wrong, and here is why the modular arithmetic is great for prediction and helps when its all zero so the approach is to to check when all is zero or 2 zero's and the last is a 4.
retina was saying, that no matter how fast you make your code, it's not useful, at all...

If you have to put in the smaller of the two KNOWN twin primes, the only purpose of that code is to print out p+2. Anything more is unnecessary, as is anything less -> If you know it's the smaller twin, why even bother printing out p+2??

 2020-11-09, 11:52 #7 mathwiz   Mar 2019 11·13 Posts What's the point of this code? If you know $p$ prime, it just computes $p+2$? (in which case... why not just add 2)? Or is it that you know $p$ prime, and it computes $p+2$ *and* tests it for primality? (in which case, why not just use any of the existing primality testing algorithms, which are actually correct?)
2020-11-09, 13:34   #8
Dr Sardonicus

Feb 2017
Nowhere

3×7×199 Posts

Quote:
 Originally Posted by ONeil Code: ta = (((2*n)//2)) tb = ((3*(n+2)//3))
Quote:
 KIRK: Mister Spock, is this ship headed for Ariannus? SPOCK: Negative, Captain. The Enterprise is now moving in a circular course. SCOTT: And at warp ten, we're going nowhere mighty fast.
-- STAR TREK, "Let That Be Your Last Battlefield"

 2020-11-13, 03:43 #9 swishzzz   Jan 2012 Toronto, Canada 1101002 Posts Code: print('''Warning: if you wish to be a prime number theorist, then you have to realize, as the integers grow the prime gaps increase too! So predicting prime numbers is near impossible at the very large scale! So for most prime number formulas, this one works best at the lower scale. User beware. You must enter a Prime to find the twin prime!''') import time start_time = time.time() while True: n = int(input("Enter a prime number: ")) if n % 2 != 0: t = (((2*n)//2)) + ((3*(n+2)//3)) ttl = (((2*n)//2)) + ((3*(n+2)//3)) + (((2*n+3))) - ((3*(n+2)//3)) ta = (((2*n)//2)) tb = ((3*(n+2)//3)) print('____________') print(ttl%6,'When all Zero likely twin primes or one prime') print(t%3) print(t%8) print('____________') print(ta,tb,"Prime numbers show here") e = int(time.time() - start_time) print('{:02d}:{:02d}:{:02d}'.format(e // 3600, (e % 3600 // 60), e % 60)) As a python developer the formatting here drives me nuts. Disregarding the content of the actual code itself, please Use 4 spaces per indent level Remove the unnecessary bracketing. You should know that * and / have precedence over + and -. Put spaces after operators and commas Be consistent in your use of '' and "" quotes Put your imports at the very top of the code
2020-11-13, 13:34   #10
Dr Sardonicus

Feb 2017
Nowhere

3·7·199 Posts

Quote:
 Originally Posted by swishzzz Disregarding the content of the actual code itself,
Good move. If you look too hard for any content, you'll hurt your eyes.
Quote:
 Remove the unnecessary bracketing. You should know that * and / have precedence over + and -.
Being unfamiliar with Python, I had to look up // (it's "floor divide"), and has the same priority as * and /. Thus, apparently in spite of the OP's best efforts, this thread has served a constructive purpose. I've learned something!

If there is any reason for the unnecessary bracketing other than making the code harder to read, I am suffering a failure of imagination as to what it could be.

Just out of curiosity, is there a generic term for calculations specifically designed not to do anything?

2020-11-13, 14:33   #11
retina
Undefined

"The unspeakable one"
Jun 2006
My evil lair

32·23·29 Posts

Quote:
 Originally Posted by Dr Sardonicus Just out of curiosity, is there a generic term for calculations specifically designed not to do anything?
Yes, they are speed-up computations.

So whenever someone says it isn't fast enough, then you just remove one of them and now it is faster. It's pure genius!

 Similar Threads Thread Thread Starter Forum Replies Last Post hal1se Miscellaneous Math 13 2018-11-05 16:34 carpetpool Miscellaneous Math 3 2017-08-10 13:47 Computer Science & Computational Number Theory 171 2013-05-14 02:57 R.D. Silverman Math 8 2005-07-15 21:56 Chris Card Math 1 2005-05-26 14:18

All times are UTC. The time now is 03:18.

Sun Jan 24 03:18:52 UTC 2021 up 51 days, 23:30, 0 users, load averages: 1.66, 1.90, 1.84