python/CodeChallenge_18.py

36 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'''
One day three best friends Bill, Bob, and Jane decided to form a team and take part in programming contests. During these contests, participants are typically
given several problems to solve. Before the competition began, the friends agreed on a rule:
They would only attempt to solve a problem if at least two of them were confident in their solution. Otherwise, they would skip that problem. For each problem, it is
known which of the friends are sure about the solution. Your task is to help the friends determine the number of problems they will attempt to solve based on their rule.
Given a list of lists of triples of integers 1 or 0. If the first number in the line equals 1, then Bill is sure about the problem's solution, otherwise he isn't sure.
The second number shows Bobs view on the solution, the third number shows Janes view. Return an integer - the number of problems the friends will implement on the
contest.
Example 1
Input:
[[ 1, 0, 1 ], [1, 1, 1], [0, 0, 0]]
Output:
2
Example 2
Input:
[[0, 1, 1], [0, 0, 1], [1, 1, 1], [1, 1, 0]]
Output:
3
'''
from typing import List
class Solution(object):
def solve(self, problems: List[List[int]]) -> int:
print(f"problems: {problems}")
count = 0
for problem in problems:
if sum(problem) >= 2:
count += 1
return count
s = Solution()
# Example usage
print(s.solve([[1, 0, 1], [1, 1, 1], [0, 0, 0]])) # Output: 2
print(s.solve([[0, 1, 1], [0, 0, 1], [1, 1, 1], [1, 1, 0]])) # Output: 3