Just to reiterate my prev. post, as I think it helps structure my weaknesses.
Coding methodology: Is the algorithm I used feasible or mostly correct? If not, how do I correct it and why won't it work or scale? I realize in some cases there are always going to be optimal solutions that will be over my head mathematically, but generally you can yield a solution that is within a reasonable range of optimal that is passable without knowing a ton of number theory in my experience. Where possible, I hope to learn algorithms along the way (such as the Sieve of Eratosthenes for prime ranges).
Coding execution: Given some pseudocode that we determine algorithmically will work, is the code written executed without redundancies and minimizing runtime?
Being more pythonic: Is something I'm not doing pythonic or can it be done simpler with some sort of library I don't know about? I believe this is mostly semantic, though in some cases can have large effects on performance (for instance, using
map()
instead of afor
loop to applyint()
).
I submitted the following code as a solution to Project Euler's #12. It's extremely slow, running in mean 7.13 seconds over 100 trials (I think; just using other submitted solutions as a benchmark. It seems as though solutions <1 seconds are generally decent.)
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def triangle_number(n):
for i in range(n):
n += i
return n
n = 1
while True:
if len(factors(triangle_number(n))) >= 500:
print n, triangle_number(n)
break
else:
n +=1
The code for the factors
function was borrowed from here here.
Just to reiterate my prev. post, as I think it helps structure my weaknesses.
Coding methodology: Is the algorithm I used feasible or mostly correct? If not, how do I correct it and why won't it work or scale? I realize in some cases there are always going to be optimal solutions that will be over my head mathematically, but generally you can yield a solution that is within a reasonable range of optimal that is passable without knowing a ton of number theory in my experience. Where possible, I hope to learn algorithms along the way (such as the Sieve of Eratosthenes for prime ranges).
Coding execution: Given some pseudocode that we determine algorithmically will work, is the code written executed without redundancies and minimizing runtime?
Being more pythonic: Is something I'm not doing pythonic or can it be done simpler with some sort of library I don't know about? I believe this is mostly semantic, though in some cases can have large effects on performance (for instance, using
map()
instead of afor
loop to applyint()
).
I submitted the following code as a solution to Project Euler's #12. It's extremely slow, running in mean 7.13 seconds over 100 trials (I think; just using other submitted solutions as a benchmark. It seems as though solutions <1 seconds are generally decent.)
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def triangle_number(n):
for i in range(n):
n += i
return n
n = 1
while True:
if len(factors(triangle_number(n))) >= 500:
print n, triangle_number(n)
break
else:
n +=1
The code for the factors
function was borrowed from here.
Just to reiterate my prev. post, as I think it helps structure my weaknesses.
Coding methodology: Is the algorithm I used feasible or mostly correct? If not, how do I correct it and why won't it work or scale? I realize in some cases there are always going to be optimal solutions that will be over my head mathematically, but generally you can yield a solution that is within a reasonable range of optimal that is passable without knowing a ton of number theory in my experience. Where possible, I hope to learn algorithms along the way (such as the Sieve of Eratosthenes for prime ranges).
Coding execution: Given some pseudocode that we determine algorithmically will work, is the code written executed without redundancies and minimizing runtime?
Being more pythonic: Is something I'm not doing pythonic or can it be done simpler with some sort of library I don't know about? I believe this is mostly semantic, though in some cases can have large effects on performance (for instance, using
map()
instead of afor
loop to applyint()
).
I submitted the following code as a solution to Project Euler's #12. It's extremely slow, running in mean 7.13 seconds over 100 trials (I think; just using other submitted solutions as a benchmark. It seems as though solutions <1 seconds are generally decent.)
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def triangle_number(n):
for i in range(n):
n += i
return n
n = 1
while True:
if len(factors(triangle_number(n))) >= 500:
print n, triangle_number(n)
break
else:
n +=1
The code for the factors
function was borrowed from here.
Just to reiterate my prev. post, as I think it helps structure my weaknesses.
Coding methodology: Is the algorithm I used feasible or mostly correct? If not, how do I correct it and why won't it work or scale? I realize in some cases there are always going to be optimal solutions that will be over my head mathematically, but generally you can yield a solution that is within a reasonable range of optimal that is passable without knowing a ton of number theory in my experience. Where possible, I hope to learn algorithms along the way (such as the Sieve of Eratosthenes for prime ranges).
Coding execution: Given some pseudocode that we determine algorithmically will work, is the code written executed without redundancies and minimizing runtime?
Being more pythonic: Is something I'm not doing pythonic or can it be done simpler with some sort of library I don't know about? I believe this is mostly semantic, though in some cases can have large effects on performance (for instance, using
map()
instead of afor
loop to applyint()
).
I submitted the following code as a solution to Project Euler's #12Project Euler's #12. It's extremely slow, running in mean 7.13 seconds over 100 trials (I think; just using other submitted solutions as a benchmark. It seems as though solutions <1 seconds are generally decent.)
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def triangle_number(n):
for i in range(n):
n += i
return n
n = 1
while True:
if len(factors(triangle_number(n))) >= 500:
print n, triangle_number(n)
break
else:
n +=1
The code for the factors
function was borrowed from here.
Just to reiterate my prev. post, as I think it helps structure my weaknesses.
Coding methodology: Is the algorithm I used feasible or mostly correct? If not, how do I correct it and why won't it work or scale? I realize in some cases there are always going to be optimal solutions that will be over my head mathematically, but generally you can yield a solution that is within a reasonable range of optimal that is passable without knowing a ton of number theory in my experience. Where possible, I hope to learn algorithms along the way (such as the Sieve of Eratosthenes for prime ranges).
Coding execution: Given some pseudocode that we determine algorithmically will work, is the code written executed without redundancies and minimizing runtime?
Being more pythonic: Is something I'm not doing pythonic or can it be done simpler with some sort of library I don't know about? I believe this is mostly semantic, though in some cases can have large effects on performance (for instance, using
map()
instead of afor
loop to applyint()
).
I submitted the following code as a solution to Project Euler's #12. It's extremely slow, running in mean 7.13 seconds over 100 trials (I think; just using other submitted solutions as a benchmark. It seems as though solutions <1 seconds are generally decent.)
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def triangle_number(n):
for i in range(n):
n += i
return n
n = 1
while True:
if len(factors(triangle_number(n))) >= 500:
print n, triangle_number(n)
break
else:
n +=1
The code for the factors
function was borrowed from here.
Just to reiterate my prev. post, as I think it helps structure my weaknesses.
Coding methodology: Is the algorithm I used feasible or mostly correct? If not, how do I correct it and why won't it work or scale? I realize in some cases there are always going to be optimal solutions that will be over my head mathematically, but generally you can yield a solution that is within a reasonable range of optimal that is passable without knowing a ton of number theory in my experience. Where possible, I hope to learn algorithms along the way (such as the Sieve of Eratosthenes for prime ranges).
Coding execution: Given some pseudocode that we determine algorithmically will work, is the code written executed without redundancies and minimizing runtime?
Being more pythonic: Is something I'm not doing pythonic or can it be done simpler with some sort of library I don't know about? I believe this is mostly semantic, though in some cases can have large effects on performance (for instance, using
map()
instead of afor
loop to applyint()
).
I submitted the following code as a solution to Project Euler's #12. It's extremely slow, running in mean 7.13 seconds over 100 trials (I think; just using other submitted solutions as a benchmark. It seems as though solutions <1 seconds are generally decent.)
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def triangle_number(n):
for i in range(n):
n += i
return n
n = 1
while True:
if len(factors(triangle_number(n))) >= 500:
print n, triangle_number(n)
break
else:
n +=1
The code for the factors
function was borrowed from here.
Just to reiterate my prev. post, as I think it helps structure my weaknesses.
Coding methodology: Is the algorithm I used feasible or mostly correct, if? If not, how do I correct it and why won't it work or scale? I realize in some cases there are always going to be optimal solutions that will be over my head mathematically, but generally you can yield a solution that is within a reasonable range of optimal that is passable without knowing a ton of number theory in my experience. Where possible, I hope to learn algorithms along the way (such as the Sieve of Eratosthenes for prime ranges).
Coding execution: Given some pseudocode that we determine algorithmically will work, is the code written executed without redundancies and minimizing runtime.?
Being more pythonic: Is something I'm not doing pythonic or can it be done simpler with some sort of library I don't know about.? I believe this is mostly semantic, though in some cases can have large effects on performance (for instance, using map()
map()
instead of a forfor
loop to apply int()int()
).
I submitted the following code as a solution to Project Euler's #12; it's#12. It's extremely slow, running in mean 7.13 seconds over 100 trials (I think; just using other submitted solutions as a benchmark. It seems as though solutions <1 seconds are generally decent.)
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def triangle_number(n):
for i in range(n):
n += i
return n
n = 1
while True:
if len(factors(triangle_number(n))) >= 500:
print n, triangle_number(n)
break
else:
n +=1
Advice, criticism appreciated. The code for the factorsfactors
function was borrowed from here. .
Just to reiterate my prev. post, as I think it helps structure my weaknesses.
Coding methodology: Is the algorithm I used feasible or mostly correct, if not how do I correct it and why won't it work or scale? I realize in some cases there are always going to be optimal solutions that will be over my head mathematically, but generally you can yield a solution that is within a reasonable range of optimal that is passable without knowing a ton of number theory in my experience. Where possible, I hope to learn algorithms along the way (such as the Sieve of Eratosthenes for prime ranges).
Coding execution: Given some pseudocode that we determine algorithmically will work, is the code written executed without redundancies and minimizing runtime.
Being more pythonic: Is something I'm not doing pythonic or can it be done simpler with some sort of library I don't know about. I believe this is mostly semantic though in some cases can have large effects on performance (for instance using map() instead of a for loop to apply int()).
I submitted the following code as a solution to Project Euler's #12; it's extremely slow, running in mean 7.13 seconds over 100 trials (I think; just using other submitted solutions as a benchmark. It seems as though solutions <1 seconds are generally decent.)
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def triangle_number(n):
for i in range(n):
n += i
return n
n = 1
while True:
if len(factors(triangle_number(n))) >= 500:
print n, triangle_number(n)
break
else:
n +=1
Advice, criticism appreciated. The code for the factors function was borrowed from here.
Just to reiterate my prev. post, as I think it helps structure my weaknesses.
Coding methodology: Is the algorithm I used feasible or mostly correct? If not, how do I correct it and why won't it work or scale? I realize in some cases there are always going to be optimal solutions that will be over my head mathematically, but generally you can yield a solution that is within a reasonable range of optimal that is passable without knowing a ton of number theory in my experience. Where possible, I hope to learn algorithms along the way (such as the Sieve of Eratosthenes for prime ranges).
Coding execution: Given some pseudocode that we determine algorithmically will work, is the code written executed without redundancies and minimizing runtime?
Being more pythonic: Is something I'm not doing pythonic or can it be done simpler with some sort of library I don't know about? I believe this is mostly semantic, though in some cases can have large effects on performance (for instance, using
map()
instead of afor
loop to applyint()
).
I submitted the following code as a solution to Project Euler's #12. It's extremely slow, running in mean 7.13 seconds over 100 trials (I think; just using other submitted solutions as a benchmark. It seems as though solutions <1 seconds are generally decent.)
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
def triangle_number(n):
for i in range(n):
n += i
return n
n = 1
while True:
if len(factors(triangle_number(n))) >= 500:
print n, triangle_number(n)
break
else:
n +=1
The code for the factors
function was borrowed from here .