#Assumptions made:
#1. Knowledge of team-players is independent and identally distributed 
#   amongst the team.
#2. Players either have the right answer or do not have an answer at all.
#3. If at least one player on the team has the right answer
#   ==> the team will get the right answer.

calc_norm <- function(team_scores, team_size, max_score){
        #Error checker:
        if(length(team_scores) != length(team_size)){
                return("Error: Learn to Count!")
        }
        if(max(team_scores) > max_score){
                return("Error: One team has cheated.")
        }
        
        normalised_scores = rep(NA, length(team_scores))
        for(i in 1:length(team_scores)){
                #Probability of team obtaining the right answer: Observed
                team_prob = team_scores[i]/max_score
                #Theoretically, a team has this chance of getting a question:
                #P(Ans) = 1 - (1-p)^(t)
                #where:
                #p = Probability of any individual obtaining the right answer.
                #t = size of the team
                
                #Rearrange equation to get p.
                #p = 1-(1-team_prob)^(1/t)
                individual_prob = 1 - (1-team_prob)^(1/team_size[i])
                
                normalised_scores[i] = individual_prob*max_score
        }
        return(normalised_scores)
}

#Hypothetical Example
team_scores_last_night = c(42, 45, 56)
team_sizes_last_night = c(3, 3, 4)
max_score_last_night = 65
normalised_scores = calc_norm(team_scores_last_night, 
                              team_sizes_last_night, 
                              max_score_last_night)
print(normalised_scores)
## [1] 19.02538 21.11809 25.34978