Re: Lucky Numbers again

2015-02-19 Thread Cecil Westerhof
2015-02-19 23:25 GMT+01:00 Steve Miner : > I found a better data structure for calculating lucky numbers. The > contrib library data.avl (from Michał Marczyk) has a persistent sorted-set > that supports nth. This runs much faster than my previous attempts. > > (require '[clojure.data.avl :as avl

Re: Lucky Numbers again

2015-02-19 Thread Steve Miner
I found a better data structure for calculating lucky numbers. The contrib library data.avl (from Michał Marczyk) has a persistent sorted-set that supports nth. This runs much faster than my previous attempts. (require '[clojure.data.avl :as avl]) (defn lucky-avl ([max] (lucky-avl 1 (apply a

Re: Lucky Numbers again

2015-02-18 Thread Cecil Westerhof
2015-02-18 20:47 GMT+01:00 Steve Miner : > One more try. This time using the int-map contrib library. (Thanks to > Zack Tellman.) > > Warning: I'm assuming that the int-set seq is automagically sorted so I > can reliably turn it back into a vector without sorting. It seems to be > stable at leas

Re: Lucky Numbers again

2015-02-18 Thread Cecil Westerhof
2015-02-18 18:25 GMT+01:00 Cecil Westerhof : > 2015-02-18 16:31 GMT+01:00 Tassilo Horn : > >> Here's my version: >> >> --8<---cut here---start->8--- >> (defn drop-every-nth [c n] >> (keep-indexed (fn [i el] >> (if (zero? (mod (inc i) n)) nil

Re: Lucky Numbers again

2015-02-18 Thread Cecil Westerhof
2015-02-18 20:47 GMT+01:00 Steve Miner : > One more try. This time using the int-map contrib library. (Thanks to > Zack Tellman.) > ​Not installed on my system. So for the moment I let it rest. -- Cecil Westerhof -- You received this message because you are subscribed to the Google Groups "C

Re: Lucky Numbers again

2015-02-18 Thread Steve Miner
One more try. This time using the int-map contrib library. (Thanks to Zack Tellman.) Warning: I'm assuming that the int-set seq is automagically sorted so I can reliably turn it back into a vector without sorting. It seems to be stable at least. I wanted a vector for fast nth access. (Nth

Re: Lucky Numbers again

2015-02-18 Thread Cecil Westerhof
2015-02-18 16:31 GMT+01:00 Tassilo Horn : > Here's my version: > > --8<---cut here---start->8--- > (defn drop-every-nth [c n] > (keep-indexed (fn [i el] > (if (zero? (mod (inc i) n)) nil el)) > c)) > > (defn lucky-numbers [n]

Re: Lucky Numbers again

2015-02-18 Thread Cecil Westerhof
2015-02-18 16:31 GMT+01:00 Tassilo Horn : > Cecil Westerhof writes: > > > One problem is that max-value is used in the doc-string also, so if it > > changes, it has to be done at two places. Is there a way around this? > > I wouldn't specify a max-value at all. Some users might have enough > tim

Re: Lucky Numbers again

2015-02-18 Thread Tassilo Horn
Cecil Westerhof writes: > One problem is that max-value is used in the doc-string also, so if it > changes, it has to be done at two places. Is there a way around this? I wouldn't specify a max-value at all. Some users might have enough time to wait for the result, have faster machines, might u

Lucky Numbers again

2015-02-18 Thread Cecil Westerhof
I have updated my Lucky Numbers code: (defn indexed-sieve "Removes all elements that have a position that is a multiply of index. With first position counting as 1." [index this-list] (keep-indexed (fn [i v] (if (= 0 (mod (inc i) index)) n