Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created January 19, 2021 01:33
Show Gist options
  • Save ZechCodes/d8b9e51d7d9897cf1a52224eafdda27a to your computer and use it in GitHub Desktop.
Save ZechCodes/d8b9e51d7d9897cf1a52224eafdda27a to your computer and use it in GitHub Desktop.
Challenge 167 - Determine If Two Numbers Add up to a Target Value

Challenge 167 - Determine If Two Numbers Add up to a Target Value

Given two unique integer lists and an integer target value, create a function to determine whether there is a pair of numbers that add up to the target value, where one number comes from one list and the other comes from the second list.

Return True if there is a pair that adds up to the target value and False otherwise.

Examples

sum_of_two([1, 2], [4, 5, 6], 5) ➞ True

sum_of_two([1, 2], [4, 5, 6], 8) ➞ True

sum_of_two([1, 2], [4, 5, 6], 3) ➞ False

sum_of_two([1, 2], [4, 5, 6], 9) ➞ False
from __future__ import annotations
import unittest
def sum_of_two(list_a: list[int], list_b: list[int], target_value: int) -> bool:
return False # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertTrue(sum_of_two([1, 2, 3], [10, 20, 30, 40, 50], 42))
def test_2(self):
self.assertFalse(sum_of_two([1, 2, 3], [10, 20, 30, 40, 50], 44))
def test_3(self):
self.assertTrue(sum_of_two([1, 2, 3], [10, 20, 30, 40, 50], 11))
def test_4(self):
self.assertFalse(sum_of_two([1, 2, 3], [10, 20, 30, 40, 50], 60))
def test_5(self):
self.assertTrue(sum_of_two([1, 2, 3], [10, 20, 30, 40, 50], 53))
def test_6(self):
self.assertFalse(sum_of_two([1, 2, 3], [10, 20, 30, 40, 50], 4))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment