On Sun, 20 Mar 2011 08:47:30 -0700 (PDT)
Christian wrote:
> Hello Tassilo!
>
> I've tested your code and looked at the Clojure Documentation for
> 'for'. Given that, I have written
>
> (reduce +(filter even? (for [fib (fib-seq) :while (< fib 400)]
> fib)))
>
> This gives me the error 'cloj
>> Do you have any resources or books that help with such things? (Taking
>> a problem and solving it the way you did)
>
> I think, my suggestions are not specific to clojure, but they apply to
> any functional language. All of them have functions for filtering
> sequences, applying a function t
Christian writes:
Hi Christian,
> I would like to thank you for this suggestion and the way you
> translated the problem statement into code!
Thanks for the compliment. :-)
> Do you have any resources or books that help with such things? (Taking
> a problem and solving it the way you did)
I t
Hi
On 20 March 2011 17:47, Christian wrote:
> Hello Tassilo!
>
> I've tested your code and looked at the Clojure Documentation for
> 'for'. Given that, I have written
>
> (reduce +(filter even? (for [fib (fib-seq) :while (< fib 400)]
> fib)))
Or using Daniel's suggestion:
(reduce + (filter
Hello Tassilo!
I've tested your code and looked at the Clojure Documentation for
'for'. Given that, I have written
(reduce +(filter even? (for [fib (fib-seq) :while (< fib 400)]
fib)))
This gives me the error 'clojure.lang.LazySeq cannot be cast to
clojure.lang.IFn'.
I think this is because
On Mar 20, 10:22 am, Christian wrote:
> valued fibonacci terms under four million. (I did not know how to
> specify a predicate depending on the value of (fib-seq) to check if
> the value is under 4 million.)
For this there is #'take-while:
(take-while #(< % 400) ...)
Daniel
--
You receiv
On 20/03/2011, at 8:25 PM, Christian wrote:
> Hello Andreas!
>
> Thanks for your swift reply. I'll try to explain the reasoning behind
> my code.
>
> In the Clojure Reference I found the function into, which is described
> like so:
>
> Usage: (into to from)
> "Returns a new coll consisting of
Hello Andreas!
Thanks for your swift reply. I'll try to explain the reasoning behind
my code.
In the Clojure Reference I found the function into, which is described
like so:
Usage: (into to from)
"Returns a new coll consisting of to-coll with all of the items of
from-coll conjoined."
I'm curren
Christian writes:
Hi Christian,
> For those unfamiliar, Project Euler Problem 2 states:
> find the sum of all
Sounds like (reduce + ...).
> even-valued fibonacci terms
Sounds like (filter even? ...)
> that are less than four million.
Hm, that's a bit more challenging. I think, you could go
Hi Christian,
What you're trying to do is to build up a vector with the last element of the
vector being the answer to your problem:
(last answer)
=> 4613732
You're trying to use cons (conj) to build up that list.
Now, your function below never terminates because you're:
a) Not actually buildin
I've tried Project Euler 2 now.
For those unfamiliar, Project Euler Problem 2 states: find the sum of
all even-valued fibonacci terms that are less than four million.
Let's assume that I have the code to fill the vector:
(def fib-seq
((fn rfib [a b]
(lazy-seq (cons a (rfib b (+ a b)
11 matches
Mail list logo