thingy
This commit is contained in:
commit
3223390d4e
24
day1-1.py
Normal file
24
day1-1.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
with open("input.txt") as file:
|
||||||
|
lines = [line.rstrip() for line in file]
|
||||||
|
|
||||||
|
first_digit = None
|
||||||
|
last_digit = None
|
||||||
|
things = []
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
first_digit = None
|
||||||
|
last_digit = None
|
||||||
|
for letter in line:
|
||||||
|
if letter.isdigit():
|
||||||
|
if first_digit is None:
|
||||||
|
first_digit = letter
|
||||||
|
last_digit = letter
|
||||||
|
else:
|
||||||
|
last_digit = letter
|
||||||
|
things.append(int(f"{first_digit}{last_digit}"))
|
||||||
|
|
||||||
|
sum = 0
|
||||||
|
for thing in things:
|
||||||
|
sum += thing
|
||||||
|
|
||||||
|
print(sum)
|
72
day1-2.py
Normal file
72
day1-2.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
with open("input.txt") as file:
|
||||||
|
lines = [line.rstrip() for line in file]
|
||||||
|
|
||||||
|
first_digit = None
|
||||||
|
last_digit = None
|
||||||
|
things = []
|
||||||
|
stupid_letters = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
||||||
|
stupid_letters_rev = ["eno", "owt", "eerht", "ruof", "evif", "xis", "neves", "thgie", "enin"]
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
first_digit = None
|
||||||
|
last_digit = None
|
||||||
|
|
||||||
|
letter_index = 0
|
||||||
|
for letter in line:
|
||||||
|
if letter.isdigit():
|
||||||
|
if first_digit is None:
|
||||||
|
first_digit = letter
|
||||||
|
first_digit_index = letter_index
|
||||||
|
last_digit = letter
|
||||||
|
last_digit_index = letter_index
|
||||||
|
else:
|
||||||
|
last_digit = letter
|
||||||
|
last_digit_index = letter_index
|
||||||
|
letter_index+=1
|
||||||
|
|
||||||
|
keep_going = True
|
||||||
|
#find first digit in stupid format
|
||||||
|
while (keep_going):
|
||||||
|
match = False
|
||||||
|
for stupid_letter in stupid_letters:
|
||||||
|
if line.find(stupid_letter) == -1:
|
||||||
|
continue
|
||||||
|
if line.find(stupid_letter) < first_digit_index:
|
||||||
|
first_digit = stupid_letters.index(stupid_letter)+1
|
||||||
|
first_digit_index = line.find(stupid_letter)
|
||||||
|
match = True
|
||||||
|
if not match:
|
||||||
|
keep_going = False
|
||||||
|
|
||||||
|
#find last digit in stupid format by reversing the whole string bc i am very smart
|
||||||
|
rev_line = line[::-1]
|
||||||
|
new_last_digit_index = (len(line)-1) - last_digit_index
|
||||||
|
keep_going = True
|
||||||
|
|
||||||
|
while (keep_going):
|
||||||
|
match = False
|
||||||
|
for stupid_letter in stupid_letters_rev:
|
||||||
|
#print(stupid_letter)
|
||||||
|
#time.sleep(1)
|
||||||
|
if rev_line.find(stupid_letter) == -1:
|
||||||
|
continue
|
||||||
|
if rev_line.find(stupid_letter) < new_last_digit_index:
|
||||||
|
#print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
||||||
|
last_digit = stupid_letters_rev.index(stupid_letter)+1
|
||||||
|
new_last_digit_index = rev_line.find(stupid_letter)
|
||||||
|
match = True
|
||||||
|
|
||||||
|
if not match:
|
||||||
|
keep_going = False
|
||||||
|
|
||||||
|
things.append(int(f"{first_digit}{last_digit}"))
|
||||||
|
print(int(f"{first_digit}{last_digit}"))
|
||||||
|
|
||||||
|
sum = 0
|
||||||
|
for thing in things:
|
||||||
|
sum += thing
|
||||||
|
|
||||||
|
print(sum)
|
||||||
|
|
44
day2-1.py
Normal file
44
day2-1.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
with open("input_day2.txt") as file:
|
||||||
|
lines = [line.rstrip() for line in file]
|
||||||
|
|
||||||
|
class colour_thing:
|
||||||
|
def __init__(self,red=0,green=0,blue=0):
|
||||||
|
self.red = int(red)
|
||||||
|
self.green = int(green)
|
||||||
|
self.blue = int(blue)
|
||||||
|
def add_rgb(self,red=0,green=0,blue=0):
|
||||||
|
self.red += int(red)
|
||||||
|
self.green += int(green)
|
||||||
|
self.blue += int(blue)
|
||||||
|
sum = 0
|
||||||
|
game_id = 1
|
||||||
|
for line in lines:
|
||||||
|
id_valid = True
|
||||||
|
string = line.split(": ")[1]
|
||||||
|
draws = string.split("; ")
|
||||||
|
game = []
|
||||||
|
for draw in draws:
|
||||||
|
temp_colour_thing = colour_thing()
|
||||||
|
colours = draw.split(", ")
|
||||||
|
for colour in colours:
|
||||||
|
count,split_colour = colour.split(" ")
|
||||||
|
match split_colour:
|
||||||
|
case "red":
|
||||||
|
temp_colour_thing.add_rgb(red=count)
|
||||||
|
case "green":
|
||||||
|
temp_colour_thing.add_rgb(green=count)
|
||||||
|
case "blue":
|
||||||
|
temp_colour_thing.add_rgb(blue=count)
|
||||||
|
game.append(temp_colour_thing)
|
||||||
|
for thing in game:
|
||||||
|
if thing.red > 12 or thing.green > 13 or thing.blue > 14:
|
||||||
|
id_valid = False
|
||||||
|
if id_valid:
|
||||||
|
print(f"{game_id} is valid")
|
||||||
|
sum+=game_id
|
||||||
|
else:
|
||||||
|
print(f"{game_id} is not valid")
|
||||||
|
game_id+=1
|
||||||
|
print(sum)
|
49
day2-2.py
Normal file
49
day2-2.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
with open("input_day2.txt") as file:
|
||||||
|
lines = [line.rstrip() for line in file]
|
||||||
|
|
||||||
|
class colour_thing:
|
||||||
|
def __init__(self,red=0,green=0,blue=0):
|
||||||
|
self.red = int(red)
|
||||||
|
self.green = int(green)
|
||||||
|
self.blue = int(blue)
|
||||||
|
def add_rgb(self,red=0,green=0,blue=0):
|
||||||
|
self.red += int(red)
|
||||||
|
self.green += int(green)
|
||||||
|
self.blue += int(blue)
|
||||||
|
sum = 0
|
||||||
|
game_id = 1
|
||||||
|
for line in lines:
|
||||||
|
id_valid = True
|
||||||
|
string = line.split(": ")[1]
|
||||||
|
draws = string.split("; ")
|
||||||
|
game = []
|
||||||
|
for draw in draws:
|
||||||
|
temp_colour_thing = colour_thing()
|
||||||
|
colours = draw.split(", ")
|
||||||
|
for colour in colours:
|
||||||
|
count,split_colour = colour.split(" ")
|
||||||
|
match split_colour:
|
||||||
|
case "red":
|
||||||
|
temp_colour_thing.add_rgb(red=count)
|
||||||
|
case "green":
|
||||||
|
temp_colour_thing.add_rgb(green=count)
|
||||||
|
case "blue":
|
||||||
|
temp_colour_thing.add_rgb(blue=count)
|
||||||
|
game.append(temp_colour_thing)
|
||||||
|
min_red = 0
|
||||||
|
min_green = 0
|
||||||
|
min_blue = 0
|
||||||
|
for thing in game:
|
||||||
|
if thing.red > min_red:
|
||||||
|
min_red = thing.red
|
||||||
|
if thing.green > min_green:
|
||||||
|
min_green = thing.green
|
||||||
|
if thing.blue > min_blue:
|
||||||
|
min_blue = thing.blue
|
||||||
|
power = min_red*min_green*min_blue
|
||||||
|
sum+=power
|
||||||
|
|
||||||
|
game_id+=1
|
||||||
|
print(sum)
|
Loading…
Reference in New Issue
Block a user