Last active
August 10, 2018 15:00
-
-
Save marco-souza/5751e8935e7cf01075bfa13ce5a8c5f0 to your computer and use it in GitHub Desktop.
Teste
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1 - Bitmap | |
# Complete the decompress function below. | |
def decompress(linesAsStringArray): | |
result_line = '' | |
for line in linesAsStringArray: | |
while line: | |
sep, rep = line[:2] | |
line = line[2:] | |
result_line += (sep * int(rep)) | |
result_line += '\n' | |
return result_line | |
# 2 - Regex: /\b(\d{6})(\d{5,9})(\d{4})\b/ | |
# 3 - open | |
"you decide to use a regular expression to mask them out, feeling proud of your forethought and amazed at how easily you solved the issue" | |
# 4 - skyline | |
# Complete the generateSkylineString function below. | |
def generateSkylineString(buildingHeightsAsString): | |
final_result = '' | |
for i in range(9): | |
result = '' | |
for v in buildingHeightsAsString: | |
result += '#' if int(v) >= 9-i else ' ' | |
final_result += '{}\n'.format(result) | |
return final_result[:-1] | |
# 5 - Generate tree | |
# Complete the generateTree function below. | |
def generateTree(inputTextStringArray): | |
text = '' | |
used_prefixes = [] | |
def print_path(path, tabs=0, prefix='', text=''): | |
if not path: | |
return text | |
new_path = path[1:] | |
current_node = path[0] | |
new_prefix = "{}.{}".format(prefix, current_node) | |
if new_prefix not in used_prefixes: | |
result = "{}{}\n".format(tabs*'\t', current_node) | |
text += result | |
used_prefixes.append(new_prefix) | |
return print_path(new_path, tabs+1, new_prefix, text) | |
for path in [i.split('.') for i in inputTextStringArray]: | |
text += print_path(path) | |
return text | |
# 6 - Wrap gates | |
# Complete the getRouteStatus function below. | |
def getRouteStatus(routeSpecAsStringArray): | |
gates = routeSpecAsStringArray[1:] | |
orig, dest = routeSpecAsStringArray[0].split(',') | |
states = [] | |
for t in gates: | |
a, b = t.split(',') | |
if a not in states: | |
if orig == a: | |
states.append(b) | |
else: | |
for i, _ in enumerate(states): | |
# have state in this gate, move | |
if a == states[i] and states[i] != dest: | |
states[i] = b | |
return "ok" if dest in states else 'invalid' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment