-1

I'm new to using Maple and am trying to create the procedure above. My code so far:

g:=proc(n)
 local x; local setG; local setG2;
    for x from 1 to n do
       setG:={seq(x+1,x=1..n-1)}; setG2:=choose(setG,3); nops(setG2);
    end do;
end proc; 

I can't seem to figure out how exactly to get this to work given what I know of Maple.

1 Answers1

0

Your loop is not needed (and is problematic). The combinat:-choose command returns all of them, so there's no looping required.

F:=proc(n)
  nops(combinat:-choose({$2..n},3));
end proc:

Or, closer to your original code,

g:=proc(n)
  local x,setG,setG2;
  setG:={seq(x+1,x=1..n-1)};
  setG2:=combinat:-choose(setG,3);
  nops(setG2);
end proc:

A very similar homework problem was asked today on another forum, with the additional caveat that the subsets each contained at least one odd integer.

H:=proc(n)
  nops(select(hastype,combinat:-choose({$2..n},3),odd));
end proc:

Or, closer to your original style,

h:=proc(n)
 local x,setG,setG2,setG3;
 setG:={seq(x+1,x=1..n-1)};
 setG2:=combinat:-choose(setG,3);
 setG3:=select(hastype,setG2,odd);
 nops(setG3);
end proc:
acer
  • 6,671
  • 15
  • 15