Skip to content

Instantly share code, notes, and snippets.

@Heliosmaster
Forked from skuro/gist:3286e7a53d4938437ed1
Last active August 29, 2015 14:18
Show Gist options
  • Save Heliosmaster/a20812f0ee4505818a51 to your computer and use it in GitHub Desktop.
Save Heliosmaster/a20812f0ee4505818a51 to your computer and use it in GitHub Desktop.
(ns minesweeper-dojo.core)
;; written by Davide Taviani and Mohammad Noureldin
(def input1 [3 1 1])
(defn is-full-of-mines? [rows cols mine-count]
(= (+ mine-count 1)
(* rows cols)))
(defn allows-zero? [rows cols mine-count]
(>= (* rows cols) (+ mine-count 4))
)
(defn impossible? [rows cols mine-count]
(not (allows-zero? rows cols mine-count)))
(defn allows-mines-on-one-side? [rows cols mine-count]
(or (> (quot (- (* rows cols) mine-count) rows) 1)
(> (quot (- (* rows cols) mine-count) cols) 1))
)
(defn solvable? [input]
(let [rows (first input)
cols (second input)
mine-count (last input)]
(cond
(or (= rows 1)
(= cols 1)
(is-full-of-mines? rows cols mine-count)
(allows-mines-on-one-side? rows cols mine-count)) true
(impossible? rows cols mine-count) false
:else "I don't know"
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment