Skip to content

Instantly share code, notes, and snippets.

@saoili
Created July 3, 2017 23:26
Show Gist options
  • Save saoili/eee1ca75d890b8dd108486933f47c7f9 to your computer and use it in GitHub Desktop.
Save saoili/eee1ca75d890b8dd108486933f47c7f9 to your computer and use it in GitHub Desktop.
def can_map(numbers, letters):
# print "in can_map for {} and {}".format(numbers, letters)
if (
len(numbers) > len(letters) or
numbers.count('0') > letters.count('A') or
('B' in letters and '0' not in numbers)
):
return False
if len(numbers) == 1:
mutliple_letters = 'A' in letters and 'B' in letters
bs_and_zeros = numbers[0] == '0' and 'B' in letters
return not (mutliple_letters or bs_and_zeros)
letter = letters[0]
number = numbers[0]
if number == '0' and letter == 'B':
return False
if can_map(numbers[1:], letters[1:]):
return True
if letters[1] != letter:
# next letter had to belong to next number, previous would be True
return False
return can_map(numbers, letters[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment