Skip to content

Commit 5149363

Browse files
committed
First 4 days implemented
0 parents  commit 5149363

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 🎄 Advent of Code 2022 solutions 🎄
2+
3+
This repository contains my solutions for AoC 2022 written in **Python** 🐍 I kindly ask all visitors ***not to judge*** code quality or maintainability, due to the following reason:
4+
- it is a time oriented competition ⏰ - meaning just find the solution to the problem ASAP,
5+
- I tend to overcomplicate solutions with list comprehensions and functional programming approach
6+
- most of the time, there is an easier solution available, but I like to sharpen my functional approach 😇
7+
8+
Thanks for stopping by 👋 If you like any of the solutions drop a ⭐ to this repository.
9+
10+
Don't forget to support [Advent of code](https://adventofcode.com/2022/support).

day01.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
with open('inputs/day01.txt', 'r') as data:
2+
elf_cal = sorted([sum(map(int,cals_per_elf.split('\n'))) for cals_per_elf in data.read().split('\n\n')])
3+
print('Most calories: '+str(elf_cal[-1]))
4+
print(' Top three: '+str(sum(elf_cal[-3:])))

day02.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# part1
2+
scores1 = {
3+
'A X': 4,
4+
'A Y': 8,
5+
'A Z': 3,
6+
'B X': 1,
7+
'B Y': 5,
8+
'B Z': 9,
9+
'C X': 7,
10+
'C Y': 2,
11+
'C Z': 6,
12+
}
13+
14+
# part2
15+
scores2 = {
16+
'A X': 3,
17+
'A Y': 4,
18+
'A Z': 8,
19+
'B X': 1,
20+
'B Y': 5,
21+
'B Z': 9,
22+
'C X': 2,
23+
'C Y': 6,
24+
'C Z': 7,
25+
}
26+
27+
with open('inputs/day02.txt', 'r') as data:
28+
match_data = data.read().split('\n')
29+
print('Part1: ',sum(map(lambda match : scores1[match], match_data)))
30+
print('Part2: ',sum(map(lambda match : scores2[match], match_data)))

day03.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
with open("inputs/day03.txt") as f:
2+
data = f.read().splitlines()
3+
4+
score = lambda x : ord(x) - ord('a') + 1 if x >= 'a' and x <= 'z' else ord(x) - ord('A') + 27
5+
6+
part1 = sum(score(set(x[:len(x)//2]).intersection(set(x[len(x)//2:])).pop()) for x in data)
7+
print ('Part1: ',part1)
8+
9+
iter_data = iter(data)
10+
part2 = sum(score(set(x[0]).intersection(set(x[1])).intersection(set(x[2])).pop()) for x in zip(iter_data,iter_data,iter_data))
11+
print ('Part2: ',part2)

day04.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
with open('inputs/day04.txt') as f:
2+
data = [list(map(int,line.replace(',','-').split('-'))) for line in f.read().splitlines()]
3+
4+
overlap_full = sum(map(lambda x : (x[0] <= x[2] and x[1] >= x[3]) or (x[2] <= x[0] and x[3] >= x[1]), data))
5+
print('Part 1: ', overlap_full)
6+
7+
overlap_count = sum(map(lambda x : (x[0] <= x[2] and x[1] >= x[2]) or (x[2] <= x[0] and x[3] >= x[0]), data))
8+
print('Part 2: ', overlap_count)

0 commit comments

Comments
 (0)