import math


def compute_dcg(recommended_items, actual_items_seen):
    """
    recommended_items: list of n recommended item for a test user
    actual_items_seen: list of actual items that the user has viewed
    return: Discounted cumulative gain for a query (user/item)
    """
    dcg = 0
    for i in range(0, len(recommended_items)):
        if recommended_items[i] in set(actual_items_seen):
            # item i is relevant
            dcg += 1.0/math.log(i+2, 2)
    return dcg