def calculate_elo(R1, R2, S, k=32):
    """

    Args:
        R1 (float): current rating of the first song
        R2 (float): current rating of the second song
        S (int): 1 for a win, 0 for a loss
        k (float): decides how much the elo rating fluctuates

    Returns:
         float: the newly calculated elo of R1 in (R1 vs R2) where S decides if R1 wins or loses

    Source: https://www.researchgate.net/publication/287630111_A_Comparison_between_Different_Chess_Rating_Systems_for_Ranking_Evolutionary_Algorithms

    """

    base = 10

    # changes how big the elo numbers are, the ratio stays the same
    div = 400

    # transformed rating

    r1 = base ** (R1 / div)
    r2 = base ** (R2 / div)

    # expected score
    e1 = r1 / (r1 + r2)

    # new elo
    elo = R1 + k * (S - e1)

    return elo