Add problem 1 solution
This commit is contained in:
46
Problem1_1.py
Normal file
46
Problem1_1.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
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:])
|
||||||
|
|
||||||
|
if clockwise :
|
||||||
|
location += number
|
||||||
|
location %= 100
|
||||||
|
else :
|
||||||
|
location -= number
|
||||||
|
while location < 0 :
|
||||||
|
location += 100
|
||||||
|
return location
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
testArray = [
|
||||||
|
"L68",
|
||||||
|
"L30",
|
||||||
|
"R48",
|
||||||
|
"L5",
|
||||||
|
"R60",
|
||||||
|
"L55",
|
||||||
|
"L1",
|
||||||
|
"L99",
|
||||||
|
"R14",
|
||||||
|
"L82"
|
||||||
|
]
|
||||||
|
|
||||||
|
location = 50
|
||||||
|
result = 0
|
||||||
|
#movementArray = testArray
|
||||||
|
movementArray = readFile()
|
||||||
|
for movement in movementArray :
|
||||||
|
location = moveLocation(location, movement)
|
||||||
|
if location == 0 :
|
||||||
|
result += 1
|
||||||
|
print(f"Result: {result}")
|
||||||
|
|
||||||
|
#Result: 1195
|
||||||
53
Problem1_2.py
Normal file
53
Problem1_2.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
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
|
||||||
4732
files/Problem1.txt
Normal file
4732
files/Problem1.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user