> > > > #Q1. THE FIRST ATTENDANCE QUESTION WAS: What is a derangement? Learn by wikipedia > > > #A1. MY ANSWER TO THE FIRST ATTENDANCE QUESTION IS: A derangement is a permutation of the elements of a set such that no element appears in its original position. In other words, a derangement is permutation that has no fixed points. > > > > #Q2. THE SECOND ATTENDANCE QUESTION WAS: Give two examples of Wtos and StoW. > > > #A2. MY ANSWER TO THE SECOND ATTENDANCE QUESTION IS: > WtoS:=proc(w) local n,i,S: > > n:=nops(w): > > S:={}: > > for i from 1 to n do > if w[i]=1 then > S:=S union {i}: > fi: > od: > > S: > > end: > > ; > StoW:=proc(S,n) local i,w: > > if S minus {seq(i,i=1..n)}<>{} then > print(S, `is not a subset of`, {seq(i,i=1..n)} ): > RETURN(FAIL): > fi: > > w:=[]: > > for i from 1 to n do > > if member(i,S) then > w:=[op(w),1]: > else > w:=[op(w),0]: > fi: > > od: > > w: > > end: > ; > #My example: > WtoS([1,0,1,1,0,0,1]); {1, 3, 4, 7} ; > WtoS([0,0,0,0,0]); {} ; > StoW({},5); [0, 0, 0, 0, 0] ; > StoW({1,3,4,7},6); {1, 3, 4, 7}, `is not a subset of`, {1, 2, 3, 4, 5, 6} FAIL ; > StoW({1,3,4,7},7); [1, 0, 1, 1, 0, 0, 1] ; > ;