Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created March 8, 2017 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/3e82c446131ebf242c20d33b10864d3a to your computer and use it in GitHub Desktop.
Save deque-blog/3e82c446131ebf242c20d33b10864d3a to your computer and use it in GitHub Desktop.
;; Partitioning by owner of the board gives contiguous sequences
(let [first-line (map vector (repeat 0) (range 0 16))]
(partition-by #(board/get-owner-at board %) first-line))
;; Contiguous sequences of coordinates
=>
(([0 0]) ([0 1] [0 2] [0 3] [0 4]) ([0 5])
([0 6]) ([0 7]) ([0 8] [0 9]) ([0 10])
([0 11] [0 12] [0 13] [0 14] [0 15]))
;; Making some windows out of it
(partition 3 1 *1)
=>
((([0 0]) ([0 1] [0 2] [0 3] [0 4]) ([0 5])) ;; First window
(([0 1] [0 2] [0 3] [0 4]) ([0 5]) ([0 6])) ;; Second window
(([0 5]) ([0 6]) ([0 7]))
(([0 6]) ([0 7]) ([0 8] [0 9]))
(([0 7]) ([0 8] [0 9]) ([0 10]))
(([0 8] [0 9]) ([0 10]) ([0 11] [0 12] [0 13] [0 14] [0 15])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment