🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fj.lang.lisp
Article #205

Re: about Permutation & Combination

#205
From: 戸梶明夫
Date: Sun, 06 Oct 1996 00:00
47 lines
1844 bytes
In-reply-to: tokaji@db.nm.fujitsu.co.jp's message of 27 Sep 1996 06:35:24 
GMT

> > fj.lang.lisp で紹介しました Mick-Lisp というのを使うと以下のような
> > 定義で、並べ方を調べる関数を定義することができます。
> 
> 同じ要素が二回以上出てきた場合でも、それらを別のものとして扱えるように
> 修正しました。

#fj.education.math は外しました。

定義を少し変更しました。narabe-kata の引数は、リスト、ベクタ、文字列が
可能です。

(defun narabe-kata (seq)
  (let ( (l (values-for ((x (length seq))) x)) ) ;; 出現位置(整数)の列に変換
    (cond
     ( (null l) nil )
     ( t
       (setq l (narabe-kata-help l))             ;; 並べ方を計算
       (setq l                                   ;; 元々の要素を復活
             (values-for ((x l))
               (values-for (x) (elt seq x))))
       l ))))

(defun narabe-kata-help (l)
  (cond
   ( (null l) (list nil) )
   ( t
     (concat-for ((x l))
       (let ( (nokori (gather-for ((y l)) (if (eq x y) nil y))) )
         (values-for ((y (narabe-kata-help nokori)))
           (cons x y)))) )))


(narabe-kata '(a b c))
((a b c) (a c b) (b a c) (b c a) (c a b) (c b a))

(narabe-kata [x y z])
((x y z) (x z y) (y x z) (y z x) (z x y) (z y x))

(narabe-kata "abc")
((97 98 99) (97 99 98) (98 97 99) (98 99 97) (99 97 98) (99 98 97))

-- 
戸梶  明夫
Technical Details
Message-ID: <INETNEWS-1-4-8.00461@niftyserve.or.jp>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: Japanese,JIS
X-Google-Thread: 1421c0,e1c9a495f4eb087d,start
X-Google-Attributes: gid1421c0,public
From: "戸梶 明夫 "
Subject: Re: about Permutation & Combination
Date: 1996/10/06
Message-ID: <INETNEWS-1-4-8.00461@niftyserve.or.jp>
X-Deja-AN: 187886470
content-type: text/plain; charset=iso-2022-jp
mime-version: 1.0
newsgroups: fj.lang.lisp