Skip to content

Instantly share code, notes, and snippets.

@fronx
Forked from anonymous/fronx-4clojure-solution73.clj
Created September 16, 2011 17:49
Show Gist options
  • Select an option

  • Save fronx/1222682 to your computer and use it in GitHub Desktop.

Select an option

Save fronx/1222682 to your computer and use it in GitHub Desktop.

Revisions

  1. fronx revised this gist Sep 16, 2011. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion fronx-4clojure-solution73.clj
    Original file line number Diff line number Diff line change
    @@ -13,4 +13,18 @@
    (map (fn [row] (count (filter #(= player %) row))))
    (filter #(= % 3))
    seq))
    [:x :o])))
    [:x :o])))

    ; [
    ; ; rows
    ; [a b c]
    ; [d e f]
    ; [g h i]
    ; ; columns
    ; [a d g]
    ; [b e h]
    ; [c f i]
    ; ; diagonals
    ; [a e i]
    ; [g e c]
    ; ]
  2. fronx revised this gist Sep 16, 2011. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion fronx-4clojure-solution73.clj
    Original file line number Diff line number Diff line change
    @@ -12,4 +12,5 @@
    (vector (map #((m (- 2 %)) %) idx)))) ; diagonal 2
    (map (fn [row] (count (filter #(= player %) row))))
    (filter #(= % 3))
    seq))
    seq))
    [:x :o])))
  3. fronx revised this gist Sep 16, 2011. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions fronx-4clojure-solution73.clj
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,10 @@
    (filter
    (fn win? [player]
    (->> (let [idx [0 1 2]]
    (concat m
    (map (fn [i] (map #(% i) m)) idx)
    (vector (map #((m %) %) idx))
    (vector (map #((m (- 2 %)) %) idx))))
    (concat m ; rows
    (map (fn [i] (map #(% i) m)) idx) ; columns
    (vector (map #((m %) %) idx)) ; diagonal 1
    (vector (map #((m (- 2 %)) %) idx)))) ; diagonal 2
    (map (fn [row] (count (filter #(= player %) row))))
    (filter #(= % 3))
    seq))
    [:x :o])))
    seq))
  4. fronx revised this gist Sep 16, 2011. 1 changed file with 9 additions and 12 deletions.
    21 changes: 9 additions & 12 deletions fronx-4clojure-solution73.clj
    Original file line number Diff line number Diff line change
    @@ -4,16 +4,13 @@
    (fn [m]
    (first
    (filter
    (fn [p]
    (if (empty?
    (->> (let [idx '(0 1 2)]
    (concat m
    (map (fn [i] (map #(% i) m)) idx)
    (vector (map #((m %) %) idx))
    (vector (map #((m (- 2 %)) %) idx))))
    (map (fn [row]
    (count (filter #(= p %) row))))
    (filter #(= % 3))))
    nil
    p))
    (fn win? [player]
    (->> (let [idx [0 1 2]]
    (concat m
    (map (fn [i] (map #(% i) m)) idx)
    (vector (map #((m %) %) idx))
    (vector (map #((m (- 2 %)) %) idx))))
    (map (fn [row] (count (filter #(= player %) row))))
    (filter #(= % 3))
    seq))
    [:x :o])))
  5. fronx revised this gist Sep 16, 2011. 1 changed file with 5 additions and 8 deletions.
    13 changes: 5 additions & 8 deletions fronx-4clojure-solution73.clj
    Original file line number Diff line number Diff line change
    @@ -6,14 +6,11 @@
    (filter
    (fn [p]
    (if (empty?
    (->> (concat m
    (map (fn [i]
    (map #(% i) m))
    '(0 1 2))
    (vector (map #((m %) %)
    '(0 1 2)))
    (vector (map #((m (- 2 %)) %)
    '(0 1 2))))
    (->> (let [idx '(0 1 2)]
    (concat m
    (map (fn [i] (map #(% i) m)) idx)
    (vector (map #((m %) %) idx))
    (vector (map #((m (- 2 %)) %) idx))))
    (map (fn [row]
    (count (filter #(= p %) row))))
    (filter #(= % 3))))
  6. @invalid-email-address Anonymous created this gist Sep 16, 2011.
    22 changes: 22 additions & 0 deletions fronx-4clojure-solution73.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    ;; fronx's solution to Analyze a Tic-Tac-Toe Board
    ;; https://4clojure.com/problem/73

    (fn [m]
    (first
    (filter
    (fn [p]
    (if (empty?
    (->> (concat m
    (map (fn [i]
    (map #(% i) m))
    '(0 1 2))
    (vector (map #((m %) %)
    '(0 1 2)))
    (vector (map #((m (- 2 %)) %)
    '(0 1 2))))
    (map (fn [row]
    (count (filter #(= p %) row))))
    (filter #(= % 3))))
    nil
    p))
    [:x :o])))