-
-
Save Heliosmaster/a20812f0ee4505818a51 to your computer and use it in GitHub Desktop.
This file contains 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 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