Replaces the contents of the result variable with the sum of the absolute differences between the two input vectors. If the input vectors are of different lengths, the shorter vector will be "extended" to the length of the longer by repeating its last element as many times as necessary. This extension is only done internally and does not change the actual size or content of the shorter vector. If any element is a "missing" value
(represented by a "." or "NaN") the result for
SUMABSDEV will be NaN. To avoid this, you can |
COPY 1,5 A The above program produces the following output: A: (1.0 2.0 3.0 4.0 5.0) B: 7.0 Sometimes, you'll want to compare two vectors for equality or to determine if all elements of one vector are the same. The SUMABSDEV command is useful for these purposes. The following program shows an example of each technique. The code in red shows how to determine if two vectors are equal. The code in blue shows how to determine if all the elements of a single vector are the same (two examples of this in the code). 'Compute probability of a straight excluding straight flushes: 'A Straight consists of 5 cards with consecutive values with the 'addition that Ace can be high (13) or low (1) as needed 'to complete the sequence. A flush is 5 cards of the same suit. 'Solution uses the fact that if an ascending sequence of consecutive 'numbers is shifted one place and subtracted from the original, then 'the middle numbers will all be one. For example: ' 4 5 6 7 8 - original sequence ' (0) 4 5 6 7 8 shifted sequence ' 4 1 1 1 1 0 difference 'Solution also uses a trick with SUMABSDEV to check for occurrences 'of a flush. (Removing the flushes affects only the third significant 'figure and beyond, so the difference may not be detectable unless 'a huge number of samples is used.) COPY 1000000 repeatCount COPY 1,13 1,13 1,13 1,13 deck COPY 1,4 suit REPEAT repeatCount SHUFFLE deck shuffledDeck TAKE shuffledDeck 1,5 hand SORT hand sortedHand COPY 0 sortedHand shiftedSortedHand SUBTRACT sortedHand shiftedSortedHand diffVector TAKE diffVector 2,5 diffVectorCenter COUNT diffVectorCenter between 1 1 diffVectorSum IF diffVectorSum = 4 'We have a straight. Check if suits match. SAMPLE 5 suit suits TAKE suits 1 firstSuit |