Skip to content

Instantly share code, notes, and snippets.

@visibletrap
Last active August 10, 2016 00:49
Show Gist options
  • Save visibletrap/b54055d438e020424ba8ae6f3fba9634 to your computer and use it in GitHub Desktop.
Save visibletrap/b54055d438e020424ba8ae6f3fba9634 to your computer and use it in GitHub Desktop.
(let [arr [[0, 0, 0, 2, 2],
[1, 1, 7, 4, 4],
[2, 2, 4, 2, 4],
[2, 1, 4, 4, 4],
[2, 7, 7, 4, 4],
[4, 6, 6, 0, 4],
[4, 4, 6, 4, 4],
[4, 4, 6, 4, 4]]]
(->> (flatten arr)
(partition-by identity)
(map (juxt first count))))
; Explanation
(->> (flatten arr)
; (0 0 0 2 2 1 1 7 4 4 2 2 4 2 4 2 1 4 4 4 2 7 7 4 4 4 6 6 0 4 4 4 6 4 4 4 4 6 4 4)
(partition-by identity)
; ((0 0 0) (2 2) (1 1) (7) (4 4) (2 2) (4) (2) (4) (2) (1) (4 4 4) (2) (7 7) (4 4 4) (6 6) (0) (4 4 4) (6) (4 4 4 4) (6) (4 4))
(map (juxt first count)))
; ([0 3] [2 2] [1 2] [7 1] [4 2] [2 2] [4 1] [2 1] [4 1] [2 1] [1 1] [4 3] [2 1] [7 2] [4 3] [6 2] [0 1] [4 3] [6 1] [4 4] [6 1] [4 2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment