[plt-scheme] Project Euler was Hash Table implementation
This is a very nice library. I could have saved quite a bit of time
if I had these to start with.
Looking at the hash table problem I noticed that mzscheme is built on
gmp, and gmp has a good deal of the low level functions implemented,
extended gcd and modular exponentiation, for example. Is there some
way of bringing them into mzscheme?
On 8/5/07, Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
> Grant Rettke wrote:
> > On 8/3/07, Mark Engelberg <mark.engelberg at gmail.com> wrote:
> >> Anyone else want to comment on the relative strengths of languages for
> >> Project Euler?
>
> The numeric tower of R5RS is really shining when solving these problem.
>
> Here is how I find reals solution of a second degree equation:
>
> (define (second-degree-solutions a b c)
> ; return list of solutions to a a x^2 + b x + c = 0
> (let ([d (- (* b b) (* 4 a c))])
> (cond
> [(< d 0)
> '()]
> [(= d 0)
> (list (/ b (* -2 a)))]
> [else
> (let ([sqrt-d (sqrt d)])
> (list (/ (- (- b) sqrt-d) (* 2 a))
> (/ (+ (- b) sqrt-d) (* 2 a))))])))
>
> For example the equation 2x^2-8=0 has the solutions -2 and 2:
>
> > (second-degree-solutions 2 0 -8)
> (-2 2)
>
> The thing to notice is that I get exact solutions, even
> though I used sqrt above.
>
> Finding *integer* solutions is now easy:
>
> (define (second-degree-integer-solutions a b c)
> ; return list of integer solutions to a x^2 + b x + c = 0
> (filter integer? (second-degree-solutions a b c)))
>
> The tools I use to solve Project Euler problems are:
>
> - the following library of number theory functions, released
> through PLaneT today:
> http://www.scheme.dk/blog/2007/08/number-theory.html
>
> - Herman's memoize package (remember to use memoize*)
>
> - Eager Comprehensions
>
> > It is a lot of fun to read everyone's solution to the problems on
> > project Euler.
>
> Sure is.
>
> --
> Jens Axel Søgaard
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>