REM Generates all permutaions of n taken r
INPUT n,r
LET s$="abcdefghijklmnopqrstuvwxyz"
LET s$=s$(1:n)
PRINT "All premutaions of "; s$ ; "taken " ; r 
DECLARE EXTERNAL SUB perm
CALL perm(#0, "", s$, r)
! Alternation of destination is possible.
! OPEN #1: "A:permutations.txt"  
! ERASE #1
! CALL perm(#1, "", s$,r)
! CLOSE #1
END
EXTERNAL SUB perm(#1, p$, s$, r)
DECLARE STRING t$
DECLARE NUMERIC i,s
IF r=0 THEN
   PRINT #1: p$
ELSE
   LET s=LEN(s$)
   FOR i=1 TO s
      LET t$=s$(1:i-1)&s$(i+1:s)
      CALL perm(#1, p$ & s$(i:i), t$, r-1)
   NEXT i
END IF
END SUB