Programming puzzles: processing lists!
06-05-2017, 02:54 PM (This post was last modified: 06-05-2017 03:00 PM by pier4r.)
Post: #122
 pier4r Senior Member Posts: 1,940 Joined: Nov 2014
RE: Programming puzzles: processing lists!

I solved it making use of a previous release of the David's library (I could not find an updated version with all the listed commands).

From 0 to users it is quick if the product is usable.

 list2array   @ works   \<<     @input: a list          OBJ\->     \->ARRY   \>> frequencyCalcHelp "input: L1: a list on elements of which we want to calculate the frequency in the list itself output: L3: the original list, sorted ascending, with no duplicates L2: the frequencies of the elements in the original list. L1: the matrix containing the two lists as columns for possible stats operations example: in: { 3 2 1 3 2 1 2 1} Out: {1 2 3} { 3 3 2} [ [1 3] [2 3] [3 2] ] requirements: - it requires the list library done by davidM check hpmuseum.org's forum topic keywords 'processing lists!' "        frequencyCalc     \<<       0                "inListSize" DROP       {}             "resListNoDup" DROP       {}              "resListFreq" DROP            \->       @input       inList              @local var       inListSize       resListNoDup       resListFreq       \<<         inList SORT LDDUP 'resListNoDup' STO                  @counting the frequency now.         resListNoDup         1         \<<           inList SWAP LCNT             @ we count the number of times the element was in the input             @ list         \>>         DOSUBS         'resListFreq' STO                  resListNoDup         resListFreq         @making the matrix         resListNoDup list2array         resListFreq list2array         2         COL\->       \>>     \>>