Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Word Pattern by Mahoter
def check_command(pattern, command):
a = pattern
num = []
while a > 0:
if a%2 == 0:
a = a/2
num += [0]
else:
num += [1]
a -= 1
a = a/2
if len(num) < len(command):
while len(num) < len(command):
num += [0]
elif len(num) > len(command):
return False
num.reverse()
cyfr = []
for letter in command:
if letter in '0123456789':
cyfr += [0]
else:
cyfr += [1]
x = len(num)-1
while x >= 0:
if num[x] != cyfr[x]:
return False
x -= 1
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"
Jan. 18, 2016