2022: Day 1 - 4

This commit is contained in:
ngb 2022-12-04 07:27:32 +01:00
parent bb8f6e1e8a
commit 78279014e0
12 changed files with 6271 additions and 0 deletions

13
2022/day1_1.py Normal file
View File

@ -0,0 +1,13 @@
max_cal = 0
with open('day1_input.txt', 'r') as f:
sum = 0
for line in f.readlines():
if line.strip():
sum += int(line)
else:
if sum > max_cal:
max_cal = sum
sum = 0
print(max_cal)

14
2022/day1_2.py Normal file
View File

@ -0,0 +1,14 @@
calories = list()
with open('day1_input.txt', 'r') as f:
_sum = 0
for line in f.readlines():
if line.strip():
_sum += int(line)
else:
calories.append(_sum)
_sum = 0
calories.sort(reverse=True)
print(calories[0:3])
print(sum(calories[0:3]))

2248
2022/day1_input.txt Normal file

File diff suppressed because it is too large Load Diff

34
2022/day2_1.py Normal file
View File

@ -0,0 +1,34 @@
# A = Rock = 1 = X
# B = Paper = 2 = Y
# C = Scissors = 3 = Z
score_map = {
'A X': 3 + 1,
'A Y': 6 + 2,
'A Z': 0 + 3,
'B X': 0 + 1,
'B Y': 3 + 2,
'B Z': 6 + 3,
'C X': 6 + 1,
'C Y': 0 + 2,
'C Z': 3 + 3
}
## Read input file
input = []
with open('day2_input.txt', 'r') as f:
for line in f.readlines():
input.append(line.strip())
# Solve problem
def run():
total = 0
for line in input:
total += score_map[line]
print(total)
if __name__ == '__main__':
run()

38
2022/day2_2.py Normal file
View File

@ -0,0 +1,38 @@
# A = Rock = 1
# B = Paper = 2
# C = Scissors = 3
# X = lose = 0
# Y = draw = 3
# Z = win = 6
score_map = {
'A X': 3 + 0,
'A Y': 1 + 3,
'A Z': 2 + 6,
'B X': 1 + 0,
'B Y': 2 + 3,
'B Z': 3 + 6,
'C X': 2 + 0,
'C Y': 3 + 3,
'C Z': 1 + 6
}
## Read input file
input = []
with open('day2_input.txt', 'r') as f:
for line in f.readlines():
input.append(line.strip())
# Solve problem
def run():
total = 0
for line in input:
total += score_map[line]
print(total)
if __name__ == '__main__':
run()

2500
2022/day2_input.txt Normal file

File diff suppressed because it is too large Load Diff

29
2022/day3_1.py Normal file
View File

@ -0,0 +1,29 @@
## Read input file
input = []
with open('day3_input.txt', 'r') as f:
for line in f.readlines():
input.append(line.strip())
# Solve problem
def run():
total = 0
for line in input:
l = int(len(line) / 2)
left, right = set(line[:l]), set(line[l:])
isect = left.intersection(right)
for i in isect:
common = i
if common.islower():
total += ord(common) - 96
else:
total += ord(common) - 38
print(total)
if __name__ == '__main__':
run()

35
2022/day3_2.py Normal file
View File

@ -0,0 +1,35 @@
## Read input file
input = []
with open('day3_input.txt', 'r') as f:
for line in f.readlines():
input.append(line.strip())
# Solve problem
def run():
total = 0
group = []
for line in input:
if len(group) < 3:
group.append(set(line))
if len(group) == 3:
isect = group[0].intersection(group[1], group[2])
if len(isect) > 1:
print(isect)
for i in isect:
common = i
if common.islower():
total += ord(common) - 96
else:
total += ord(common) - 38
group = []
print(total)
if __name__ == '__main__':
run()

300
2022/day3_input.txt Normal file
View File

@ -0,0 +1,300 @@
gvNbShZZgQfWdQhdPQmggLTFLwmwjFqjVVgM
CsJnHllcsnnnnJrGRnRwPPLVmFLHLBjFFVHmPT
JlnCtctJnJDcJlDCRpPrSSQWfphzWZfbZSvfNfbS
WjvRSdSQjvpjWzNlnZlNZqCCMzZZ
nJtJsbctPBPwLNcDZNNGLClC
tsFJHBgJwgJbnvSHHWVWHhVhpQ
zRzPhCCSHVZzfGHZ
qBsWBpqBwBcvqqWgdfZrprdggPHHVZ
WWmvwvBbnWmnwvWcbmWWnqNCRSDRRSSjjSDbPJbRjClLhC
rQrznfHHhrHzllzlzTGcJgtJ
jhhjjSZVPWVZvSFtTttLTglgFtvm
dqSCqVWdbDSSVqbVVSqhNdrnpnCnfsnnwfnsRpMpBMrf
rTnvrSSHvHtnDQVDtfmW
ZjCglhcCJschpZbZgbtGmRtbGmwtQtbmtN
FFZCghFJhlslFpjcdFTPLHHmrqTMTdzBLHLH
WzDfrDwwDCCDMnfDHHJjTHTtNdngdHtQ
FmScGPPPPm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bGGrSSJgWvlScptFmwbmfHHBfsNFmBbfsFm

30
2022/day4_1.py Normal file
View File

@ -0,0 +1,30 @@
## Read input file
input = []
with open('day4_input.txt', 'r') as f:
for line in f.readlines():
input.append(line)
# Solve problem
def run():
count = 0
for line in input:
first, second = line.split(',')
first = make_range(first)
second = make_range(second)
if is_in(first, second) or is_in(second, first):
count += 1
print(count)
def make_range( a ):
return tuple(int(i) for i in a.split('-'))
def is_in( r1, r2 ):
return r1[0] <= r2[0] and r1[1] >= r2[1]
if __name__ == '__main__':
run()

30
2022/day4_2.py Normal file
View File

@ -0,0 +1,30 @@
## Read input file
input = []
with open('day4_input.txt', 'r') as f:
for line in f.readlines():
input.append(line)
# Solve problem
def run():
count = 0
for line in input:
first, second = line.split(',')
first = make_range(first)
second = make_range(second)
if overlaps(first, second) or overlaps(second, first):
count += 1
print(count)
def make_range( a ):
return tuple(int(i) for i in a.split('-'))
def overlaps( r1, r2 ):
return not (r2[1] < r1[0] or r2[0] > r1[1])
if __name__ == '__main__':
run()

1000
2022/day4_input.txt Normal file

File diff suppressed because it is too large Load Diff