Skip to content

Instantly share code, notes, and snippets.

@m00nlight
Forked from skuro/nonograms-dojo.clj
Last active September 14, 2016 19:28
Show Gist options
  • Save m00nlight/ecb132ce2c294cf29c05814a65a23844 to your computer and use it in GitHub Desktop.
Save m00nlight/ecb132ce2c294cf29c05814a65a23844 to your computer and use it in GitHub Desktop.
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1)
(1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 0 1 1 1 0)
(0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1)
(1 1 1 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 1)
(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
(0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0)
(1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1)
(0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0)
(0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 0 1 1 0 0)
(ns banana-server.handler
(:use mikera.image.core )
(:use hiccup.core)
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]))
(def banana (load-image-resource "banana.bmp"))
(def pixels (get-pixels banana))
(for [pixel pixels]
(println pixel))
(defn transpose [matrix]
(apply map list matrix))
(def black-white (map (fn [x] (if (= x -1) 0 1)) pixels))
(def grid (partition 20 (vec black-white)))
(defn calc-row
[row]
(map #(count %)
(filter (fn [x] (= (first x) 1)) (partition-by #(= % 1) row))))
(defn calc-rows
[grid]
(map #(calc-row %) grid))
(def row-answer (calc-rows grid))
(def col-answer (calc-rows (transpose grid)))
(def row-str (clojure.string/join
"|"
(map #(clojure.string/join "," %)
col-answer)))
(def col-str (clojure.string/join
"<br />" (map #(clojure.string/join "," %) row-answer)))
(defroutes app-routes
(GET "/" [] (str row-str col-str))
(GET "/nonogram" [] {:row row-answer, :col col-answer})
(route/not-found "Not Found"))
(def app
(wrap-defaults app-routes site-defaults))
1,2,2|1,4,1|1,6|7,1|8|1,6|1,5|1,6|1,6|1,6|1,6|8|1,6|8|1,7|2,7|2,9|9,1|10,1|4,4,11,2
1,2
1,3
1,3
6,1,3
2,8,5
6,1,7
20
19
19
1,16,1
2,13,1
1,8,2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment