PROG5.LST 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. Listing:
  2. 1 MODULE prog5;
  3. 2 (* this program lists the 9-digit numbers, containing every
  4. 3 digit from 1 to 9 which are a product of three 3-digit
  5. 4 numbers, which also contain every digit from 1 to 9 *)
  6. 5 IMPORT IO;
  7. 6 FROM perms IMPORT NextPerm;
  8. 7
  9. 8 PROCEDURE check(n:LONGCARD):BOOLEAN;
  10. ***** ^ undeclared identifier
  11. 9 (* Checks if the digits of n are a permutation of 1..9 *)
  12. 10 VAR i:[1..9];
  13. 11 digit:[0..9];
  14. 12 seen:ARRAY [0..9] OF BOOLEAN;
  15. ***** ^ not supported yet
  16. ***** ^ not supported yet
  17. 13 BEGIN
  18. 14 seen[0] := TRUE;
  19. ***** ^ not supported yet
  20. ***** ^ not supported yet
  21. 15 FOR i := 1 TO 9 DO
  22. 16 seen[i] := FALSE;
  23. ***** ^ not supported yet
  24. ***** ^ not supported yet
  25. 17 END;
  26. 18 FOR i := 1 TO 9 DO
  27. 19 digit := CARDINAL(n MOD 10); (* n MOD 10 is the remainder
  28. ***** ^ not supported yet
  29. ***** ^ not supported yet
  30. 20 when n is divided by 10 *)
  31. 21 IF seen[ digit ] THEN
  32. ***** ^ not supported yet
  33. ***** ^ not supported yet
  34. 22 RETURN FALSE;
  35. 23 ELSE
  36. 24 seen[ digit ] := TRUE;
  37. ***** ^ not supported yet
  38. ***** ^ not supported yet
  39. 25 END;
  40. 26 n := n DIV 10; (* DIV means whole number division *)
  41. ***** ^ not supported yet
  42. ***** ^ not supported yet
  43. 27 END;
  44. 28 RETURN TRUE;
  45. 29 END check;
  46. ***** ^ not supported yet
  47. 30
  48. 31 VAR d:ARRAY[0..8] OF SHORTCARD;
  49. ***** ^ not supported yet
  50. ***** ^ not supported yet
  51. 32 a,b,c:CARDINAL;
  52. 33 n:LONGCARD;
  53. ***** ^ undeclared identifier
  54. 34 i:CARDINAL;
  55. 35 wrap:BOOLEAN;
  56. 36 BEGIN
  57. 37 FOR i := 0 TO 8 DO
  58. 38 d[i] := SHORTCARD(i) + 1;
  59. ***** ^ not supported yet
  60. ***** ^ not supported yet
  61. ***** ^ not supported yet
  62. 39 END;
  63. 40
  64. 41 REPEAT
  65. 42 a := CARDINAL(d[0])*100 + CARDINAL( d[1]*10 + d[2] );
  66. ***** ^ not supported yet
  67. ***** ^ not supported yet
  68. ***** ^ not supported yet
  69. ***** ^ not supported yet
  70. ***** ^ not supported yet
  71. ***** ^ not supported yet
  72. 43 b := CARDINAL(d[3])*100 + CARDINAL( d[4]*10 + d[5] );
  73. ***** ^ not supported yet
  74. ***** ^ not supported yet
  75. ***** ^ not supported yet
  76. ***** ^ not supported yet
  77. ***** ^ not supported yet
  78. ***** ^ not supported yet
  79. 44 c := CARDINAL(d[6])*100 + CARDINAL( d[7]*10 + d[8] );
  80. ***** ^ not supported yet
  81. ***** ^ not supported yet
  82. ***** ^ not supported yet
  83. ***** ^ not supported yet
  84. ***** ^ not supported yet
  85. ***** ^ not supported yet
  86. 45 n := LONGCARD(a) * LONGCARD(b) * LONGCARD(c);
  87. ***** ^ not supported yet
  88. ***** ^ undeclared identifier
  89. ***** ^ not supported yet
  90. ***** ^ undeclared identifier
  91. ***** ^ not supported yet
  92. ***** ^ undeclared identifier
  93. ***** ^ not supported yet
  94. 46
  95. 47 IF check(n) THEN
  96. ***** ^ not supported yet
  97. ***** ^ not supported yet
  98. 48 IO.WrStr('A solution is ');
  99. ***** ^ not supported yet
  100. ***** ^ not supported yet
  101. ***** ^ not supported yet
  102. 49 IO.WrCard(a, 1);
  103. ***** ^ not supported yet
  104. ***** ^ not supported yet
  105. ***** ^ not supported yet
  106. 50 IO.WrStr(' x ');
  107. ***** ^ not supported yet
  108. ***** ^ not supported yet
  109. ***** ^ not supported yet
  110. 51 IO.WrCard(b, 1);
  111. ***** ^ not supported yet
  112. ***** ^ not supported yet
  113. ***** ^ not supported yet
  114. 52 IO.WrStr(' x ');
  115. ***** ^ not supported yet
  116. ***** ^ not supported yet
  117. ***** ^ not supported yet
  118. 53 IO.WrCard(c, 1);
  119. ***** ^ not supported yet
  120. ***** ^ not supported yet
  121. ***** ^ not supported yet
  122. 54 IO.WrStr(' = ');
  123. ***** ^ not supported yet
  124. ***** ^ not supported yet
  125. ***** ^ not supported yet
  126. 55 IO.WrLngCard(n, 1);
  127. ***** ^ not supported yet
  128. ***** ^ not supported yet
  129. ***** ^ not supported yet
  130. ***** ^ not supported yet
  131. 56 IO.WrLn;
  132. ***** ^ not supported yet
  133. ***** ^ not supported yet
  134. 57 END;
  135. 58 NextPerm(9,d,wrap);
  136. ***** ^ not supported yet
  137. ***** ^ not supported yet
  138. ***** ^ not supported yet
  139. 59 UNTIL wrap;
  140. 60 END prog5.
  141. 61
  142. 79 errors