[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [ProgSoc] Combination Theory
> Hey Kiddies,
> Ok ... I'd like to write a function that is passed an integer, and returns an
> array of strings (?), containing all possible unique combinations of the
> numbers up to and including the argument.
> Oh .. efficiency is an issue ... but don't let that stop you from posting an
The following QuickBASIC (yes I know, it's the R-est RAD tool I know of :)
subroutine does this. It uses a recursive method; anyone want to
write the iterative version?
Oh yes, and it doesn't generate an array of strings, it prints the output. But
generating an array of strings from this should be straightforward, if you're
interested I'll amend this program to generate strings instead.
DECLARE SUB NumberCombo (prepend$, start!, finish!)
'NumberCombo by Nicholas FitzRoy-Dale
'Sample call, produces all number combinations between 1 and 4.
NumberCombo "", 1, 4
SUB NumberCombo (prepend$, start, finish)
FOR counter = start TO finish
IF prepend$ <> "" THEN PRINT prepend$;
PRINT STR$(counter) + " ] ";
newprepend$ = prepend$ + STR$(counter)
IF counter < finish THEN NumberCombo newprepend$, counter + 1, finish
firstname.lastname@example.org, email@example.com, firstname.lastname@example.org
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to email@example.com.
If you are having trouble, ask firstname.lastname@example.org for help.
This list is archived at <http://www.progsoc.uts.edu.au/lists/progsoc/>