-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
;; https://4clojure.oxal.org/#/problem/073 | ||
|
||
(ns ex.q073) | ||
|
||
(defn ans | ||
"Problem 73, Analyze a Tic-Tac-Toe Board" | ||
[board] | ||
(letfn [(win? [coll] (if (and (apply = coll) (not= (first coll) :e)) (first coll) nil)) | ||
(transpose [coll] (apply map vector coll)) | ||
(diag [coll i] (map (fn [[idx row]] (row idx)) (zipmap i coll)))] | ||
(first (drop-while nil? | ||
(lazy-cat | ||
(map win? board) | ||
(map win? (transpose board)) | ||
(map win? [(diag board [0 1 2]) (diag board [2 1 0])])))))) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
;; https://4clojure.oxal.org/#/problem/073 | ||
|
||
(ns ex.q073-test | ||
(:require [clojure.test :as t] | ||
[ex.q073 :as sut])) | ||
|
||
(t/deftest test-q73 | ||
(t/testing "Problem 73, Analyze a Tic-Tac-Toe Board" | ||
(t/is (= nil (sut/ans [[:e :e :e] | ||
[:e :e :e] | ||
[:e :e :e]]))) | ||
(t/is (= :x (sut/ans [[:x :e :o] | ||
[:x :e :e] | ||
[:x :e :o]]))) | ||
(t/is (= :o (sut/ans [[:e :x :e] | ||
[:o :o :o] | ||
[:x :e :x]]))) | ||
(t/is (= nil (sut/ans [[:x :e :o] | ||
[:x :x :e] | ||
[:o :x :o]]))) | ||
(t/is (= :x (sut/ans [[:x :e :e] | ||
[:o :x :e] | ||
[:o :e :x]]))) | ||
(t/is (= :o (sut/ans [[:x :e :o] | ||
[:x :o :e] | ||
[:o :e :x]]))) | ||
(t/is (= nil (sut/ans [[:x :o :x] | ||
[:x :o :x] | ||
[:o :x :o]]))))) |