Post Reply 
Symbolic Combinations and Permutations question.
01-13-2015, 03:57 AM
Post: #5
RE: Symbolic Combinations and Permutations question.
(01-13-2015 02:53 AM)Han Wrote:  Here's my attempt at the general version via recursion. Usage:

COMBOSET(list,n)

Works for arbitrary sets, too. For example, try: COMBOSET({"a","b",1,[0,-1,0]},2)

Code:
EXPORT COMBOSET(s,n)
BEGIN
  local l:={};
  local sl:={};
  local tl:={};
  local i,j;
  local m:=size(s);

  case
    if n==m then l:={s}; end;
    if n==1 then l:=makelist({s(X)},X,1,m); end; 
    if n>m then l:={}; end;
    for i from 2 to m-n+2 do
      sl:=sub(s,i,m); 
      tl:=COMBOSET(sl,n-1);
      for j from 1 to size(tl) do
        tl(j):=concat({s(i-1)},tl(j));
      end;
      l:=concat(l,tl); 
    end;
  end;
END;

Hello Han,

Thank you. I do not think I could make i better. I've written similar program for HP50 and recently was thinking to rewrite it for HP Prime. I was thinking about your resent post about solving system of eqs. You described case were there was more eqs. than unknowns and fsolve was giving some kind of error. If I remember correctly from linear algebra system like that is called overdetermined and theoretically could have only one solution but mostly has number of solutions for different combinations of eqs. for example if you have 3 eqs. and 2 unknowns you would have, in general, 3 solutions: sol. for eq1 and eq2, sol. for eq1 and eq3 and sol. for eq2 and eq3 (combinations of eqs.). but I have to find the book and do some reviewing. Thanks once again.

Cheers
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Symbolic Combinations and Permutations question. - John P - 01-13-2015 03:57 AM



User(s) browsing this thread: 1 Guest(s)