Python
Here's my initial solution in Python for part one.
import sys
def distance(start, next):
if start == next:
return 6
sequence = "roygbv"
startIndex = sequence.find(start)
nextIndex = sequence.find(next, startIndex)
if nextIndex >= 0:
return nextIndex - startIndex
else:
return len(sequence) - startIndex + sequence.find(next)
def total_distance(sequence):
total = 0
lastChar = "r"
for char in sequence:
total += distance(lastChar, char)
lastChar = char
return total
if __name__ == '__main__':
print(total_distance(sys.argv[1]))