fork(2) download
  1. #no. of rocks,scissors and papers.
  2. R,S,P = map(int,input().split())
  3.  
  4. l=list()
  5. l=[0]*R + [1]*S +[2]*P
  6. # i marked rocks as 0 , scissor as 1 and paper as 2
  7.  
  8. from itertools import permutations
  9.  
  10. k= list(permutations(l))
  11.  
  12. rock_wins = 0
  13. scissor_wins = 0
  14. paper_wins = 0
  15.  
  16. for i in k:
  17. winner = i[0] # i took the first player as winner
  18. for j in range(1,len(i)):
  19.  
  20. if i[j]==winner:
  21. #it means fight between same kind of players, so it is a draw.
  22. pass#did nothing
  23. elif abs(i[j]-winner)==1:
  24. #it means either a fight between 0 and 1 (rocks or scissor) or between
  25. # 1 and 2 (scissor and paper) , in both cases, smaller value wins.
  26. winner = min(winner,i[j])
  27. else:
  28. #it means a fight between 0 and 2, i.e. a paper and rock
  29. winner = 2
  30. if winner==0:
  31. rock_wins+=1
  32. elif winner==1:
  33. scissor_wins+=1
  34. else:
  35. paper_wins+=1
  36.  
  37. total = len(k)
  38. print(rock_wins/total,scissor_wins/total,paper_wins/total)
  39.  
Success #stdin #stdout 0.02s 9484KB
stdin
2 2 2
stdout
0.3333333333333333 0.3333333333333333 0.3333333333333333