Re: Why is this Project Euler solution slow?

2013-10-01 Thread David Chambers
> >> On Tue, Oct 1, 2013 at 11:22 AM, David Chambers < >> david.ch...@gmail.com > wrote: >> >> Last night I attempted Project Euler #5 <http://projecteuler.net/ >> **problem=5 <http://projecteuler.net/problem=5>> i

Re: Why is this Project Euler solution slow?

2013-10-01 Thread Stan Dyck
On Tue, Oct 1, 2013 at 11:22 AM, David Chambers > wrote: Last night I attempted Project Euler #5 <http://projecteuler.net/problem=5> in Clojure. The problem is as follows: > # Smallest multiple > > 2520 is the smallest number that can

Re: Why is this Project Euler solution slow?

2013-10-01 Thread David Chambers
1*13*17*19". > > > On Tue, Oct 1, 2013 at 11:22 AM, David Chambers > > > wrote: > >> Last night I attempted Project Euler #5<http://projecteuler.net/problem=5>in >> Clojure. The problem is as follows: >> >> > # Smallest multiple >>

Re: Why is this Project Euler solution slow?

2013-10-01 Thread Ben Wolfson
You can actually solve this problem quite directly. I just looked up my python solution and it's just "print 9*16*5*7*11*13*17*19". On Tue, Oct 1, 2013 at 11:22 AM, David Chambers wrote: > Last night I attempted Project Euler #5<http://projecteuler.net/problem=5>in &

Re: Why is this Project Euler solution slow?

2013-10-01 Thread Wes Freeman
Any brute force solution will be relatively slow. The fast solutions require a doing math to simplify. Wes On Tue, Oct 1, 2013 at 2:22 PM, David Chambers wrote: > Last night I attempted Project Euler #5<http://projecteuler.net/problem=5>in > Clojure. The problem is as follows: >

Why is this Project Euler solution slow?

2013-10-01 Thread David Chambers
Last night I attempted Project Euler #5 <http://projecteuler.net/problem=5>in Clojure. The problem is as follows: > # Smallest multiple > > 2520 is the smallest number that can be divided by each of the numbers > from 1 to 10 without any remainder. > > What is the small

Re: Project Euler problem in clojure

2013-06-20 Thread Alan Malloy
More importantly than any of these things, he is hanging onto the head of a very, very large sequence with (def lazytri (map triangle (range))). This will lead to serious memory pressure, and perhaps eventually a slowdown as this sequence takes up all the memory in his app and the GC strains to

Re: Project Euler problem in clojure

2013-06-20 Thread Meikel Brandmeyer (kotarak)
Hi, Am Donnerstag, 20. Juni 2013 15:19:40 UTC+2 schrieb John Holland: > > (defn triangle [n] (reduce + (range n))) > (def lazytri (lazy-seq (map triangle (range > > Some quick idea: here is a major difference in your clojure and your java implementation. You always recompute the whole sum f

Re: Project Euler problem in clojure

2013-06-20 Thread John Holland
OK, with a coding improvement (defn factors-sqrt [n] (filter #(= 0 (mod n %)) (range 1 (+ 1 (Math/sqrt n ) (defn num-of-factors [n] (* 2 (count (factors-sqrt n it works for 499. (Idea being factors come in pairs, each factor > sqrt(x) corresponds to one > sqrt(x)) Was it just runnin

Project Euler problem in clojure

2013-06-20 Thread John Holland
I'm working on problems at projecteuler.net in Clojure. There is a particular problem that my code doesn't seem to work for. The problem is: == The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 +

Re: Project Euler problem 28

2011-02-15 Thread Marek Stępniowski
On Feb 14, 11:13 pm, Andreas Kostler wrote: > Does anyone wanna have a look at my solution for Project Euler Problem 28? > > (defn diagonal-sum [n-max] > (+ 1 (reduce + > (map (fn[n] > (reduce + (map #(- (* n n) (* %

Re: Project Euler problem 28

2011-02-15 Thread Benny Tsai
single list. I find this quite handy. * It's a purely subjective thing, but I like using (inc x) and (dec x) when incrementing and decrementing x by 1, respectively. On Feb 14, 11:13 pm, Andreas Kostler wrote: > Hi all, > Does anyone wanna have a look at my solution for Project Euler

Re: Project Euler problem 28

2011-02-15 Thread Ken Wesson
On Tue, Feb 15, 2011 at 2:59 AM, Ken Wesson did NOT write: > (defn diagonal-sum-4 [n-max] >  (let [cores (.availableProcessors (Runtime/getRuntime)) >        step (* 2 cores)] >    (inc >      (reduce + >        (map get >          (doall >            (map #(future (diagonal-sum-4a n-max % step))

Re: Project Euler problem 28

2011-02-15 Thread Ken Wesson
On Tue, Feb 15, 2011 at 1:13 AM, Andreas Kostler wrote: > Hi all, > Does anyone wanna have a look at my solution for Project Euler Problem 28? > > (defn diagonal-sum [n-max] >        (+ 1 (reduce + >                (map (fn[n] >                      (reduce + (map #(

Project Euler problem 28

2011-02-14 Thread Andreas Kostler
Hi all, Does anyone wanna have a look at my solution for Project Euler Problem 28? (defn diagonal-sum [n-max] (+ 1 (reduce + (map (fn[n] (reduce + (map #(- (* n n) (* % (- n 1))) (range 4 (take-nth 2 (range 3 (+ 2 n-max

Re: Project Euler problem 14: Maybe it's me but hash maps don't seem to work

2010-10-10 Thread Stuart Halloway
Since collatz is defined for integer math, I would argue that the use of "quot" instead of "/" isn't a workaround at all -- "quot" is the right function for the job, and better communicates what the code is doing. That said, Mark is certainly right that we want feedback on the numeric support i

Re: Project Euler problem 14: Maybe it's me but hash maps don't seem to work

2010-10-07 Thread Sean Corfield
On Thu, Oct 7, 2010 at 7:42 PM, Jarl Haggerty wrote: > 1.  How do I get leiningen to use 1.3 when I type lein repl, right now > I have to compile a jar and execute it if I want to use the 1.3 > library. Specify these dependencies: :dependencies [[org.clojure/clojure "1.3.0-master-SNAPSHOT"

Re: Project Euler problem 14: Maybe it's me but hash maps don't seem to work

2010-10-07 Thread Jarl Haggerty
I try not to post twice in a row but I thought it was rude of me not to say thanks for the help. On Oct 7, 7:42 pm, Jarl Haggerty wrote: > I was using 1.2, I thought I posted that here but I don't see the > message.  I don't have the same problem in 1.3, but I have some > slightly tangental quest

Re: Project Euler problem 14: Maybe it's me but hash maps don't seem to work

2010-10-07 Thread Jarl Haggerty
I was using 1.2, I thought I posted that here but I don't see the message. I don't have the same problem in 1.3, but I have some slightly tangental questions. 1. How do I get leiningen to use 1.3 when I type lein repl, right now I have to compile a jar and execute it if I want to use the 1.3 lib

Re: Project Euler problem 14: Maybe it's me but hash maps don't seem to work

2010-10-07 Thread Mark Engelberg
On Thu, Oct 7, 2010 at 12:29 PM, Jarl Haggerty wrote: > I'm using clojure 1.2 OK, I stand corrected. Stuart's right. The problem is that you're getting mixed numeric types. When you do (collatz 113383) the sequence eventually hits 2482111348 which is a Long, not an Integer. When you divide by 2

Re: Project Euler problem 14: Maybe it's me but hash maps don't seem to work

2010-10-07 Thread Mark Engelberg
by having Clojure's collections defy the rules > of Java, unless you are calling them through the Java interfaces in an > interop scenario. > Clojure 1.3 also complicates the story since a number can now be represented in more than one way. For Project Euler problems especiall

Re: Project Euler problem 14: Maybe it's me but hash maps don't seem to work

2010-10-07 Thread Miki
FWIW: I've used the built in "memoize" and had not problem. You can view my solution at http://bitbucket.org/tebeka/euler-clj/src/tip/14.clj On Oct 6, 10:46 pm, Jarl Haggerty wrote: > Problem 14 on project Euler is to find the number under 1,000,000 that > is the start o

Re: Project Euler problem 14: Maybe it's me but hash maps don't seem to work

2010-10-07 Thread Stuart Halloway
defy the rules of Java, unless you are calling them through the Java interfaces in an interop scenario. Stu > Problem 14 on project Euler is to find the number under 1,000,000 that > is the start of the longest Collatz sequence. My solution is below, > basically it uses a hash ma

Project Euler problem 14: Maybe it's me but hash maps don't seem to work

2010-10-07 Thread Jarl Haggerty
Problem 14 on project Euler is to find the number under 1,000,000 that is the start of the longest Collatz sequence. My solution is below, basically it uses a hash map to cache the lengths of collatz sequences. But when I get to 113383 the collatz function just bounces between the numbers 1, 2

Re: Project Euler: Problem suggestions that show off clojure?

2009-10-16 Thread Meikel Brandmeyer
Hi, You can have a look here: http://clojure-euler.wikispaces.com. I chose the problems I solved because I found them interesting or because I had an idea how to solve them. I didn't look specifically for problems fitting to Clojure. (And in fact most of my solution look rather ugly when now loo

Project Euler: Problem suggestions that show off clojure?

2009-10-15 Thread Stan Dyck
I recently discovered Project Euler (http://projecteuler.net/) and have decided to take on some of the problems there to improve my clojure skills. I see from searching around that I'm not the first to have this idea so I thought I'd ask if anyone on this list who has done this c

Re: Project Euler

2008-11-22 Thread Rock
I had no idea, great! Thanks. Rock On Nov 22, 11:38 pm, Meikel Brandmeyer <[EMAIL PROTECTED]> wrote: > Hi Rock, > > Am 22.11.2008 um 22:23 schrieb Rock: > > >http://code.google.com/p/project-euler-lisp/ > > There is alsohttp://clojure-euler.wikispaces.com. > &g

Re: Project Euler

2008-11-22 Thread Meikel Brandmeyer
Hi Rock, Am 22.11.2008 um 22:23 schrieb Rock: http://code.google.com/p/project-euler-lisp/ There is also http://clojure-euler.wikispaces.com. Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature

Project Euler

2008-11-22 Thread Rock
Clojure is one of the programming languages being used at Project Euler. I've been working out the problems (got more than 30 solved so far). But I thought it could be helpful to post the solutions, so that anyone curious can have a look and see how they were (very humbly) implemented by m