100 REM The operation of this program is described in the paper 110 REM "Permutation Lattices Revisited", written by George Markowsky 120 REM and published in Mathematical Social Sciences, 27 (1994), pp. 59-74 130 REM The program is copyrighted 2001 and maybe freely distributed 140 REM provided this notice is included in the program. 150 REM This program is designed to illustrate the principles discussed 160 REM in the paper. It is left to the user to adapt it to any particular 170 REM purpose. All risks associated with using this program are assumed 180 REM by the user. The code is provided as is for instructional purposes. 190 REM This program computes the least and greatest complement of a 200 REM permutation. A sample permutation is given in the data below. 210 READ N 220 DIM IND(N), LC(N), GC(N) 230 FOR I = 1 TO N : READ J : LET IND(J) = I : NEXT I 240 DATA 7,5,3,7,6,2,1,4 250 LET FIRST = 1 : LET LAST = 1 : LET PTR = 1 260 FOR I = 1 TO N 270 IF I = N THEN GOTO 280 ELSE IF IND(I) < IND(I+1) THEN GOTO 330 280 FOR J = LAST TO FIRST STEP -1 290 LET LC(PTR) = J 300 LET PTR = PTR + 1 310 NEXT J 320 LET FIRST = I + 1 330 LET LAST = I + 1 340 NEXT I 350 FOR I = 1 TO N : PRINT LC(I); : NEXT I : PRINT 360 LET FIRST = 1 : LET LAST = 1 : LET PTR = N 370 FOR I = 1 TO N 380 IF I = N THEN GOTO 390 ELSE IF IND(I) > IND(I+1) THEN GOTO 440 390 FOR J = LAST TO FIRST STEP -1 400 LET GC(PTR) = J 410 LET PTR = PTR - 1 420 NEXT J 430 LET FIRST = I + 1 440 LET LAST = I + 1 450 NEXT I 460 FOR I = 1 TO N : PRINT GC(I); : NEXT I : PRINT