Re: algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-28 Thread John Gabriele
Y'know, I'm guilty of not looking into flatland/useful enough. I'll have to try out codox on it, and see if that makes it easier for me to get acquainted with it. Thanks, Alex. On Wednesday, March 19, 2014 6:57:27 AM UTC-4, Alex Nixon wrote: Or use glue from flatland.useful.seq

Re: algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-28 Thread John Gabriele
Brilliant. Thanks, Shantanu! On Wednesday, March 19, 2014 12:09:56 AM UTC-4, Shantanu Kumar wrote: Something like this? (defn x [1 3 4 5 7 9 10 13]) (reduce (fn [a i] (let [y (last a) z (last y)] (if (and z (= (inc z) i)) (conj (pop a) (conj y i)) (conj a [i] [] x) Shantanu On

Re: algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-19 Thread Alex Nixon
Or use glue from flatland.useful.seq https://github.com/flatland/useful and: user= (glue conj [] (fn [s n] (= (inc (last s)) n)) [1 3 4 5 7 9 10 13]) ([1] [3 4 5] [7] [9 10] [13]) On 19 March 2014 04:10, Shantanu Kumar kumar.shant...@gmail.com wrote: On Wednesday, 19 March 2014 09:39:56

algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-18 Thread John Gabriele
If you've got a sorted list of numbers, for example: [1 3 4 5 7 9 10 13] where some are consecutive, how can you pull out the consecutive runs? That is, either produce [1 [3 4 5] 7 [9 10] 13]; or maybe something like [[1 7 13] [3 4 5] [9 10]] ; (the first vec is the elements

Re: algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-18 Thread Shantanu Kumar
Something like this? (defn x [1 3 4 5 7 9 10 13]) (reduce (fn [a i] (let [y (last a) z (last y)] (if (and z (= (inc z) i)) (conj (pop a) (conj y i)) (conj a [i] [] x) Shantanu On Wednesday, 19 March 2014 08:26:43 UTC+5:30, John Gabriele wrote: If you've got a sorted list of numbers, for

Re: algorithm help: extracting groups of consecutive ints from a sorted list

2014-03-18 Thread Shantanu Kumar
On Wednesday, 19 March 2014 09:39:56 UTC+5:30, Shantanu Kumar wrote: Something like this? (defn x [1 3 4 5 7 9 10 13]) Sory for the typo. Should be (def x [1 3 4 5 7 9 10 13]) (reduce (fn [a i] (let [y (last a) z (last y)] (if (and z (= (inc z) i)) (conj (pop a) (conj y i)) (conj a