All combinations of 3letters out of n
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | * Get all combinations (with replacement) of 3 letters out of N. * Raynald Levesque 2002/06/2. SET MPRINT=yes. DATA LIST FREE /nbers. BEGIN DATA 1 END DATA. LIST. * This macro finds all combinations (with replacement) of 3 letters out of n (where n > 3). *////////////////////////////////. DEFINE !doit (!POS=!CMDEND) !LET !x=!NULL STRING answer1 TO answer3 answer (A8). !DO !var !IN (!1) !LET !x=!CONCAT(!x,!BLANKS(1)) STRING !CONCAT('V',!LENGTH(!x)) (A8). COMPUTE !CONCAT('V',!LENGTH(!x))=!QUOTE(!var). !DOEND !LET !lastv1=!LENGTH(!SUBSTR(!x,3)) !LET !lastv2=!LENGTH(!SUBSTR(!x,2)) !LET !lastv3=!LENGTH(!SUBSTR(!x,1)) VECTOR vec=v1 TO !CONCAT('V',!LENGTH(!x)). LOOP #cnt1=1 TO !lastv1. COMPUTE answer1=vec(#cnt1). LOOP #cnt2=#cnt1 TO !lastv2. COMPUTE answer2=vec(#cnt2). LOOP #cnt3=#cnt2 TO !lastv3. COMPUTE answer3=vec(#cnt3). COMPUTE answer=CONCAT(RTRIM(answer1),RTRIM(answer2),RTRIM(answer3)). XSAVE OUTFILE='c:\\temp\\temp.sav' /KEEP=answer. END LOOP. END LOOP. END LOOP. EXECUTE. GET FILE='c:\\temp\\temp.sav'. !ENDDEFINE. *////////////////////////////////. !doit A B C G K L P S T V X Y. |