home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-12 | 1.2 KB | 67 lines | [TEXT/????] |
- def avg(list)
- {
- x = 0;
- for(k in list) x = x+k;
- return x/list.n;
- }
-
- def var(list)
- {
- std = 0; a = avg(list);
- for(k in list) std = std + (k-a)^2;
- return std/list.n;
- }
-
- def sumsq(list)
- {
- x = 0;
- for(k in list) x = x + k*k;
- return x;
- }
-
- def min(list)
- {
- x = list.0;
- for(k in list) if (k<x) x = k;
- return x;
- }
-
- def max(list)
- {
- x = list.0;
- for(k in list) if (k>x) x = k;
- return x;
- }
-
- def printvar(list) { println(" var of ",list," is ",var(list)); }
- def printmin(list) { println(" min of ",list," is ",min(list)); }
- def printmax(list) { println(" max of ",list," is ",max(list)); }
- def printavg(list) { println(" avg of ",list," is ",avg(list)); }
- def printsumsq(list) { println("sumsq of ",list," is ",sumsq(list)); }
-
- def main()
- {
- b = [4,2,5,3,6,9,10,7,8,1,14,12,15,13,16,19,20,17,18,11]; str = "";
- println(1,str,2);
- thread printvar(b);
- thread printsumsq(b);
- thread printavg(b);
- thread printmax(b);
- thread printmin(b);
- thread printvar(b);
- thread printsumsq(b);
- thread printavg(b);
- thread printmax(b);
- thread printmin(b);
- thread printvar(b);
- thread printsumsq(b);
- thread printavg(b);
- thread printmax(b);
- thread printmin(b);
- thread printvar(b);
- thread printsumsq(b);
- thread printavg(b);
- thread printmax(b);
- thread printmin(b);
- }
-