Skip to content

Instantly share code, notes, and snippets.

View dartharva's full-sized avatar

Atharva Dhoble dartharva

View GitHub Profile
@dartharva
dartharva / adventofcode2022_day6.py
Created December 6, 2022 06:18
Advent of Code 2022, Day 3 - Simple, verbose python
with open('input.txt', 'r') as input_file:
input_signal = input_file.read().strip()
def signalcatch(distinct_chars):
for i in range(len(input_signal)):
buf_stream = input_signal[i:i+distinct_chars]
if len(set(buf_stream)) == len(buf_stream):
return i + distinct_chars
print(signalcatch(4), signalcatch(14))
@dartharva
dartharva / adventofcode2022_day5.py
Last active December 5, 2022 22:21
Advent of Code 2022, Day 3 - Simple, verbose python
stacks = {
1: ['M','S','J','L','V','F','N','R'],
2: ['H','W','J','F','Z','D','N','P'],
3: ['G','D','C','R','W'],
4: ['S','B','N'],
5: ['N','F','B','C','P','W','Z','M'],
6: ['W','M','R','P'],
7: ['W','S','L','G','N','T','R'],
8: ['V','B','N','F','H','T','Q'],
9: ['F','N','Z','H','M','L'],
@dartharva
dartharva / adventofcode2022_day4.py
Created December 4, 2022 18:39
Advent of Code 2022, Day 4 - Simple, verbose python
with open('input.txt', 'r') as inputfile:
assignments = [i.rsplit(',') for i in inputfile.read().split('\n')]
for x in assignments:
for i,j in enumerate(x):
k = j.split('-')
x[i] = set(range(int(k[0]), int(k[1])+1))
count_1 = 0
count_2 = 0
for i in assignments:
@dartharva
dartharva / adventofcode2022_day3.py
Created December 3, 2022 12:08
Advent of Code 2022, Day 3 - Simple, verbose python
with open('input.txt', 'r') as file:
rucksacks = file.read().strip().split()
def priority(letter):
if letter.islower():
return ord(letter) - ord('a') + 1
else:
return ord(letter) - ord('A') + 27
def common_items(rucksacks):
@dartharva
dartharva / adventofcode2022_day1.py
Created December 2, 2022 08:01
Advent of Code 2022, Day 1 - Simple, verbose python
with open('input.txt', 'r') as file:
calories = file.read().split('\n\n')
sums = [sum(int(x) for x in line.split()) for line in calories]
print(max(sums)) #Problem 1
top_3 = sorted(sums, reverse = True)[:3]
print(top_3, sum(top_3)) #Problem 2
@dartharva
dartharva / adventofcode2022_day2.py
Created December 2, 2022 07:53
Advent of Code 2022, Day 2 - Simple, verbose python.
with open('input.txt') as f:
rounds = [i.split(' ') for i in f.read().split('\n')]
#Part 1
PLAYS = {
"X": "rock",
"Y": "paper",
"Z": "scissors",
"A": "rock",