smeghead #930(2007/07/15 13:50 GMT) [ Common Lisp ] Rating0/0=0.00
27進数みなすようにして、AAA以降にも対応しましたが、冗長で汚いコードになってしまいました。 (print-alpha 100)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
(defun 27-to-alpha (str) (let ((*read-base* 27)) (format nil "~{~a~}" (loop for i from 0 to (1- (length str)) collect (string (code-char (+ 64 (read-from-string (string (aref str i)))))))))) (defun print-alpha (num) (mapcar #'(lambda (str) (format t "~a, " (27-to-alpha str))) (let ((offset 0)) (labels ((next-offset (n offset) (if (null (search "0" (format nil "~27r" (+ n offset)))) offset (next-offset n (1+ offset))))) (loop for i from 1 to num do (setf offset (next-offset i offset)) collect (format nil "~27r" (+ i offset)))))) nil)
Rating0/0=0.00-0+
[ reply ]
smeghead
#930()
[
Common Lisp
]
Rating0/0=0.00
(defun 27-to-alpha (str) (let ((*read-base* 27)) (format nil "~{~a~}" (loop for i from 0 to (1- (length str)) collect (string (code-char (+ 64 (read-from-string (string (aref str i)))))))))) (defun print-alpha (num) (mapcar #'(lambda (str) (format t "~a, " (27-to-alpha str))) (let ((offset 0)) (labels ((next-offset (n offset) (if (null (search "0" (format nil "~27r" (+ n offset)))) offset (next-offset n (1+ offset))))) (loop for i from 1 to num do (setf offset (next-offset i offset)) collect (format nil "~27r" (+ i offset)))))) nil)Rating0/0=0.00-0+
[ reply ]