The goal is to print the winner's number ex) scond person = 2
input N which is the number of people playing the game, and rolling five dice roll( dice is normall dice 1~6).
conditions:
1) if the dice number all added during the five rolls exceeds 20 that person is game-over
2) the user close to 20 is the winner
3) if there are more than one user with the closeset number to 20, than the person with smaller number when the numbers rolled from the dice are multipled is the winner
ex)
input :
4
5 2 6 5 4
1 3 4 5 6
6 1 2 3 5
3 3 3 4 6
output : 2
-->input : first line input a number ( how many players )
scond line you get inputs of thr first person's five numbers using space : 5 2 6 5 4
thrid line scond person's dice roll numbers : 1 3 4 5 6
and so on...
output : printing the winner's number --> if second person wins, than the output is 2
i finished coding but the onine judge program printed wrong answer :(
What I have tried:
import sys
num_people = int(input())
dice = [list(map(int, input().split())) for _ in range(num_people)]
dice_added = []
dice_multipled = []
multiple = 1
dice_min = []
for i in range(num_people):
if sum(dice[i]) <= 20:
dice_added.append(sum(dice[i]))
else:
dice_added.append(0)
for j in range(num_people):
for x in range(5):
multiple *= int(dice[j][x])
dice_multipled.append(multiple)
multiple = 1
dice_index = list(filter(lambda x : dice_added[x] == max(dice_added), range(len(dice_added))))
for i in list(dice_index):
dice_min.append(dice_multipled[i])
for i in range(len(dice_index)-1):
if dice_min[i] < dice_min[i+1]:
print(dice_index[i]+1)
else:
print(0)