Re: [Tutor] Project Euler #8

2013-06-01 Thread Wolfgang Maier
Dave Angel davea.name> writes: > > > str_num = '1234567890' > > n = 5 > > > > strings = [str_num[i:i+5] for i in range(0, len(str_num)) if > > len(str_num[i:i+5])==5] > > If you changed the range() size, you could eliminate the extra if test. > After all, the only ones that'll be short are t

Re: [Tutor] Project Euler #8

2013-05-31 Thread Alan Gauld
On 31/05/13 21:49, Nick Shemonsky wrote: I did stumble upon using reduce ...but I didn't really understand what it was doing def product(intlist): return reduce(operator.mul, intlist) I explain reduce thusly in my Functional Programming topic: - The reduce function

Re: [Tutor] Project Euler #8

2013-05-31 Thread Dave Angel
On 05/31/2013 04:49 PM, Nick Shemonsky wrote: Here's the final code... I kept the if statement that way if I throw in a random series of numbers that isn't evenly divisible by 5, it'll always work itself out. And this answered the 1000 digit problem without issue. str_num = '1234567890' n =

Re: [Tutor] Project Euler #8

2013-05-31 Thread Nick Shemonsky
Thanks for the responses. I am using python 2.7. I'm not new to programming but might as well be... I last programmed heavily about a decade ago in college. I was a MIS major so I did my fair share of c++, sql, and php work but now I'm a windows sys admin so I haven't used it much at all in a long

Re: [Tutor] Project Euler #8

2013-05-31 Thread Alan Gauld
On 31/05/13 19:23, Nick Shemonsky wrote: or maybe it'd be quicker to compare a to b through each iteration and just keep the larger product rather than creating a giant list You are probably right if it is a giant list. str_num = '1234567890' n = 5 strings = [str_num[i:i+5] for i in range(0

Re: [Tutor] Project Euler #8

2013-05-31 Thread Dave Angel
On 05/31/2013 02:23 PM, Nick Shemonsky wrote: Hey there everybody. I'm new to python Welcome. But are you new to programming, or just to Python in particular? And which Python? I'd guess 2.7 and am attempting to teach myself to code while brushing up on my math skills via the problems at

[Tutor] Project Euler #8

2013-05-31 Thread Nick Shemonsky
Hey there everybody. I'm new to python and am attempting to teach myself to code while brushing up on my math skills via the problems at projecteuler.net. My solutions thus far have been mostly brute force and this is no exception but I'm having an issue with tackling some iteration in the problem.

Re: [Tutor] project euler prime factorization problem

2010-08-29 Thread Dave Angel
Steven D'Aprano wrote: On Mon, 30 Aug 2010 05:31:00 am bob gailer wrote: My current reasoning was something of this sort: Find all the factors of a number, then reduce them to just the prime factors Very inefficient. IMHO the proper way is to generate a list of all the prime numbers

Re: [Tutor] project euler prime factorization problem

2010-08-29 Thread Alan Gauld
"Nick" wrote I didn't call the functions in the program because I was calling them myself in the interpreter after running it. I assume you mean after importing it? Running a program is generally taken to mean executing the script as a standalone program. To execute the internal functions

Re: [Tutor] project euler prime factorization problem

2010-08-29 Thread Steven D'Aprano
On Mon, 30 Aug 2010 05:31:00 am bob gailer wrote: > > My current reasoning was something of this sort: Find all the > > factors of a number, then reduce them to just the prime factors > > Very inefficient. IMHO the proper way is to generate a list of all > the prime numbers up to the square root

Re: [Tutor] project euler prime factorization problem

2010-08-29 Thread Nick
"Did you test the program? That is one way to tell whether it works perfectly. What you showed above will do one visible thing - it will print "Don't forget to consider primes 2, 3, 5, and 7\n". The rest is a somewhat confusing collection of function definitions and comments. You never call the

Re: [Tutor] project euler prime factorization problem

2010-08-29 Thread bob gailer
On 8/29/2010 3:08 AM, Nick wrote: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? #don't forget 2,3,5,7. this function doesn't deliver those as output. def is_prime(b): #checks a number greater than 7 to see if it is prime and

Re: [Tutor] project euler prime factorization problem

2010-08-29 Thread Alan Gauld
"Nick" wrote What is the largest prime factor of the number 600851475143 ? For help on the math aspects try Wikipedia. Look up Prime factors... Would it be useful for me to buy a book, and if so what are some easily accessible ones? I feel dive into python is just too advanced for me.

[Tutor] project euler prime factorization problem

2010-08-29 Thread Nick
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? #don't forget 2,3,5,7. this function doesn't deliver those as output. def is_prime(b): #checks a number greater than 7 to see if it is prime and returns if is. if b % 2 != 0 and b

Re: [Tutor] project euler

2009-01-04 Thread Roel Schroeven
prasad rao schreef: > hello! > I got it 266333. > My code== > > t=0 > for x in range(1000): > if divmod(x,3)[1]==0:t+=x > if divmod(x,5)[1]==0:t+=x > t=266333 > > Am I correct in comprehention of the problem? Not entirely: you're counting numbers that are multiples of both 3 and 5 double

[Tutor] project euler

2009-01-04 Thread prasad rao
hello! I got it 266333. My code== t=0 for x in range(1000): if divmod(x,3)[1]==0:t+=x if divmod(x,5)[1]==0:t+=x t=266333 Am I correct in comprehention of the problem? Prasad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/

Re: [Tutor] Project Euler Problem 6

2008-04-24 Thread joe gallo
It says: Find the difference between the sum of the squares of the first * one hundred* natural numbers and the square of the sum. You did range(1,111). On Thu, Apr 24, 2008 at 1:13 PM, kinuthia muchane <[EMAIL PROTECTED]> wrote: > Hi, > > I am trying to solve problem 6 on the Project Euler, bu

Re: [Tutor] Project Euler Problem 6

2008-04-24 Thread Steve Willoughby
On Thu, Apr 24, 2008 at 11:13:31PM +0300, kinuthia muchane wrote: > return sum([k*k for k in range(1,111)])# sum of the squares of the > first one hundred numbers Wouldn't the first hundred numbers be range(1,101)? > def aux1(): > inter = sum([k for k in range(1,111))# square of the s

[Tutor] Project Euler Problem 6

2008-04-24 Thread kinuthia muchane
Hi, I am trying to solve problem 6 on the Project Euler, but when I submit my answer, I am told that it is wrong. Here is the problem: The sum of the squares of the first ten natural numbers is, 1² + 2² + ... + 10² = 385 The square of the sum of the first ten natural num