Array Reduction Variant

A variant of the array reduction algorithm that reduces a 2k×2k array to k×k by extracting unique elements. This version uses a different approach: it fills the result array position by position, searching through the original array for values that haven't been used yet in the result array. The algorithm ensures no duplicates by checking each candidate value against all previously filled positions in the result array.

Source Code:

CLS
INPUT k
n = 2 * k

DIM a(n, n), b(n / 2, n / 2)

RANDOMIZE VAL(MID$(TIME$, 8, 2))

FOR i = 1 TO n
FOR j = 1 TO n
a(i, j) = INT(RND * k * k) + 1
NEXT j, i


FOR i = 1 TO n
FOR j = 1 TO n

        PRINT a(i, j);
NEXT j
PRINT
NEXT i


b(1, 1) = a(1, 1)

FOR i = 1 TO n / 2
FOR j = 1 TO n / 2
        IF (i + j) = 2 GOTO 100
        b(i, j) = -1
        FOR di = 1 TO n
        FOR dj = 1 TO n
                ab = a(di, dj)
                FOR ki = 1 TO i
                FOR kj = 1 TO j
                IF b(ki, kj) = ab GOTO 50
                NEXT kj
                NEXT ki
                b(i, j) = ab
                GOTO 100
50 :    PRINT ab; i; j
        NEXT dj
        NEXT di
100 : REM
NEXT j
NEXT i


PRINT

FOR i = 1 TO n / 2
FOR j = 1 TO n / 2
PRINT b(i, j);
NEXT j
PRINT
NEXT i
END