fork download
  1. (defn rot90
  2. "Rotate rows 90 degrees clockwise."
  3. [rows]
  4. (mapv reverse (apply map list rows)))
  5.  
  6. (defn add-row
  7. "Adds new row, values starting at bottom left value + 1."
  8. [rows]
  9. (let [n (-> rows last first dec)
  10. width (-> rows first count)
  11. row (take width (iterate dec n))]
  12. (conj rows row)))
  13.  
  14. (defn solve
  15. [n]
  16. (let [seed [[(* n n)]]
  17. idx (* 2 (dec n))
  18. step (comp add-row rot90)]
  19. (-> (iterate step seed) (nth idx) rot90 rot90)))
  20.  
  21. (println (solve 5))
Success #stdin #stdout 1.22s 4386816KB
stdin
Standard input is empty
stdout
[(1 2 3 4 5) (16 17 18 19 6) (15 24 25 20 7) (14 23 22 21 8) (13 12 11 10 9)]