お題:リストの内容比較 - No Programming, No Lifeを解いてみた。
なんか思ったよりすっきり書けませんでした orz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use srfi-1) | |
(use srfi-13) | |
(use srfi-42) | |
(let* ((left (delete-duplicates '(aaa bbb ccc bbb eee hhhh))) | |
(right (delete-duplicates '(bbb ddd eee fff ggg iiiii))) | |
(left-only (lset-difference equal? left right)) | |
(right-only (lset-difference equal? right left)) | |
(both (lset-intersection equal? left right)) | |
(uni (lset-union equal? left right)) | |
(len (apply max (map string-length (map symbol->string uni))))) | |
(print #`"[left only] ,|left-only|") | |
(print #`"[right only] ,|right-only|") | |
(print #`"[both] ,|both|") | |
(print "") | |
(do-ec (: s (sort uni (^ l (apply string<= (map symbol->string l))))) | |
(let ((l (if (member s left) s "")) | |
(r (if (member s right) s ""))) | |
(format #t #`"~,|len|a|~,|len|a\n" l r)))) |
0 件のコメント:
コメントを投稿