def quartile(arr, val):
    """ Return the quartile (0-3) of val in arr. """
    sorted_array = sorted(arr)
    interval_length = len(sorted_array) / 4.0
    return int(sorted_array.index(val) / interval_length)