← Back to challenges

Lucky Seven

PythonHardnumbersloopsalgorithmsvalidation

Instructions

Given a list of numbers, return whether it is possible to make the number 7 by adding any three different numbers together.

Examples

lucky_seven([2, 4, 3, 8, 9, 1]) ➞ True

lucky_seven([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) ➞ True

lucky_seven([0, 0, 0, 2, 3]) ➞ False
# You cannot repeat the same number to make 2 + 2 + 3 = 7

lucky_seven([0, 0, 7]) ➞ False
# You need three different numbers.

Notes

  • Tests will only include numbers.
  • Trivially, any list with a length of less than two automatically fails the test.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.