Hi, all:

I'm tring to solve such a problem: Given a string consisting of "1" and 
"0", find all the locations of "1", and print them in the format of 
intervals.

For example: "00101110101110" => 3, 5-7, 9, 11-13

Here is my solution:

(defn bar [x]
  (letfn [(foo [mystr]
            (->>
              (map-indexed vector mystr)
              (filter #(= (second %) \1))
              (map (comp inc first))
              (partition-all 2 1)
              (filter #(= 2 (count %)))))]
    (let [y (map #(if (> (- (second %) (first %)) 1) (print (first %) ", " 
(second %) "-")) (foo x))]
      (print (ffirst y) "-" y (last (last (foo x)))))))


With the code above, I got many nils in the result:

(bar "00101110101110") => 3 , 5 -nil - (nil nil 7 , 9 -nil 9 , 11 -nil nil 
nil nil) 13

How can I remove them?

And, is there any way to make my code more concise?



-- 
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.

Reply via email to