QiでL-99 (P17 指定した位置でリストを分割) — #:g1

Posted 2008-03-27 05:58:00 GMT

-(http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html)
もっと綺麗に書けそうなんだけれども…。

(split [a b c d e f g h i k] 3)
\=> [[a b c] [d e f g h i k]]
\

(define split Lst N -> (split* Lst [ ] N))

(define split* Lst Acc Cnt -> [(reverse Acc) | [Lst]] where (or (empty? Lst) (> 1 Cnt)) [H | T] Acc Cnt -> (split* T [H | Acc] (1- Cnt)))


comments powered by Disqus