Array Reduction

A program that reduces a 2k×2k array to a k×k array by extracting unique elements. The program creates a random 2k×2k array, converts it to a one-dimensional array, extracts unique values (removing duplicates), and then reshapes the unique values into a k×k array. This demonstrates array manipulation, duplicate removal, and array reshaping algorithms.

Source Code:

CLS
INPUT k
n = 2 * k

DIM a(n, n), b(n / 2, n / 2), t1(n * n), t2(n * n / 4)

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
        t1((i - 1) * n + j) = a(i, j)
        PRINT t1((i - 1) * n + j);
NEXT j
PRINT
NEXT i

j = 1

FOR i = 1 TO n * n

        FOR k = 1 TO j
        IF t2(k) = t1(i) THEN EXIT FOR
        IF k = j THEN
                t2(j) = t1(i)
        j = j + 1
        END IF
        NEXT k

NEXT i


FOR i = 1 TO n / 2
FOR j = 1 TO n / 2
b(i, j) = t2((i - 1) * n / 2 + j)
NEXT j, i

PRINT

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