-
-
Save pieter-van-prooijen/f34ffcaef1ca9d71d801cc35a26763ad to your computer and use it in GitHub Desktop.
Nonograms dojo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns nonogram.core | |
(:require [mikera.image.core :as image] | |
[mikera.image.dither :as dither])) | |
;; create column and row wise matrices | |
(defn create-matrices [image-path] | |
(let [img (-> (image/load-image image-path) | |
(image/resize 20 20) | |
#_(dither/dither (dither/mono-palette-function)))] | |
[(for [x (range 20) y (range 20)] | |
(if (zero? (image/get-pixel img x y)) 0 1)) | |
(for [x (range 20) y (range 20)] | |
(if (zero? (image/get-pixel img y x)) 0 1))])) | |
;; count the one sequences in a range | |
(defn one-counts [row-or-column] | |
(->> (partition-by identity row-or-column) | |
(remove (fn [range] (= 0 (first range)))) | |
(map count))) | |
;; do for all rows and columns | |
(defn all-one-counts [image-path] | |
(let [[per-column per-rows] (create-matrices image-path)] | |
(->> (....)))) | |
(comment (create-matrices "resources/100px-Greek_lc_lamda_thin.svg.png")) | |
((0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) | |
(0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0) | |
(0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0) | |
(0 1 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0) | |
(0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0) | |
(0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0) | |
(0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0) | |
(0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0) | |
(0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0) | |
(0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0) | |
(0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0) | |
(0 0 0 0 0 1 1 1 1 0 1 1 0 0 0 0 0 0 0 0) | |
(0 0 0 0 0 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0) | |
(0 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0) | |
(0 0 0 1 1 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0) | |
(0 0 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1) | |
(0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 1 1) | |
(0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1) | |
(1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0) | |
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment