home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / Salsa 0.3 / lister < prev    next >
Encoding:
Text File  |  1996-04-12  |  1.2 KB  |  67 lines  |  [TEXT/????]

  1. def avg(list)
  2. {
  3.     x = 0;
  4.     for(k in list) x = x+k;
  5.     return x/list.n;
  6. }
  7.  
  8. def var(list)
  9. {
  10.     std = 0; a = avg(list);
  11.     for(k in list) std = std + (k-a)^2;
  12.     return std/list.n;
  13. }
  14.  
  15. def sumsq(list)
  16. {
  17.     x = 0;
  18.     for(k in list) x = x + k*k;
  19.     return x;
  20. }
  21.  
  22. def min(list)
  23. {
  24.     x = list.0;
  25.     for(k in list) if (k<x) x = k;
  26.     return x;
  27. }
  28.  
  29. def max(list)
  30. {
  31.     x = list.0;
  32.     for(k in list) if (k>x) x = k;
  33.     return x;
  34. }
  35.  
  36. def printvar(list) { println("  var of ",list," is ",var(list)); }
  37. def printmin(list) { println("  min of ",list," is ",min(list)); }
  38. def printmax(list) { println("  max of ",list," is ",max(list)); }
  39. def printavg(list) { println("  avg of ",list," is ",avg(list)); }
  40. def printsumsq(list) { println("sumsq of ",list," is ",sumsq(list)); }
  41.  
  42. def main()
  43. {
  44.      b = [4,2,5,3,6,9,10,7,8,1,14,12,15,13,16,19,20,17,18,11]; str = "";
  45.     println(1,str,2);
  46.     thread printvar(b);
  47.     thread printsumsq(b);
  48.     thread printavg(b);
  49.     thread printmax(b);
  50.     thread printmin(b);
  51.     thread printvar(b);
  52.     thread printsumsq(b);
  53.     thread printavg(b);
  54.     thread printmax(b);
  55.     thread printmin(b);
  56.     thread printvar(b);
  57.     thread printsumsq(b);
  58.     thread printavg(b);
  59.     thread printmax(b);
  60.     thread printmin(b);
  61.     thread printvar(b);
  62.     thread printsumsq(b);
  63.     thread printavg(b);
  64.     thread printmax(b);
  65.     thread printmin(b);
  66. }
  67.