This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-15
Channels
- # architecture (2)
- # beginners (16)
- # boot (2)
- # cider (4)
- # clara (6)
- # cljs-dev (78)
- # cljsrn (3)
- # clojure (158)
- # clojure-austin (1)
- # clojure-belgium (1)
- # clojure-dusseldorf (19)
- # clojure-italy (8)
- # clojure-russia (3)
- # clojure-spec (77)
- # clojure-uk (61)
- # clojurescript (341)
- # cursive (9)
- # data-science (12)
- # datomic (18)
- # emacs (9)
- # fulcro (109)
- # hoplon (10)
- # juxt (2)
- # leiningen (2)
- # lumo (31)
- # off-topic (1)
- # om (4)
- # onyx (40)
- # parinfer (17)
- # re-frame (36)
- # reagent (19)
- # spacemacs (10)
- # vim (60)
- # yada (20)
Data la seguente struttura dati contenente un stato del gioco del tris, qual e' secondo voi il modo piu' elegante di verificare se :x
o :o
ha vinto?
(def game [[nil :o :x]
[nil :x :o]
[:x nil nil]])
Non sono particolarmente contento:
(defn row [game x] (map #((game x) %) [0 1 2]))
(defn column [game y] (map #((game %) y) [0 1 2]))
(defn diag1 [game] (map (fn [[x y]] ((game x) y)) [[0 0] [1 1] [2 2]]))
(defn diag2 [game] (map (fn [[x y]] ((game x) y)) [[0 2] [1 1] [2 0]]))
(defn all [game] (concat (map (partial row game) [0 1 2]) (map (partial column game) [0 1 2]) [(diag1 game) (diag2 game)]))
(defn win? [s triplets] (some true? (map (partial apply = s) triplets)))
(win? :x (all game))
true
(win? :o (all game))
nil
beh non male dai, volevo suggerire lo stesso, mi piacciono i diag