MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / is_combination_valid

Function is_combination_valid

project_euler/problem_032/sol32.py:19–37  ·  view source on GitHub ↗

Checks if a combination (a tuple of 9 digits) is a valid product equation. >>> is_combination_valid(('3', '9', '1', '8', '6', '7', '2', '5', '4')) True >>> is_combination_valid(('1', '2', '3', '4', '5', '6', '7', '8', '9')) False

(combination)

Source from the content-addressed store, hash-verified

17
18
19def is_combination_valid(combination):
20 """
21 Checks if a combination (a tuple of 9 digits)
22 is a valid product equation.
23
24 >>> is_combination_valid(('3', '9', '1', '8', '6', '7', '2', '5', '4'))
25 True
26
27 >>> is_combination_valid(('1', '2', '3', '4', '5', '6', '7', '8', '9'))
28 False
29
30 """
31 return (
32 int("".join(combination[0:2])) * int("".join(combination[2:5]))
33 == int("".join(combination[5:9]))
34 ) or (
35 int("".join(combination[0])) * int("".join(combination[1:5]))
36 == int("".join(combination[5:9]))
37 )
38
39
40def solution():

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected