home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1995 / ARCHIVE95.iso / discs / pipeline / 8_12 / Lottery / c_LotMath < prev    next >
Text File  |  1995-06-27  |  2KB  |  67 lines

  1. %OP%VS4.13 (28-Apr-92), The Bindon Family, R4001 0009 7093 7995 
  2. %OP%TNN
  3. %OP%DP0
  4. %OP%PL66
  5. %OP%HM0
  6. %OP%FM0
  7. %OP%BM0
  8. %OP%PT1
  9. %OP%PDDotMatrix
  10. %OP%WC2,1522,78,1132,0,0,0,0
  11. %CO:A,80,0%%V%%L%function("NumCount","a:array","c:array","d:array")
  12. \ "c" is a 2 x 49  array to count instances of 1...49
  13. \ Set the first  column of "c" to 1...49
  14. \ Set the second column of "c" to zeros
  15. %V%%L%for("i",1,49)
  16. %V%%L%set_value(index(@c,1,i),i)
  17. %V%%L%set_value(index(@c,2,i),0)
  18. %V%%L%next
  19. \ Count the numbers 1...49 in array "a" skipping blanks
  20. %V%%L%set_name("n",0)
  21. %V%%L%for("i",1,cols(@a))
  22. %V%%L%for("j",1,rows(@a))
  23. %V%%L%if(index(@a,i,j)=" ",goto(A16),)
  24. %V%%L%set_name("v",index(@a,i,j))
  25. %V%%L%set_value(index(@c,2,v),index(@c,2,v)+1)
  26. %V%%L%next
  27. %V%%L%next
  28. \ Insertion sort of counted balls in descending order 
  29. %V%%L%for("i",1,48)
  30. %V%%L%set_name("k",i)
  31. %V%%L%for("j",i+1,49)
  32. %V%%L%if(index(@c,2,j)>index(@c,2,k),set_name("k",j),)
  33. %V%%L%next
  34. \ Note that INDEX(,,) always returns a CELL REFERENCE
  35. \ and contents may change          DEREF( takes value
  36. %V%%L%if(i=k,goto(A35),)
  37. %V%%L%set_name("t",deref(index(@c,1,k)))
  38. %V%%L%set_name("u",deref(index(@c,2,k)))
  39. %V%%L%for("j",k,i+1,-1)
  40. %V%%L%set_value(index(@c,1,j),index(@c,1,j-1))
  41. %V%%L%set_value(index(@c,2,j),index(@c,2,j-1))
  42. %V%%L%next
  43. %V%%L%set_value(index(@c,1,i),t)
  44. %V%%L%set_value(index(@c,2,i),u)
  45. %V%%L%next
  46. \
  47. \ find distribtion of ball success in 2 x 21 arraray "d"
  48. \ index function does not allow index 0
  49. %V%%L%for("nb",1,21)
  50. %V%%L%set_value(index(@d,1,nb),0)
  51. %V%%L%next
  52. \ Note that @c and @d arrays must be large enough for "j" and "nb" ranges  
  53. %V%%L%for("j",1,49)
  54. %V%%L%for("nb",0,20)
  55. %V%%L%if(index(@c,2,j)=nb,set_value(index(@d,1,nb+1),index(@d,1,nb+1)+1),)
  56. %V%%L%next
  57. %V%%L%next
  58. %V%%L%result("done")
  59. \
  60. %V%%L%function("fac","i:number")
  61. %V%%L%if(@i=0,result(1),)
  62. %V%%L%set_name("n",1)
  63. %V%%L%for("j",@i,1,-1)
  64. %V%%L%set_name("n",n*j)
  65. %V%%L%next
  66. %V%%L%result(n)
  67.