This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |