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