import math


def DCG(relevance_scores, k=14):
    """ Function for computing the discounted cumulative gain for a given
    list of relevance scores ordered by rank within result list.

    Examples
    --------
    >>> DCG([3, 2, 3, 0, 1, 2])
    8.097171433256849
    >>> DCG([3, 2, 3, 0, 1, 2], k=2)
    5.0

    """
    relevance_scores = relevance_scores[:k]
    DCG = relevance_scores[0]  # rel_1
    for i, relevance_score in enumerate(relevance_scores[1:]):
        position = i + 2  # position in relevance list
        DCG += relevance_score / math.log(position, 2)
    return DCG