Fantastic! I thought it had to be recursive...but when I started thinking about it, numbers started dancing uncontrollably (and unintelligibly) in front of my eyes.

Thanks!

Mark

On 12 Sep 2005, at 20:12, Alex Tweedly wrote:

Mark Smith wrote:

This is probably really easy, but I'm so stupid when it comes to maths that I can't figure it out:

Given a list of any number of lines, how can I generate a list of every possible combination of those lines ie.

Here's a way to generate all combinations of the numbers - you can go from there to lines (or whatever) ...

function combinations pNum
  local tRes, temp, L
  if pNum <= 1 then
    return 1 & cr
  end if
  put  combinations(pNum-1) into temp
  repeat for each line L in temp
    put L & cr after tRes
  end repeat
  put pNum & cr after tRes
  repeat for each line L in temp
    put L & comma & pNum & cr after tRes
  end repeat
  return tRes
end combinations

or you can do it slightly more tersely and efficiently, but in a less attractive order (*) as

function combinations pNum
  local tRes, temp, L
  if pNum <= 1 then
    return 1 & cr
  end if
  put  combinations(pNum-1) into temp
  repeat for each line L in temp
    put L & comma & pNum & cr after tRes
    put L & cr after tRes
  end repeat
  return tRes & pNum & cr
end combinations


(*) "attractive" ?? I don't know why - but I find the order produced by the first code fragment more easy to follow, and hence more "attractive". Call me a geek :-).

--
Alex Tweedly       http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.21/96 - Release Date: 10/09/2005

_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to