import math


def dcg(r, k=None):
    """The Burges et al. (2005) version of DCG.

    This is what everyone uses (except trec_eval)
    :param r: results
    :param k: cut-off
    :return: sum (2^ y_i - 1) / log (i +2)
    """
    result = sum([(pow(2, rel) - 1) / math.log(rank + 2, 2) for rank, rel in enumerate(r[:k])])
    return result