kozima #10105(2010/02/05 09:50 GMT) [ Common Lisp ] Rating3/3=1.00
最初にこんなリストを作って,
(" abc " " " " " "abc abc " " " " " " " " " " " " ")
90°ずつ回転させたのと合わせました。
abca c b b c abca abca c b b c acba acba c b b c acba
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
(defun rotate (m) (apply #'map 'list #'vector (reverse m))) (defun merge-line (&rest lines) (apply #'map 'string (lambda (&rest chars) (or (find #\Space chars :test #'char/=) #\Space)) lines)) (defun merge-matrix (&rest matrices) (apply #'mapcar #'merge-line matrices)) (defun write-cross (s) (let* ((m (let* ((n (length s)) (empty (format nil "~V@T~V@T~V@T " n n n)) (line1 (format nil "~V@T~A~V@T " n s n)) (line2 (format nil "~A~V@T~A " s n s))) `(,line1 ,@(make-list (1- n) :initial-element empty) ,line2 ,@(make-list (* 2 n) :initial-element empty)))) (m1 (rotate m)) (m2 (rotate m1)) (m3 (rotate m2))) (mapc #'write-line (merge-matrix m m1 m2 m3))))
Rating3/3=1.00-0+
1 reply [ reply ]
kozima
#10105()
[
Common Lisp
]
Rating3/3=1.00
最初にこんなリストを作って,
(" abc " " " " " "abc abc " " " " " " " " " " " " ")90°ずつ回転させたのと合わせました。
(defun rotate (m) (apply #'map 'list #'vector (reverse m))) (defun merge-line (&rest lines) (apply #'map 'string (lambda (&rest chars) (or (find #\Space chars :test #'char/=) #\Space)) lines)) (defun merge-matrix (&rest matrices) (apply #'mapcar #'merge-line matrices)) (defun write-cross (s) (let* ((m (let* ((n (length s)) (empty (format nil "~V@T~V@T~V@T " n n n)) (line1 (format nil "~V@T~A~V@T " n s n)) (line2 (format nil "~A~V@T~A " s n s))) `(,line1 ,@(make-list (1- n) :initial-element empty) ,line2 ,@(make-list (* 2 n) :initial-element empty)))) (m1 (rotate m)) (m2 (rotate m1)) (m3 (rotate m2))) (mapc #'write-line (merge-matrix m m1 m2 m3))))Rating3/3=1.00-0+
1 reply [ reply ]