vku_spring_code_r2_ltpq

Used binary representation and bitwise operators
mail@pastecode.io avatar
unknown
python
2 years ago
583 B
9
Indexable
Never
class ChallengeClass:
    def Verify(_, s):
        s = list(map(int, s.split(', ')))
        
        def X(i):
            R = s[i] <= 50
            if i > 4:
                R = s[i] in map(lambda x : sum(map(lambda j : (x>>j&1) * s[i-1-j], range(5))) if x.bit_count()>1 else -1, range(32))
            if i: R &= X(i-1)
            return R
        
        return X(len(s)-1)

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