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

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-19 Thread Alex Nixon
Or use glue from flatland.useful.seq 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 wrote: > > > On Wednesday, 19 March 2014 09:39:56 UTC+5:30, Shantanu Ku

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)) (

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, fo

Re: Algorithm help

2009-07-17 Thread Mark Triggs
Heheh, three times slower but gives the wrong answer--maybe not a great trade-off :o) I'd misread the way the last if statements work in the Python version. I modified mine to read: (defn backtrack-all [c x y i j] (cond (or (zero? i) (zero? j)) #{""} (= (get x (dec i)) (get y

Re: Algorithm help

2009-07-17 Thread martin_clausen
Thanks. Your code is definitely much more idiomatic Clojure - and 3X faster. The lcs function does exactly what it is suppose to, but the backtrack-all function only returns the first LCS found(for the strings "AATCC" "ACACG" => ("ACC"), whereas the Python version returns all the LCSes found (for

Re: Algorithm help

2009-07-16 Thread Mark Triggs
Hi there, I had a bit of a go at converting the Python version into Clojure and removed the need to mutate an array. Because the 'lcs' function was basically just mapping over a list of i/j pairs and accumulating the resulting matrix, it seemed like a good candidate for reduce: (defn lcs [x y]

Re: Algorithm help

2009-07-16 Thread Laurent PETIT
Hi, I didn't test what I'll say, but it seems to me there are more than one problem: * when having in cond long conditions followed by a long expression, you should consider switching to "miser" mode by placing the expression on a new line, indented 2 characters from the condition start column