文字列の均等分割
この問題は、除算だけでははく算術演算とか、文字列の長さをstrlenの類いで測るとかをしなくても、多分書けるのではないかと思います。
Posted feedbacks - Common Lisp
行数以外は数値を使ってません。 もっとよく考えればきれいに書けるかも。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | (defun divid-1 (string n)
(loop
with list = (coerce string 'list)
with list2 = (nthcdr n list)
for slow on list
for fast = list2 then (or (nthcdr n fast) list2)
if (eq list2 fast) collect slow))
(defun divid-2 (string n)
(loop with list = (divid-1 string n)
with last = (last list)
for sublist on (cdr list)
while (car last)
do (mapl (lambda (l) (pop (car l))) sublist)
finally (return (mapcar #'ldiff list (cdr list)))))
(defun divid (string n)
(mapcar (lambda (l) (format nil "~{~C~}" l)) (divid-2 string n)))
|




nobsun
#4090()
Rating-1/3=-0.33
1 reply [ reply ]