Instagram
youtube
Facebook
Twitter

Python The Old Saint And Three Questions program Codechef solution

Python The Old Saint And Three Questions program Codechef solution

Problem

Once upon a time, there was a hero and an old saint. And like in any story with a hero and an old saint, the old saint asked the hero three questions!

But here's the twist: each question was a binary question, which means that the answer to each must be either a yes or a no, not none, not both. Our hero, who was not so wise in the ways of science, answered them arbitrarily and just hoped he was correct. The old saint, being so old, does not remember which answers were correct. The only thing that he remembers is how many of them were yes and how many of them were no." Our hero will pass the test if the old saint cannot distinguish his responses from the set of correct answers, i.e., if the number of yes and no in the responses matches that in the correct answers, regardless of their order.

You are given the answers to each of the three questions and the responses of the hero to the same. Find out whether the hero will be able to pass the old saint's test.

Input Format

  • The first line will contain T, the number of test cases. The descriptions of the test cases follow.
  • The first line of each test case consists of three space-separated integers A1A2A3, representing the correct answers to the first, second, and third questions, respectively (0 for no and 1 for yes).
  • The second line of each test case consists of three space-separated integers B1 B2 B3, representing the response of the hero to the first, second, and third questions, respectively (0 for no and 1 for yes).

Output Format

For each test case, print "Pass" (without quotes) if the hero passes the old saint's test, "Fail" (without quotes) otherwise.

Constraints

  • 1<=T<=64
  • 0<=Ai,Bi<=1

Sample Input:

1 0 1

1 1 0

0 0 0

1 1 1

Sample Output:

Pass

Fail

Explanation:

  • In the first test case, since the number of 1s (Yes) is 2 and the number of 0s (No) is 1 among both the correct answers and the hero's answers, the old saint will fail to distinguish. Hence, the hero passes the test.
  • In the second test case, the number of 1s (Yes) is 0 among the correct answers but 3 among the hero's responses. Similarly, the number of 0s doesn't match. Therefore, the old saint will be able to identify the differences between the correct answer and the hero's response. Hence, the hero fails the test.

Solution:

for i in range(int(input(“Enter the number of terms: “))):

    A = list(map(int, input(“Enter 3 elements A1, A2, A3: “).split()))

    B = list(map(int, input(“Enter 3 elements B1, B2, B3: “).split()))

    

    print("Pass" if A.count(1) == B.count(1) else "Fail")

 

          Steps to solve this problem:

  1. Ask the user to enter the number of terms.
  2. In a loop, ask the user to enter three numbers, use the map() function to get iterator objects, and using the list() function, convert them into a list and store the list in variable A.
  3. Again, ask the user to enter three numbers, use the map() function to get iterator objects, and using the list() function, convert them into a list and store the list in variable B.
  4. Now check if A.count(1) is equal to B.count(1), then print "Pass". Otherwise, print "Fail".