Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33625
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Problems on these two questions |
| Date | 2012-11-20 15:02 +0000 |
| Organization | Norwich University |
| Message-ID | <ah1kbgFac8tU3@mid.individual.net> (permalink) |
| References | <400c615f-4d93-4b8b-85ec-1bb4c47e30fe@googlegroups.com> <mailman.15.1353366936.29569.python-list@python.org> |
On 2012-11-19, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote: > On Sun, 18 Nov 2012 17:52:35 -0800 (PST), su29090 > <129km09@gmail.com> declaimed the following in > gmane.comp.python.general: > >> >> I all of the other problems but I have issues with these: >> >> 1.Given a positive integer n , assign True to is_prime if n >> has no factors other than 1 and itself. (Remember, m is a >> factor of n if m divides n evenly.) >> > Google: Sieve of Eratosthenes (might be mis-spelled) The sieve is a nice simple and fast algorithm, provided there's a bound on the highest n you need to check. It's much less simple and less fast if n is unbounded or the bound is unknown. Python's standard library isn't equipped with the an obvious collection to use to implement it either. >> 2.An arithmetic progression is a sequence of numbers in which >> the distance (or difference) between any two successive >> numbers if the same. This in the sequence 1, 3, 5, 7, ... , >> the distance is 2 while in the sequence 6, 12, 18, 24, ... , >> the distance is 6. >> >> Given the positive integer distance and the positive integer >> n , associate the variable sum with the sum of the elements >> of the arithmetic progression from 1 to n with distance >> distance . For example, if distance is 2 and n is 10 , >> then sum would be associated with 26 because 1+3+5+7+9 = >> 25 . > > So, what have you tried? > > Consider: you have a "sum", you have a sequence of "elements" > (based upon a spacing "distance"), and you have an upper bound > "n" > > You need to generate a sequence of "elements" starting at "1", > using "distance" as the spacing, until you exceed "n", and you > want to produce a "sum" of all those elements... This one's sort of a trick question, depending on your definition of "trick". The most obvious implementation is pretty good. In both cases a web search and a little high-density reading provides insights and examples for the OP. -- Neil Cerutti
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Problems on these two questions su29090 <129km09@gmail.com> - 2012-11-18 17:52 -0800
Re: Problems on these two questions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-19 02:09 +0000
Re: Problems on these two questions su29090 <129km09@gmail.com> - 2012-11-18 18:15 -0800
Re: Problems on these two questions Dave Angel <d@davea.name> - 2012-11-18 21:33 -0500
Re: Problems on these two questions Dave Angel <d@davea.name> - 2012-11-18 21:18 -0500
Re: Problems on these two questions Chris Angelico <rosuav@gmail.com> - 2012-11-19 13:23 +1100
Re: Problems on these two questions Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-11-19 18:15 -0500
Re: Problems on these two questions Neil Cerutti <neilc@norwich.edu> - 2012-11-20 15:02 +0000
Re: Problems on these two questions Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-11-19 18:16 -0500
Re: Problems on these two questions Dave Angel <d@davea.name> - 2012-11-19 20:52 -0500
Re: Problems on these two questions Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-19 23:32 -0700
csiph-web