vku_spring_code_r2_ltpq

Used recursion, backtrack, lambda, ternary expression.
mail@pastecode.io avatar
unknown
python
a year ago
582 B
3
Indexable
Never
class ChallengeClass:
    def Verify(_, s):
        s = list(map(int, s.split(', ')))

        def X(i):
            R = s[i] <= 50
            if i > 4:
                Y = lambda j,t,c: Y(j+1, t,c) or Y(j+1, t+s[i-1-j], c+1) if j-5 else t==s[i] if c>1 else 0
                R = Y(0,0,0)
            if i: R &= X(i-1)
            return R
        
        return X(len(s) - 1)

print(
ChallengeClass().Verify("1, 2, 3, 4, 5, 6")
# ChallengeClass().Verify("15, 17, 1, 38, 19, 70, 75, 58, 89, 203, 234, 659, 350, 1535, 437, 2428, 1885, 6635, 4400, 15785")
)