54 lines
893 B
Python
54 lines
893 B
Python
def readFile():
|
|
ary = []
|
|
with open("files/Problem1.txt") as file:
|
|
for line in file:
|
|
ary.append(line)
|
|
return ary
|
|
|
|
def moveLocation(location: int, movement: str) -> int:
|
|
clockwise = movement[0] == 'R'
|
|
number = int(movement[1:])
|
|
crossedZero = 0
|
|
|
|
if clockwise :
|
|
location += number
|
|
while location >= 100 :
|
|
location -= 100
|
|
crossedZero += 1
|
|
else :
|
|
if location == 0 :
|
|
location += 100
|
|
location -= number
|
|
while location < 0 :
|
|
location += 100
|
|
crossedZero += 1
|
|
if location == 0 :
|
|
crossedZero += 1
|
|
return [location, crossedZero]
|
|
|
|
|
|
|
|
testArray = [
|
|
"L68",
|
|
"L30",
|
|
"R48",
|
|
"L5",
|
|
"R60",
|
|
"L55",
|
|
"L1",
|
|
"L99",
|
|
"R14",
|
|
"L82"
|
|
]
|
|
|
|
location = 50
|
|
result = 0
|
|
#movementArray = testArray
|
|
movementArray = readFile()
|
|
for movement in movementArray :
|
|
[location, crossedZero] = moveLocation(location, movement)
|
|
result += crossedZero
|
|
print(f"Result: {result}")
|
|
|
|
#Result: 6770
|