[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 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 )

Tony van der Hoff        | mailto:tony at vanderhoff.org
Buckinghamshire, England |