If you want to do this, you can do it simpler, without the loop and temp var:

(defn twice-composite? [n]
  (->> (take-while #(< % n) prime-seq)
    (every #(or (divides? (* 2 %) n)
                (not (divides? % n))))

but this is not what you want.  See the hints I sent you off the list.

On Wed, Nov 3, 2010 at 2:34 PM, Dan Kefford <dan_keff...@hotmail.com> wrote:
> One idea that I had was to inline the factoring logic into twice-
> composite. Who cares about the factors? We just want to know if there
> are two or not:
>
> (defn twice-composite? [n]
>  (loop [ps prime-seq
>         tmp n
>         p-count 0]
>    (if (< 2 p-count)
>      false
>      (if (= 1 tmp)
>        (= 2 p-count)
>        (let [p (first ps)]
>          (if (divides? tmp p)
>            (recur ps (quot tmp p) (inc p-count))
>            (recur (rest ps) tmp p-count))))))
> )
>
> But this lead to even slower code.
>
> On Nov 3, 2:15 pm, Mark Engelberg <mark.engelb...@gmail.com> wrote:
>> Your Clojure implementation of your particular approach is reasonable,
>> but you need a cleverer approach.  I'll send you a hint offline.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
Cheers,
Leif

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to