from ops import *

# solves the problem for vectors in Q^2
# in a _very_ straight-forward way
# (A is nx2)
def solve_n_x_two(A, verbose = True):
    to_rational(A)

    # find something non-zero on the first column:
    idx = -1 # first non-zero index
    for i in range(height(A)):
        if A[i][0] != 0: 
            idx = i
            break # stops iteration
    
    if verbose: 
        if idx == -1: 
            print("The first column is 0")
        else:
            print("The first nonzero index is {}".format(idx))
    
    if idx == -1:
        # then the first column is ZERO
        # we check if there is something != 0 in the 2:nd column:
        return 0 if all(A[i][1] == 0 for i in range(height(A))) else 1

    # otherwise A[idx][0] is nonzero. We move row idx to the top:
    swap(0, idx, A)
    
    if verbose:
        print_mtx(A)

    # now A[0][0] != 0. 
    
    # make all the other rows start with 0:
    for row in range(1, height(A)):
        factor = -(1/A[0][0])*A[row][0]
        addTo(0, factor, row, A)

    if verbose:
        print("first row fixed:")
        print_mtx(A)

    # Now we have something like this:
    #
    #  X *
    #  0 *
    #  0 *
    #  ...
    #  0 *
    # 

    # check if there is something != 0 on the 2:nd column starting with 2:nd entry
    return 1 if all(A[i][1] == 0 for i in range(1, height(A))) else 2