Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Word Pattern by colinmcnicholl
def check_command(pattern, command):
"""Input: Two arguments. A pattern as a positive integer and
a command as a string.
Output: Is the pattern coincide with the command or not as a boolean.
"""
binary_pattern = bin(pattern).lstrip('0b').zfill(len(command))
binary_command = ''.join(['0' if char.isdigit() else '1'
for char in command])
return binary_command == binary_pattern
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"
Feb. 9, 2019
Comments: