home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pli / runpli1a.arc / ORDER < prev    next >
Text File  |  1987-09-28  |  4KB  |  109 lines

  1. CLRSCR;
  2. PRINT(SYSPRINT,
  3.  '             Maximum Order for a Permutation on n Elements, n <= 16');
  4. PUTCRLF; PUTCRLF; PUTCRLF;
  5. PRINT(SYSPRINT,REPEAT(' ',39),'Maximum'); PUTCRLF;
  6. PRINT(SYSPRINT,REPEAT(' ',33),'n','      Order'); PUTCRLF;
  7. max_num_elements=16;
  8. num_elements=1;
  9. DO WHILE(num_elements <= max_num_elements);
  10.   max_order(num_elements)=num_elements;
  11.   num_elements=num_elements+1;
  12. END;
  13. num_elements=1;
  14. DO WHILE(num_elements <= 4);
  15.   PRINT(SYSPRINT,REPEAT(' ',34-LENGTH(STR(num_elements))),num_elements,
  16.    REPEAT(' ',9-LENGTH(STR(max_order(num_elements)))),
  17.    max_order(num_elements)); 
  18.   PUTCRLF;
  19.   num_elements=num_elements+1;
  20. END;
  21. min_num_elements=4;
  22. tem_int_1=8*max_num_elements+9;
  23. max_seq_length=2;
  24. tem_int_2=0;
  25. DO WHILE(tem_int_2 < tem_int_1);
  26.   max_seq_length=max_seq_length+1;
  27.   tem_int_2=2*max_seq_length+3;
  28.   tem_int_2=tem_int_2*tem_int_2;
  29. END;
  30. IF tem_int_2 > tem_int_1 THEN max_seq_length=max_seq_length-1;
  31. seq_length=2;
  32. DO WHILE(seq_length <= max_seq_length);
  33.   element_index=1;
  34.   DO WHILE(element_index <= seq_length);
  35.     element(element_index)=element_index+1;
  36.     element_index=element_index+1;
  37.   END;
  38.   element(seq_length)=element(seq_length)-1;
  39.   num_elements=min_num_elements;
  40.   finished=FALSE;
  41.   DO WHILE(! finished);
  42.     element_num=seq_length;
  43.     element(element_num)=element(element_num)+1;
  44.     num_elements=num_elements+1;
  45.     DO WHILE((element_num > 0)
  46.     &        (num_elements > max_num_elements));
  47.       IF element_num > 1 THEN
  48.         DO;
  49.           element(element_num-1)=element(element_num-1)+1;
  50.           num_elements=num_elements+1;
  51.           element_index=element_num;
  52.           DO WHILE(element_index <= seq_length);
  53.             num_elements=num_elements-element(element_index);
  54.             tem_int_1=element(element_index-1)+1;
  55.             element(element_index)=tem_int_1;
  56.             num_elements=num_elements+tem_int_1;
  57.             element_index=element_index+1;
  58.           END;
  59.         END;
  60.       element_num=element_num-1;
  61.     END;
  62.     IF element_num > 0 THEN
  63.       DO;
  64.         least_common_multiple=element(1);
  65.         element_index=2;
  66.         DO WHILE(element_index <= seq_length);
  67.           tem_int_1=least_common_multiple;
  68.           tem_int_2=element(element_index);
  69.           tem_int_3=tem_int_2;
  70.           tem_int_4=1;
  71.           DO WHILE(tem_int_4 != 0);
  72.             tem_int_4=MOD(tem_int_1,tem_int_2);
  73.             IF tem_int_4 != 0 THEN
  74.               DO;
  75.                 tem_int_1=tem_int_2;
  76.                 tem_int_2=tem_int_4;
  77.               END;
  78.           END;
  79.           least_common_multiple
  80.            =least_common_multiple/tem_int_2;
  81.           tem_int_1=tem_int_3/tem_int_2;
  82.           least_common_multiple=least_common_multiple*tem_int_1;
  83.           element_index=element_index+1;
  84.         END;
  85.         IF least_common_multiple > max_order(num_elements) THEN
  86.           max_order(num_elements)=least_common_multiple;
  87.       END;
  88.     ELSE
  89.       finished=TRUE;
  90.   END;
  91.   next_min_num_elements=(seq_length+1)*(seq_length+4);
  92.   next_min_num_elements=next_min_num_elements/2;
  93.   next_min_num_elements=next_min_num_elements-1;
  94.   IF next_min_num_elements > max_num_elements THEN
  95.     next_min_num_elements=max_num_elements;
  96.   DO WHILE(min_num_elements < next_min_num_elements);
  97.     tem_int_1=max_order(min_num_elements);
  98.     min_num_elements=min_num_elements+1;
  99.     IF tem_int_1 > max_order(min_num_elements) THEN
  100.       max_order(min_num_elements)=tem_int_1;
  101.     PRINT(SYSPRINT,REPEAT(' ',34-LENGTH(STR(min_num_elements))),
  102.      min_num_elements,
  103.      REPEAT(' ',9-LENGTH(STR(max_order(min_num_elements)))),
  104.      max_order(min_num_elements)); 
  105.     PUTCRLF;
  106.   END;
  107.   seq_length=seq_length+1;
  108. END;
  109.