Question 4: More Python
path=''
x=-66
y=1007
breadcrumbs = []
def countSteps(steps, direction):
return len(steps) - len(steps.replace(direction, ''))
with open('path.txt','r') as pathFile:
path = pathFile.read()
splitPath = path.split('*')
smallestX=10000
biggestX=0
smallestY=10000
biggestY=0
for steps in splitPath:
x += (countSteps(steps,'S') - countSteps(steps, 'N'))
y += (countSteps(steps,'W') - countSteps(steps, 'E'))
if x < smallestX:
smallestX = x
if y < smallestY:
smallestY = y
if x > biggestX:
biggestX = x
if y > biggestY:
biggestY = y
breadcrumbs.append([x, y])
line = 0
lineString = ""
for item in sorted(breadcrumbs):
if item[0] == line:
lineString += ' ' * (item[1] - len(lineString) - 1) + 'X'
else:
print(lineString)
line += 1
lineString = ' ' * (item[1] - len(lineString) - 1) + 'X'
print(lineString)