Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

12.18.2008

New (small) factoring library

So, this is the result of repeated use of several factoring-oriented functions for project euler. It's quite small, and any semi-competent programmer could probably come up with a faster or more efficient solution, but these were mine and they work perfectly well for my purposes. Everything is pretty straightforward, I figured the docstring was enough documentation and it isn't commented, but use it if you want. Everything I write, unless it says otherwise (which it won't unless it's for a job or for someone else to sell) is released under the GPL, despite my general perception that no one will ever want to reproduce it. In any event, the library is here.
I'm particularly happy with the primefactor function. It's my first successful (and actually useful) attempt at recursion, and it works very well. As the docstring suggests, the getprimes function (which is utilized by primefactor) slows down around n = 100000 or so, but I've optimized it the best I can, and I think it's fine for most practical applications. Anyway, enjoy.

7.12.2008

Project Euler

I recently discovered an awesome site, projecteuler.net, which has 202 mathematically-based programming tests. This is really helpful to someone like me who's learning a language and needs some practice, but doesn't have to program for his or her job. You can download my solution to problem three, in python, (preferably after you've solved it yourself) at tauntaun.10gbfreehost.com/code/problem3.zip
If you know of any other similar sites that supply programming challenges, I'd love to hear about them in the comments. Unfortunately, I have a sneaking suspicion that no one but me will ever see this post.
I've also tried the quizzes at pythonchallenge.org, but those seem to move at a much faster rate and, well, I'm a little slow.