Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Word Pattern by Kurush
# migrated from python 2.7
def check_command(pattern, command):
bin_pattern = bin(pattern)[2:].rjust(len(command), "0")
if len(bin_pattern) > len(command): return False
for pattern_char, command_char in zip(bin_pattern, command):
if pattern_char == "1" and command_char.isdigit(): return False
if pattern_char == "0" and not command_char.isdigit(): return False
return True
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert check_command(42, "12a0b3e4") == True, "42 is the answer"
assert check_command(101, "ab23b4zz") == False, "one hundred plus one"
assert check_command(0, "478103487120470129") == True, "Any number"
assert check_command(127, "Checkio") == True, "Uppercase"
assert check_command(7, "Hello") == False, "Only full match"
assert check_command(8, "a") == False, "Too short command"
assert check_command(5, "H2O") == True, "Water"
assert check_command(42, "C2H5OH") == False, "Yep, this is not the Answer"
June 27, 2014