We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'compareTriplets' function below.## The function is expected to return an INTEGER_ARRAY.# The function accepts following parameters:# 1. INTEGER_ARRAY a# 2. INTEGER_ARRAY b#defvalidate_triplets(func):defwrapper(self,*args,**kwargs):forarginargs:iflen(arg)!=3:raiseValueError("Each triplet must contain exactly 3 elements.")returnfunc(self,*args,**kwargs)returnwrapperclassTriplet:def__init__(self,values):self.values=valuesdef__iter__(self):returniter(self.values)classScore:def__init__(self):self.alice_points=0self.bob_points=0defupdate(self,alice_score,bob_score):self.alice_points+=alice_scoreself.bob_points+=bob_scoreclassCompareTriplets:@validate_tripletsdef__init__(self,alice_triplet,bob_triplet):self.alice=Triplet(alice_triplet)self.bob=Triplet(bob_triplet)self.scores=Score()defcompare(self):comparison_results=list(self._compare_values())forresultincomparison_results:ifresult>0:self.scores.update(1,0)elifresult<0:self.scores.update(0,1)def_compare_values(self):fora,binzip(self.alice,self.bob):yielda-bdefget_scores(self):returnself.scores.alice_points,self.scores.bob_pointsdefmain():alice_triplet=list(map(int,input().strip().split()))bob_triplet=list(map(int,input().strip().split()))comparator=CompareTriplets(alice_triplet,bob_triplet)comparator.compare()result=comparator.get_scores()print(result[0],result[1])if__name__=="__main__":main()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Compare the Triplets
You are viewing a single comment's thread. Return to all comments →
This is my solution.