Solving 4clojure problems offline in emacs

It annoys me when sometimes a solution to a 4clojure problem gets a bit long to type and test in the little edit box. As they say it is not an IDE, and doesn’t try to be, so I wrote a little app that fetches the problems down via the api and wraps the tests up in an assertion so you can edit it in emacs or whatever, run the tests in lein and submit to 4clojure when you are done. It’s on Github, probably more useful for the harder ones.

As an example, below is my soln to #73 using it, I can run it with lein run -m offline-4clojure.p73

; Analyze a Tic-Tac-Toe Board - Hard
; A <a href="">tic-tac-toe</a>
; board is represented by a two dimensional vector.
; X is represented by :x, O is represented by :o, and empty is
; represented by :e.
; A player wins by placing three Xs or three Os in a horizontal,
; vertical, or diagonal row.
; Write a function which analyzes a tic-tac-toe board and returns :x if
; X has won, :o if O has won, and nil if neither player has won.
; tags - game
; restricted -

(ns offline-4clojure.p73
  (:use clojure.test))

(def __
(fn [board]
  (let [triples
        (fn [board]
          (map #(map (partial get-in board) %)
                (for [x [0 1 2]]
                  [[x 0] [x 1] [x 2]])
                (for [y [0 1 2]]
                  [[0 y] [1 y] [2 y]])
                [[[0 0] [1 1] [2 2]]
                 [[0 2] [1 1] [2 0]]])))]
    (ffirst (filter #(or (= [:o :o :o] %)
                         (= [:x :x :x] %))
                    (triples board)))))


(defn -main []
  (are [x] x
(= nil (__ [[:e :e :e]
            [:e :e :e]
            [:e :e :e]]))
(= :x (__ [[:x :e :o]
           [:x :e :e]
           [:x :e :o]]))
(= :o (__ [[:e :x :e]
           [:o :o :o]
           [:x :e :x]]))
(= nil (__ [[:x :e :o]
            [:x :x :e]
            [:o :x :o]]))
(= :x (__ [[:x :e :e]
           [:o :x :e]
           [:o :e :x]]))
(= :o (__ [[:x :e :o]
           [:x :o :e]
           [:o :e :x]]))
(= nil (__ [[:x :o :x]
            [:x :o :x]
            [:o :x :o]]))))