Help:=proc(): print(`Games(S,n), TieLessGames(S,n) , IsBad(L)`): print(`NaiveTieLessSeq(S,N),TieLessGamesC(S,n) , FSnk(S,n,k), fSnk(S,n,k) `): print(`fSn(S,n) , fSnSeq(S,n) `): end: #Games(S,n): inputs a set of positive integers S #and a non-neg. integer n, outputs all the sequences #(lists in Maple's langauage) in S Games:=proc(S,n) local T1,t1,s: option remember: if n<0 then RETURN({}): fi: if n=0 then RETURN({[]}): fi: T1:=Games(S,n-1): { seq(seq( [ op(t1), s], t1 in T1),s in S) }: end: #Inputs a sequence of integers L and outputs true #if (at least) one of the non-empty partial sums is 0 IsBad:=proc(L) local i,s: s:=0: for i from 1 to nops(L) do s:=s+L[i]: if s=0 then RETURN(true): fi: od: false: end: #TieLessGames(S,n): inputs a set of positive integers S #and a non-neg. integer n, outputs all the sequences #(lists in Maple's langauage) in S #there was never a tie during the game (or the end) TieLessGames:=proc(S,n) local T,GoodGuys,t: T:=Games(S,n): GoodGuys:={}: for t in T do if not IsBad(t) then GoodGuys:=GoodGuys union {t}: fi: od: RETURN(GoodGuys): end: #NaiveTieLessSeq(S,N): the first N terms in the #counting sequence for Tie-Less games with n #events where S is the set of possible scores NaiveTieLessSeq:=proc(S,N) local n: [seq(nops( TieLessGames(S,n) ),n=1..N)]: end: #TieLessGamesC(S,n): Not-as-stupid version of TieLessGames(n,S) TieLessGamesC:=proc(S,n) local T1,t1,T,su,S1: option remember: if n<0 then RETURN({}): fi: if n=0 then RETURN({[]}): fi: T1:=TieLessGamesC(S,n-1): T:={}: for t1 in T1 do su:=-convert(t1,`+`): S1:=S minus {su}: T:=T union {seq([op(t1),s1], s1 in S1)}: od: RETURN(T): end: #NaiveTieLessSeqC(S,N): the first N terms in the #counting sequence for Tie-Less games with n #events where S is the set of possible scores NaiveTieLessSeqC:=proc(S,N) local n: [seq(nops( TieLessGamesC(S,n) ),n=1..N)]: end: #FSnk(S,n,k): inputs a set S of integers, and integeres #n and k, and outputs the set of works in the alphabet S #of length n, whose sum is k FSnk:=proc(S,n,k) local s,T,T1,t1: option remember: if n<0 then RETURN({}): fi: if n=0 then if k=0 then RETURN({[] }): else RETURN({}): fi: fi: if k=0 then RETURN({}): fi: T:={}: for s in S do T1:=FSnk(S,n-1,k-s): T:=T union {seq([ op(t1), s], t1 in T1) }: od: T: end: TieLessGamesCC:=proc(S,n) local k: {seq( op(FSnk(S,n,k)), k=n*min(op(S))..n*max(op(S)) )}: end: #fSnk(S,n,k): inputs a set S of integers, and integeres #n and k, and outputs the number of words in the alphabet S #of length n, whose sum is k fSnk:=proc(S,n,k) local s,T,T1,t1: option remember: if n<0 then RETURN(0): fi: if n=0 then if k=0 then RETURN(1): else RETURN(0): fi: fi: if k=0 then RETURN(0): fi: add(fSnk(S,n-1,k-s),s in S): end: #fSn(S,n): the total number of tie-less games with scores in S #of length n fSn:=proc(S,n) local k: add( fSnk(S,n,k), k= n*min(op(S))..n*max(op(S)) ): end: fSnSeq:=proc(S,N) local n: [seq( fSn(S,n), n=1..N) ]: end: