Initial Commit and finished day 1!
This commit is contained in:
commit
9d257c8aec
4
README.md
Normal file
4
README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Advent of Code 2024
|
||||
Bearded Eagle's Advent of code solutions. Most of my solutions will be in Python unless I'm feeling a bit adventurous that day.
|
||||
|
||||
*2024 - C. Massey Griffin*
|
||||
34
day01/day01.py
Normal file
34
day01/day01.py
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
#INPUT = './day01/sampleinput.txt'
|
||||
INPUT = './day01/input.txt'
|
||||
|
||||
def parse_input(file_input:str):
|
||||
leftcol = []
|
||||
rightcol = []
|
||||
with open(file_input) as ifile:
|
||||
for line in ifile.readlines():
|
||||
spair = line.strip().split(' ')
|
||||
leftcol.append(int(spair[0]))
|
||||
rightcol.append(int(spair[1]))
|
||||
return leftcol, rightcol
|
||||
|
||||
def p1_solve(left, right):
|
||||
left.sort()
|
||||
right.sort()
|
||||
result = 0
|
||||
for i in range(len(left)):
|
||||
result += abs(left[i] - right[i])
|
||||
print('Answer to part 1 is: {}'.format(result))
|
||||
|
||||
def p2_solve(left, right):
|
||||
result = 0
|
||||
for i in range(len(left)):
|
||||
num = left[i]
|
||||
result += num * right.count(num)
|
||||
print('Answer to part 2 is: {}'.format(result))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
l,r = parse_input(INPUT)
|
||||
p1_solve(l,r)
|
||||
p2_solve(l,r)
|
||||
1000
day01/input.txt
Normal file
1000
day01/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
6
day01/sampleinput.txt
Normal file
6
day01/sampleinput.txt
Normal file
@ -0,0 +1,6 @@
|
||||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
||||
Loading…
Reference in New Issue
Block a user