Compare the Triplets

Sort by

recency

|

4346 Discussions

|

  • + 0 comments

    Here's my shortest answer (so far)…

    def compareTriplets(a, b):
        return (list(map(sum, zip(*(
          (1, 0) if i > j else (0, 1)
          for i, j in zip(a, b) if i != j))))
          or [0, 0])
    

    Also short, but done without for loop…

    def compareTriplets(a, b):
        return list(map(sum, zip(*(map(lambda i:
            (1, 0) if i[0] > i[1] else (0, 1) if i[0] < i[1] else (0, 0),
            zip(a, b))))))
    

    I'm not sure whether the for in a sequence comprehension is really considered to be the same as a for-loop, but I thought I'd try to make a solution without that keyword anyway.

    Yesterday, I had submitted this longer answer because I was sleepy…

    def compareTriplets(a, b):
        at = bt = 0
        for i in range(3):
          if a[i] > b[i]:
            at += 1
          if b[i] > a[i]:
            bt += 1
        return [at, bt]
    
  • + 0 comments
    def compareTriplets(a, b):
        sa=0
        sb=0
        for i in range(3):
            if a[i]<b[i]:
                sb+=1
            if a[i]>b[i]:
                sa+=1
            if a[i]==b[i]:
                sa+=0
                sb+=0
        return sa,sb
    
  • + 0 comments

    def maxx(a,b): if a==b: return 2 elif a>b: return 0 else: return 1 def compareTriplets(a, b): # Write your code here score=[0]*3 for i in range(0,len(a)): winner=maxx(a[i],b[i]) score[winner]+=1 score.pop() return score

  • + 1 comment
        x = sum([10 if aa>bb else 1 if aa <bb else 0 for aa,bb in zip(a,b)])    
        return [x//10, x%10]
    
  • + 0 comments

    Thanks for sharing the link! That was an interesting read—appreciate the detailed insights and the thoughtful discussion happening in the thread. Looking forward to more updates! महादेव बुक लॉगिन