From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_MSGID, SUBJ_ALL_CAPS autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f86c18fa05448c83 X-Google-Attributes: gid103376,public From: Jon S Anthony Subject: Re: RECURSION PROBLEM Date: 1997/11/04 Message-ID: #1/1 X-Deja-AN: 287921031 Distribution: world References: <34558FD4.2781@db.erau.edu> Organization: PSINet Newsgroups: comp.lang.ada Date: 1997-11-04T00:00:00+00:00 List-Id: Robert Byrne writes: > > I need to use recursion to display all pairs (combinations) of > characters from a set of characters read from a file given on the I note that you say _combinations_, not permutations. The following is a simple solution in Lisp. Translate into Ada and you are done... (defun combos (letters i) (labels ((a-set (cur letters next) (if (= next (length letters)) nil (cons (cons cur (aref letters next)) (a-set cur letters (1+ next)))))) (if (= i (length letters)) nil (append (a-set (aref letters i) letters (1+ i)) (combos letters (1+ i)))))) COMBOS * (combos "abcdef12345" 0) ((#\a . #\b) (#\a . #\c) (#\a . #\d) (#\a . #\e) (#\a . #\f) (#\a . #\1) (#\a . #\2) (#\a . #\3) (#\a . #\4) (#\a . #\5) (#\b . #\c) (#\b . #\d) (#\b . #\e) (#\b . #\f) (#\b . #\1) (#\b . #\2) (#\b . #\3) (#\b . #\4) (#\b . #\5) (#\c . #\d) (#\c . #\e) (#\c . #\f) (#\c . #\1) (#\c . #\2) (#\c . #\3) (#\c . #\4) (#\c . #\5) (#\d . #\e) (#\d . #\f) (#\d . #\1) (#\d . #\2) (#\d . #\3) (#\d . #\4) (#\d . #\5) (#\e . #\f) (#\e . #\1) (#\e . #\2) (#\e . #\3) (#\e . #\4) (#\e . #\5) (#\f . #\1) (#\f . #\2) (#\f . #\3) (#\f . #\4) (#\f . #\5) (#\1 . #\2) (#\1 . #\3) (#\1 . #\4) (#\1 . #\5) (#\2 . #\3) (#\2 . #\4) (#\2 . #\5) (#\3 . #\4) (#\3 . #\5) (#\4 . #\5)) * /Jon -- Jon Anthony Synquiry Technologies, Ltd., Belmont, MA 02178, 617.484.3383 "Nightmares - Ha! The way my life's been going lately, Who'd notice?" -- Londo Mollari