Skip to content

Instantly share code, notes, and snippets.

@cjhanks
Created February 21, 2014 06:02
Show Gist options
  • Save cjhanks/9129570 to your computer and use it in GitHub Desktop.
Save cjhanks/9129570 to your computer and use it in GitHub Desktop.
sre-tests
"""
http://www.careercup.com/question?id=5127611667709952
"""
RowSize = 5
Data = [['a', 'b', 'c', 'd', 'e'],
['f', 'g', 'h', 'i', 'j'],
['k', 'l', 'm', 'n', 'o'],
['p', 'q', 'r', 's', 't'],
['u', 'v', 'w', 'x', 'y'],
['z', ' '] ]
SEQUENCE = 'CON'
def calculated_position(character):
""" :return: (y, x) """
return list(divmod(ord(character.upper()) - ord('A'), RowSize))
def navigate(src, dst):
"""
"""
def navigate_field(positive, negative, index):
while src[index] != dst[index]:
if src[index] < dst[index]:
src[index] += 1
print(positive)
elif src[index] > dst[index]:
src[index] -= 1
print(negative)
navigate_field('D', 'U', 0)
navigate_field('R', 'L', 1)
print('OK')
def main():
current_position = [0, 0]
for character in SEQUENCE:
destination = calculated_position(character)
navigate(current_position, destination)
current_position = destination
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment