Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List All Combinations
#1
Hmm, this has probably been challanged before, but...

Can one make a program where, given letters in a list (a DATA statment) and the number of letters, all different combinations of those letters could be outputted to a file?

So if I put this as my data stament:

Code:
DATA T, H, E

The file (output.txt or something) would print

Code:
THE
TEH
HET
HTE
ETH
EHT

I'm working on one...
size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Reply
#2
could it be set a three or do you have to have it be adjustable.
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
Quote:could it be set a three or do you have to have it be adjustable.
Dunno. Extra points for adjustable 8)
size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Reply
#4
ok im working on one.
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#5
PROGGER,

Because there's more than one way to skin a cat, here's a brute force solution to the problem. Instead of the letters T H E, it uses the numbers 1 2 3. If you really wanted the letter, you could convert the numbers to the letters easily before printing.
Code:
defint a-z
for x=123 to 321
    s$=mid$(str$(x),1)
    if instr(s$,"1")>0 and instr(s$,"2")>0 and instr(s$,"3")>0 then print s$
next x
system
What do you think?
*****
Reply
#6
This is my recursive entry:
Code:
'Antoni Gual 2003
DECLARE SUB COMBINE (I%)
DECLARE SUB PRINTIT ()
DEFINT A-Z
CONST NDATA = 5
DATA Q,B,A,S,I,C,N,E,W,S
DIM SHARED CNT&
DIM SHARED A(0 TO NDATA)
DIM SHARED B$, P$
B$ = SPACE$(NDATA)
P$ = B$
FOR I = 1 TO NDATA
  READ c$
  MID$(B$, I, 1) = c$
NEXT
COMBINE 1
PRINT : PRINT CNT&; " PERMUTATIONS"
END

SUB COMBINE (I)
IF I > NDATA THEN EXIT SUB
FOR J = 1 TO NDATA
   FOR K = 1 TO I
     IF A(K - 1) = J THEN GOTO ENDED
   NEXT
   A(I) = J
   COMBINE (I + 1)
   IF I = NDATA THEN PRINTIT
ENDED:
NEXT
END SUB

SUB PRINTIT
FOR KK = 1 TO NDATA
  MID$(P$, KK, 1) = MID$(B$, A(KK), 1)
NEXT
PRINT P$,
CNT& = CNT& + 1
END SUB
Antoni
Reply
#7
moneo:
I took you basic idea a put it into mine and

Code:
CLS
DEFLNG A-Z
INPUT in$
t = TIMER
l = LEN(in$)
FOR i = 1 TO l
l2$ = l2$ + LTRIM$(STR$(i))
NEXT i
FOR i = l TO 1 STEP -1
l3$ = l3$ + LTRIM$(STR$(i))
NEXT i
FOR i = VAL(l2$) TO VAL(l3$)
s$ = LTRIM$(MID$(STR$(i), 1))
FOR z = 1 TO l
  IF INSTR(s$, LTRIM$(STR$(z))) < 1 THEN EXIT FOR
  f$ = ""
  IF z = l THEN
   FOR z2 = 1 TO l
    f$ = f$ + MID$(in$, VAL(MID$(s$, z2, 1)), 1)
   NEXT z2
   PRINT f$
  END IF
NEXT z
NEXT i
PRINT "TIMER: "; INT(TIMER - t)

edit: oops. forggot to chage something *click* done it works now. try it.
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#8
Quote:PROGGER,

Because there's more than one way to skin a cat, here's a brute force solution to the problem. Instead of the letters T H E, it uses the numbers 1 2 3. If you really wanted the letter, you could convert the numbers to the letters easily before printing.
Code:
defint a-z
for x=123 to 321
    s$=mid$(str$(x),1)
    if instr(s$,"1")>0 and instr(s$,"2")>0 and instr(s$,"3")>0 then print s$
next x
system
What do you think?
*****
lol, it works

*is testing*
size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Reply
#9
ANTONI,

I tested your program and it works fine. It's hard to verify 120 combinations, so I adjusted your code to only use 3 letters, which were easy to check. Can't figure out your algorithm, but it works 100%. Congratulations!
*****
Reply
#10
i fixed mine
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)