_Letters to the Editor_
by Tom Ruby

MODULE Lisp2 ;
(* Constructing combinations without LISP, or
   a makelist operation which checks for duplicate combinations *)

IMPORT FIO ;  (* For getting the output out *)
TYPE
   Ball = (Blue, Red, White, Green, Overflow ) ;
   Counter = ARRAY[ 0 .. 8 ] OF Ball ;

PROCEDURE Increment( VAR C : Counter ) ;

   VAR
      I : CARDINAL ;

   BEGIN
     I := 0 ;
     LOOP
        INC( C[I] ) ;
        IF ( C[I] = Overflow ) AND ( I < 8 ) THEN
           C[I] := Blue ;
        ELSE                                   
        EXIT ;
           END ;
        INC( I ) ;
        END ;
      END Increment ;
PROCEDURE Accept( N : Counter ) : BOOLEAN ;
   (* Return T if N is a possible combination
      (no more than 3 balls of any color ) *)
   VAR
      C : ARRAY[ Blue .. Green ] OF CARDINAL ;
      B : Ball ;
      I : CARDINAL ;
   BEGIN
      FOR B := Blue TO Green DO C[B] := 0 END ;
      FOR I := 0 TO 8 DO INC( C[N[I]] ) END ;
      FOR B := Blue TO Green DO
          IF C[B] > 3 THEN RETURN FALSE END ;
          END ;
      RETURN TRUE ;                            
    END Accept ;
VAR
   I : Counter ;
   J : CARDINAL ;
   Ch : CHAR ;
   F : FIO.File ;
   Buffer : ARRAY[ 0 .. 16384 ] OF BYTE ;
BEGIN
   (* All blue balls *)
   FOR J := 0 TO 8 DO I[J] := Blue END ;
   F := FIO.Create( 'LISP.PRN' ) ;
   FIO.AssignBuffer( F, Buffer ) ;
   WHILE I[8] < Overflow DO (* While <= 9 green balls *)
      IF Accept( I ) THEN
         FOR J := 0 TO 8 DO
             CASE I[J] OF
                  | Blue  : Ch := 'B' ;
                  | Red   : Ch := 'R' ;
                  | White : Ch := 'W' ;
                  | Green : Ch := 'G' ;       
              END ;
             FIO.WrChar( F, Ch ) ;
             END ;
         FIO.WrLn( F ) ;
         END ;
      Increment( I ) ;
      END ;
   FIO.Close( F ) ;
   END Lisp2 .


