2015-02-18 5:06 GMT+01:00 Udayakumar Rayala <uday.ray...@gmail.com>: > Do you want the check if your initial code is working correctly? Because > when I ran it, this is the output with 100 numbers: > > (1 3 7 9 13 15 21 25 31 33 37 43 49 51 63 67 69 73 75 79 87 93 99) >
That is the correct output: http://en.wikipedia.org/wiki/Lucky_number There was a stupid mistake: it should return @current-list instead of current-list. > I have modified it like this. I have highlighted what I have changed.: > > (defn indexed-sieve [index this-list] > (keep-indexed > (fn [i v] > (if (= 0 (mod (inc i) index)) > nil > v)) > this-list)) > > (defn lucky-numbers [max-value] > (let [current-list *(atom (range 1 max-value)) * > > current-index *(atom 2)*] > > (while (< @current-index (count @current-list)) > (reset! current-list (indexed-sieve *@current-index* > @current-list)) > (reset! current-index (inc @current-index))) > @current-list)) > > This give the following output: > > (1 3 7 13 19 27 39 49 63 79 91) > > This seems more correct. > > You can further convert the while to loop recur to avoid using atoms. > There was a solution posted with recur. Two problems: - It gives a StackOverflowError with 1000000 and 100000. My solution has no problem with those values. At the moment I am trying 10000000, but it will take two hours two finish I am afraid. - It takes about two times as long to execute -- Cecil Westerhof -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.