def correlations_cpu(correlations, x, y, z, ct):
    """ function for computing the reference answer

    This function is the CPU version of the quadratic difference algorithm.
    It computes the correlations based on the quadratic difference criterion.
    This function is mainly for testing and verification, for large datasets
    use the GPU kernel.

    :param correlations: A correlations table of size sliding_window_width by N
        used for storing the result, which is also returned.
    :type correlations: a 2d numpy array of type numpy.uint8

    :param x: The x-coordinates of the hits
    :type x: numpy ndarray of type numpy.float32

    :param y: The y-coordinates of the hits
    :type y: numpy ndarray of type numpy.float32

    :param z: The z-coordinates of the hits
    :type z: numpy ndarray of type numpy.float32

    :param ct: The ct values of the hits
    :type ct: numpy ndarray of type numpy.float32

    :returns: correlations table of size sliding_window_width by N.
    :rtype: numpy 2d array
    """
    for i in range(correlations.shape[1]):
        for j in range(i + 1, i + correlations.shape[0] + 1):
            if j < correlations.shape[1]:
                if (ct[i]-ct[j])**2 < (x[i]-x[j])**2  + (y[i] - y[j])**2 + (z[i] - z[j])**2:
                   correlations[j - i - 1, i] = 1
    return correlations