The horizontals are easy. It's literally just solutions
: you want a list of lists of numbers, and that's what you already have!
I can't imagine why you want to sum things, since that's unrelated to checking a sudoku solution (which should involve checking for uniqueness). If you did, though, you could sum each horizontal with just (map #(reduce + %) solution)
.
The verticals involve a neat trick: you can use (apply map vector m)
to transpose a "matrix" of nested vectors. So just turn the solution 90 degrees, and then check its horizontals! And of course if you want, you can add them up in the same way, although again I don't see why.
Squares are more interesting, and there are a few ways to go about it. I would use get-in
and a sequence of coordinate pairs, like:
(defn squares [solution]
(for [y (range 3)
x (range 3)]
(for [y' (range 3)
x' (range 3)]
(get-in solution [(+ y' (* 3 y))
(+ x' (* 3 x))]))))
For completeness: I did say you should be checking for uniqueness rather than summing (after all, 9 5s sum to 45, but that's definitely not a good solution!). Here's one way you could verify that a list of 9 numbers constitute a valid row/column/square:
(defn valid? [numbers]
(and (= 9 (count numbers))
(= (set (range 1 10))
(set numbers)))