Skip to content

Instantly share code, notes, and snippets.

@tyler-austin
Created June 1, 2017 22:32
Show Gist options
  • Save tyler-austin/ab887d621d85a700da59cb1b5feaee5c to your computer and use it in GitHub Desktop.
Save tyler-austin/ab887d621d85a700da59cb1b5feaee5c to your computer and use it in GitHub Desktop.
Code Fights - areEquallyStrong

Call two arms equally strong if the heaviest weights they each are able to lift are equal.

Call two people equally strong if their strongest arms are equally strong (the strongest arm can be both the right and the left), and so are their weakest arms.

Given your and your friend's arms' lifting capabilities find out if you two are equally strong.

Example

For yourLeft = 10, yourRight = 15, friendsLeft = 15 and friendsRight = 10, the output should be
areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = true;
For yourLeft = 15, yourRight = 10, friendsLeft = 15 and friendsRight = 10, the output should be
areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = true;
For yourLeft = 15, yourRight = 10, friendsLeft = 15 and friendsRight = 9, the output should be
areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = false.

Input/Output

  • [time limit] 4000ms (py3)

  • [input] integer yourLeft

    • A non-negative integer representing the heaviest weight you can lift with your left arm.

      Guaranteed constraints:

      0 ≤ yourLeft ≤ 20.
      
  • [input] integer yourRight

    • A non-negative integer representing the heaviest weight you can lift with your right arm.

      Guaranteed constraints:

      0 ≤ yourRight ≤ 20.
      
  • [input] integer friendsLeft

    • A non-negative integer representing the heaviest weight your friend can lift with his or her left arm.

      Guaranteed constraints:

      0 ≤ friendsLeft ≤ 20.
      
  • [input] integer friendsRight

    • A non-negative integer representing the heaviest weight your friend can lift with his or her right arm.

      Guaranteed constraints:

      0 ≤ friendsRight ≤ 20.
      
  • [output] boolean

    • true if you and your friend are equally strong, false otherwise.
class AreEquallyStrong:
@classmethod
def are_equally_strong(cls, your_left: int, your_right: int, friends_left: int, friends_right: int):
your_weakest = min([your_left, your_right])
your_strongest = max([your_left, your_right])
friends_weakest = min([friends_left, friends_right])
friends_strongest = max([friends_left, friends_right])
return your_strongest == friends_strongest and your_weakest == friends_weakest
def areEquallyStrong(your_left: int, your_right: int, friends_left: int, friends_right: int):
your_weakest = min([your_left, your_right])
your_strongest = max([your_left, your_right])
friends_weakest = min([friends_left, friends_right])
friends_strongest = max([friends_left, friends_right])
return your_strongest == friends_strongest and your_weakest == friends_weakest
import unittest
from are_equally_strong import AreEquallyStrong
class TestAreEquallyStrong(unittest.TestCase):
def test_1(self):
your_left = 10
your_right = 15
friends_left = 15
friends_right = 10
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertTrue(result)
def test_2(self):
your_left = 15
your_right = 10
friends_left = 15
friends_right = 10
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertTrue(result)
def test_3(self):
your_left = 15
your_right = 10
friends_left = 15
friends_right = 9
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertFalse(result)
def test_4(self):
your_left = 10
your_right = 5
friends_left = 5
friends_right = 10
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertTrue(result)
def test_5(self):
your_left = 10
your_right = 15
friends_left = 5
friends_right = 20
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertFalse(result)
def test_6(self):
your_left = 10
your_right = 20
friends_left = 10
friends_right = 20
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertTrue(result)
def test_7(self):
your_left = 5
your_right = 20
friends_left = 20
friends_right = 5
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertTrue(result)
def test_8(self):
your_left = 20
your_right = 15
friends_left = 5
friends_right = 20
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertFalse(result)
def test_9(self):
your_left = 5
your_right = 10
friends_left = 5
friends_right = 10
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertTrue(result)
def test_10(self):
your_left = 1
your_right = 10
friends_left = 10
friends_right = 0
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertFalse(result)
def test_11(self):
your_left = 5
your_right = 5
friends_left = 10
friends_right = 10
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertFalse(result)
def test_12(self):
your_left = 10
your_right = 5
friends_left = 10
friends_right = 6
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertFalse(result)
def test_13(self):
your_left = 1
your_right = 1
friends_left = 1
friends_right = 1
result = AreEquallyStrong.are_equally_strong(your_left, your_right, friends_left, friends_right)
self.assertTrue(result)
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment