Hi John,

'partition' will be useful for you, as Moritz pointed out.

(partition 2 1 [1 2 3 4]) -> ((1 2) (2 3) (3 4))
(partition 2 1 [1 2 2 4]) -> ((1 2) (2 2) (2 4))
(partition 2 1 [1 2 2 2]) -> ((1 2) (2 2) (2 2))

(some #(= % [2 2]) (partition 2 1 [1 2 3 4])) -> nil
(some #(= % [2 2]) (partition 2 1 [1 2 2 4])) -> true
(some #(= % [2 2]) (partition 2 1 [1 2 2 2])) -> true

(filter #(= % [2 2]) (partition 2 1 [1 2 3 4])) -> ()
(filter #(= % [2 2]) (partition 2 1 [1 2 2 4])) -> ((2 2))
(filter #(= % [2 2]) (partition 2 1 [1 2 2 2])) -> ((2 2) (2 2))

I'm sorry I can't recognize whether you need a pair of 2s or two pairs of 
2s.

If you need one or more pairs of 2s, do
(defn has22 [coll] (boolean (some #(= % [2 2]) (partition 2 1 coll))))
(has22 [1 2 3 4]) -> false
(has22 [1 2 2 4]) -> true
(has22 [1 2 2 2]) -> true

If you need two or more pairs of 2s, do
(defn has222 [coll] (< 1 (count (filter #(= % [2 2]) (partition 2 1 
coll)))))
(has222 [1 2 3 4]) -> false
(has222 [1 2 2 4]) -> false
(has222 [1 2 2 2]) -> true

Regards,
Yoshinori Kohyama

-- 
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
  • [no subject] John Holland
    • Re: Mark Rathwell
      • Re: Moritz Ulrich
    • Re: Yoshinori Kohyama
      • Re: DeWitt Clinton
        • Re: nicolas.o...@gmail.com
          • Re: Yoshinori Kohyama
            • Re: nicolas.o...@gmail.com
              • Re: Yoshinori Kohyama
    • Re: Ben Smith-Mannschott

Reply via email to