Good to know, thank you Ben :)
On Jan 13, 10:49 am, B Smith-Mannschott wrote:
> On Thu, Jan 13, 2011 at 17:36, Benny Tsai wrote:
> > (conj) will add items to different places in the collection, depending
> > on the type of the collection. For a set, this can be at either the
> > end OR the begi
Right, my bad. It was a typo. (sorted-set (f))
Thanks for your help.
On Jan 13, 12:16 pm, Benny Tsai wrote:
> Armando's suggested change worked fine for me.
>
> (use '[clojure.contrib.lazy-seqs :only (primes)])
>
> (defn prime-factors [n]
> (let [f (some #(if (= 0 (rem n %)) %) primes)]
> (
On Thu, Jan 13, 2011 at 17:36, Benny Tsai wrote:
> (conj) will add items to different places in the collection, depending
> on the type of the collection. For a set, this can be at either the
> end OR the beginning.
For a (hashed) set, this can be *anywhere* (between existing elements too).
FTF
Replying to myself :-)
After some pondering, it DOES make sense if I pay attention to what
you guys saying: for unordered set conj can nondeterministically add
either at beginning OR end.
On Jan 13, 12:40 pm, Vitaly Peressada wrote:
> Benny, thanks for your explanation. It does make sense and cl
Benny, thanks for your explanation. It does make sense and clarifies
the issue. What DOES NOT make sense is
Clojure 1.2.0
user=> (conj (conj (conj #{4} 3) 2) 1)
#{1 2 3 4}
user=> (conj (conj (conj #{6857} 1471) 839) 71)
#{71 839 6857 1471}
Any ideas?
On Jan 13, 11:36 am, Benny Tsai wrote:
> (
Armando's suggested change worked fine for me.
(use '[clojure.contrib.lazy-seqs :only (primes)])
(defn prime-factors [n]
(let [f (some #(if (= 0 (rem n %)) %) primes)]
(println "n:" n ", f:" f)
(if (= f n)
(sorted-set f)
(conj (prime-factors (/ n f)) f
user=> (prime-fac
Armando, thanks for a plausible explanation. Here is what happened
after I made the suggested change:
user=> (prime-factors 600851475143)
n: 600851475143 , f: 71
n: 8462696833 , f: 839
n: 10086647 , f: 1471
n: 6857 , f: 6857
#
I guess this something subtle with unordered vs. sorted-set as
implici
(conj) will add items to different places in the collection, depending
on the type of the collection. For a set, this can be at either the
end OR the beginning.
For this problem, the output is built by:
(conj (conj (conj #{6857} 1471) 839) 71)
which is equivalent to:
(-> #{6857} (conj 1471) (c
A literal set is a unordered hash-set. To get the factors in order
change #{f} for (sorted-set f).
On Jan 13, 7:09 am, Vitaly Peressada wrote:
> The following solution by mtgred for http://clojure-
> euler.wikispaces.com/">Project Euler Clojure problem 003 uses
> implicit recursion.
>
>
> (use '
The following solution by mtgred for http://clojure-
euler.wikispaces.com/">Project Euler Clojure problem 003 uses
implicit recursion.
(use '[clojure.contrib.lazy-seqs :only (primes)])
(defn prime-factors [n]
(let [f (some #(if (= 0 (rem n %)) %) primes)]
(if (= f n) #{f} (conj (prime-facto
10 matches
Mail list logo