Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active November 5, 2015 02:57
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 amirrajan/6090464af6fac505db1b to your computer and use it in GitHub Desktop.
Save amirrajan/6090464af6fac505db1b to your computer and use it in GitHub Desktop.
(def five-by-five [[:. :. :. :. :.]
[:. :. :. :. :.]
[:. :. :. :. :.]
[:. :. :. :. :.]
[:. :. :. :. :.]])
(defn to-coordinates [board]
(into []
(flatten
(map-indexed
(fn [row-pos row]
(map-indexed
(fn [col-pos piece]
{:row-pos row-pos
:col-pos col-pos
:piece piece}) row)) board))))
@camdez
Copy link

camdez commented Nov 5, 2015

Something like this?

(defn to-coordinates2 [board]
  (mapcat (fn [col col-idx]
            (map-indexed #(array-map :col-pos col-idx :row-pos %1 :piece %2) col))
          board
          (range)))

Or, equivalently:

(defn to-coordinates3 [board]
  (mapcat (fn [col col-idx]
            (map-indexed (fn [row-idx piece]
                           {:col-pos col-idx :row-pos row-idx :piece piece})
                         col))
          five-by-five
          (range)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment