Skip to content

Instantly share code, notes, and snippets.

@slabko
Forked from skuro/nonograms-dojo.clj
Last active September 14, 2016 19:43
Show Gist options
  • Save slabko/087020f9914722ce17948578662a816f to your computer and use it in GitHub Desktop.
Save slabko/087020f9914722ce17948578662a816f to your computer and use it in GitHub Desktop.
(ns edge.transform)
(def test-matrix (repeat 9 [1 2 3 4 5 6 7 8 9]))
(defn- average-color [colors]
(let [s (sum colors)
])
(color 2))
(defn avg
[numbers]
(/ (apply + numbers) (count numbers)))
(defn scale-row
"Row is a vector that is averaged and scaled into a vector or 'size' items."
[target-length row]
(let [source-length (count row)
scale (/ source-length target-length)
row' (partition scale row)
target-row (map avg row')]
target-row))
(defn scale-matrix [hscale vscale matrix]
(map (partial scale-row hscale) (apply map list (map (partial scale-row vscale) matrix)))
)
@slabko
Copy link
Author

slabko commented Sep 14, 2016

(ns edge.transform)

(def test-matrix (repeat 9 [1 2 3 4 5 6 7 8 9]))

(defn- average-color [colors](let [s %28sum colors%29
])
(color 2))

(defn avg
[numbers](/ %28apply + numbers%29 %28count numbers%29))

(defn scale-row
"Row is a vector that is averaged and scaled into a vector or 'size' items."
[target-length row]

(let [source-length (count row)
      scale (/ source-length target-length)
      row' (partition scale row)
      target-row (map avg row')]
        target-row))

(defn scale-matrix [hscale vscale matrix](map %28partial scale-row hscale%29 %28apply map list %28map %28partial scale-row vscale%29 matrix%29%29)
)

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