       IDENTIFICATION DIVISION.
       PROGRAM-ID. strategy-nearest.
 
       DATA DIVISION.
       LOCAL-STORAGE SECTION.
          01 I PIC 9(2).
          01 THIS-CARD-DISTANCE PIC 9(2).
          01 MIN-CARD-DISTANCE PIC 9(2) VALUE 99.
          01 IDX-NEAREST-CARD PIC 9(1).

       LINKAGE SECTION.
       78 NUM-CARDS               VALUE 4.
       01 PRIZE-CARD PIC 9(2).
       01 PLAYER-REC.
         02 PLAYER-NAME PIC X(6).      
         02 PLAYER-BID PIC 9(2).
         02 PLAYER-POINTS PIC 9(2).
         02 PLAYER-STRATEGY PIC 9(1).
         02 PLAYER-HAND PIC 9(2) OCCURS NUM-CARDS TIMES.

       PROCEDURE DIVISION USING PRIZE-CARD, PLAYER-REC.
          MOVE 0 TO PLAYER-BID.
          MOVE 99 TO MIN-CARD-DISTANCE.
          PERFORM FIND-NEAREST VARYING I FROM 1 BY 1 UNTIL I > NUM-CARDS.
          PERFORM SELECT-NEAREST.

          GOBACK
          .

       FIND-NEAREST.
         IF PLAYER-HAND (I) > 0
           COMPUTE THIS-CARD-DISTANCE = PRIZE-CARD - PLAYER-HAND (I)
           IF THIS-CARD-DISTANCE < 0
             COMPUTE THIS-CARD-DISTANCE = -1 * THIS-CARD-DISTANCE
           END-IF
             
           IF THIS-CARD-DISTANCE < MIN-CARD-DISTANCE
             MOVE THIS-CARD-DISTANCE TO MIN-CARD-DISTANCE
             MOVE I TO IDX-NEAREST-CARD 
           END-IF
         END-IF.
 
       SELECT-NEAREST.
         MOVE PLAYER-HAND (IDX-NEAREST-CARD) TO PLAYER-BID.
         MOVE 0 TO PLAYER-HAND (IDX-NEAREST-CARD). 
