Skip to content

Instantly share code, notes, and snippets.

@krishnabhargav
Last active August 29, 2015 14:05
Show Gist options
  • Save krishnabhargav/cf4c5a382045a40d2cc8 to your computer and use it in GitHub Desktop.
Save krishnabhargav/cf4c5a382045a40d2cc8 to your computer and use it in GitHub Desktop.
functional way to determine if the elements in the sequence are all consecutive
(defn are-consecutive? [input]
(let [sorted (sort input)
diff (map - (rest sorted) sorted)
all-one? (every? #(= 1 %) diff)]
all-one?))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment