OSDir


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Program to find Primes of the form prime(n+2) * prime(n+1) - prime(n) +- 1.


On Thu, 04 Oct 2018 09:44:01 +0100, Tony van der Hoff wrote:

> On 04/10/18 09:31, Alister via Python-list wrote:
>> On Wed, 03 Oct 2018 09:43:07 -0700, Musatov wrote:
>> 
>>> On Wednesday, October 3, 2018 at 11:12:43 AM UTC-5, Michael Torrie
>>> wrote:
>>>> On 10/03/2018 09:26 AM, Musatov wrote:
>>>>> I don't even know where to begin! (I'm reading the Dummies book)
>>>>
>>>> If you have no experience in computer programming, it's going to be a
>>>> steep learning curve.
>>>>
>>>> But your first step is to learn Python and how to write programs in
>>>> it.
>>>> That book and others will help with that.  You'll have to write lots
>>>> of simple programs unrelated to primes along the way that help you
>>>> understand programming concepts.
>>>>
>>>> If you already have experience in other languages, the task will be
>>>> easier.
>>>>
>>>> Computer programming is quite natural to some (small children seem to
>>>> get it much easier than us adults), but I've seen others struggle to
>>>> grasp the abstract concepts for years.
>>>>
>>>> Once you've grasped basic Python programming, you can return top the
>>>> original problem at hand.  Start by identifying the process or
>>>> algorithm that would find these primes. In other words, how would you
>>>> do it on pen and paper?  Computer programs are not magic.  They are
>>>> only expressions of human thinking. Often some very smart
>>>> mathematicians have come up with powerful algorithms (a step-by-step
>>>> process) to do these things,
>>>> and your job as a programmer is to turn this mathematical process
>>>> into a computer program using things like loops and Boolean logic.
>>>> How would you find these primes using your pen, paper, and
>>>> calculator?
>>>
>>> Literally, how I found them was taking a list of primes and checking
>>> if the calculations with the lesser primes resulted in numbers also
>>> further along on the list.
>>>
>>> Another way I guess would be to do the calculations then check if the
>>> number is prime.
>> 
>> That is exactly how you do it with in a program.
>> 
>> create a loop & check to see if the target number can be divided by
>> each possible divisor in turn .
>> for large numbers this will take a large number of tests (hey that is
>> why you have the computer do them, it is faster than you & does not get
>> bored ;-) ) there are numerous tricks for speeding up this process once
>> you have the basic working.
>> 
>> start by testing small numbers & then use your real data once you have
>> something that works
>> 
>> as a starter a simple loop in python could be as follows
>> 
>> for x in xrange(10):
>> 	print x
>> 
>> once you have an outline of a program post it back here if things dont
>> work as expected
>> 
>> 
> Two lines, two errors! To save the noob a lot of head-scratching, that
> should be:
> for x in range(10):
> 
> If you're running python 3, as you should do for any new project:
> 	print( x )

perfectly legit python 2.7
I probably should have considered writing python 3 compatible code but 
range operates differently on the 2 versions & would be a poor choice for 
python 2 when numbers get larger

ass for the head scratching a noob (& anyone else for that mater) far 
more from correcting code than they do from simply copy & pasting working 
code.




-- 
TAILFINS!! ... click ...