commit 523f45b46ab09b937d5c91c8e5b3e74f7407f20e Author: Ultrablob Date: Mon Jan 20 11:37:00 2025 -0500 add to gothib diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..917ab61 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.venv/ +input.txt \ No newline at end of file diff --git a/aoc/day3.py b/aoc/day3.py new file mode 100644 index 0000000..f19ebd4 --- /dev/null +++ b/aoc/day3.py @@ -0,0 +1,13 @@ +import re + +instruction = re.compile(r"mul\((\d+),(\d+)\)") + +re. +data = re.findall(instruction, open("aoc/input.txt", "r").read()) + +total = 0 + +for n1, n2 in data: + total += int(n1) * int(n2) + +print(total) \ No newline at end of file diff --git a/art_frame.py b/art_frame.py new file mode 100644 index 0000000..87ac2ee --- /dev/null +++ b/art_frame.py @@ -0,0 +1,17 @@ +points = int(input()) +max_x = 0 +max_y = 0 +min_x = 100 +min_y = 100 + +for i in range(points): + x, y = tuple(map(int, input().split(","))) + + max_x = max(max_x, x) + max_y = max(max_y, y) + + min_y = min(min_y, y) + min_x = min(min_x, x) + +print(f"{min_x-1},{min_y-1}") +print(f"{max_x+1},{max_y+1}") \ No newline at end of file diff --git a/binary_search_example.py b/binary_search_example.py new file mode 100644 index 0000000..8c53a18 --- /dev/null +++ b/binary_search_example.py @@ -0,0 +1,5 @@ +from bisect import bisect_left + +items = [5, 8, 2, 3] + +print(bisect_left(sorted(items), 2)) \ No newline at end of file diff --git a/boba.py b/boba.py new file mode 100644 index 0000000..451c0ff --- /dev/null +++ b/boba.py @@ -0,0 +1,20 @@ +a = 0 +b = 0 + +n = input("") + +votes = input("") + +for vote in votes: + if vote == "A": + a += 1 + elif vote == "B": + b += 1 + + +if a > b: + print("A") +elif a < b: + print("B") +else: + print("Tie") \ No newline at end of file diff --git a/book_sorting.py b/book_sorting.py new file mode 100644 index 0000000..f344b78 --- /dev/null +++ b/book_sorting.py @@ -0,0 +1,4 @@ +# i gave up :skull: + +for book in input(""): + \ No newline at end of file diff --git a/chess.py b/chess.py new file mode 100644 index 0000000..cf97d53 --- /dev/null +++ b/chess.py @@ -0,0 +1,10 @@ +VALUES = { + "queen": 9, + "rook": 5, + "bishop": 3, + "knight": 3, + "pawn": 1, + "king": "priceless" +} + +print(VALUES[input("")]) \ No newline at end of file diff --git a/coal_counting.py b/coal_counting.py new file mode 100644 index 0000000..508e592 --- /dev/null +++ b/coal_counting.py @@ -0,0 +1,12 @@ +from bisect import bisect_left + +num_children, years = tuple(map(int, input("").split(" "))) + +children = sorted(map(int, input("").split(" "))) + +coal_thresholds = list(map(int, input("").split(" "))) + +for threshold in coal_thresholds: + coal = num_children - bisect_left(children, threshold) + + print(coal) \ No newline at end of file diff --git a/dmoj_test.py b/dmoj_test.py new file mode 100644 index 0000000..e69de29 diff --git a/doubleo7.py b/doubleo7.py new file mode 100644 index 0000000..4c42eb2 --- /dev/null +++ b/doubleo7.py @@ -0,0 +1,36 @@ +num_actions = int(input("")) + +my_ammo = 0 +my_score = 0 + +their_ammo = 0 + +for their_action in input(""): + + if their_action == "R": + their_ammo += 1 + + if their_action == "R" and my_ammo == 0: + # print("R", end="") + my_ammo += 1 + elif their_action == "R" and my_ammo > 0: + # print("F", end="") + my_ammo -= 1 + my_score += 1 + elif their_action == "B": + # print("R", end="") + my_ammo += 1 + elif their_action == "F" and their_ammo > 0: + # print("B", end="") + their_ammo -= 1 + pass + elif their_action == "F" and their_ammo == 0: + if my_ammo > 0: + # print("F", end="") + my_ammo -= 1 + my_score += 1 + else: + # print("R", end="") + my_ammo += 1 + +print(my_score) \ No newline at end of file diff --git a/enraged.py b/enraged.py new file mode 100644 index 0000000..b0e690f --- /dev/null +++ b/enraged.py @@ -0,0 +1,17 @@ +columns = int(input("")) + +murders_acceptable = 2 + +row1 = input("") +row2 = input("") + +for cell1, cell2 in zip(row1, row2): + if cell1 == "S" and cell2 == "S": + murders_acceptable -= 1 + if murders_acceptable == -1: + break + +if murders_acceptable == -1: + print("NO") +else: + print("YES") \ No newline at end of file diff --git a/hacking_grades.py b/hacking_grades.py new file mode 100644 index 0000000..cd726b6 --- /dev/null +++ b/hacking_grades.py @@ -0,0 +1,24 @@ +courses, points = tuple(map(int, input("").split(" "))) + +numerators = map(int, input("").split(" ")) +denominators = map(int, input("").split(" ")) + +fitness = lambda frac: (frac[0]+1)/(frac[1]+1) - (frac[0]/frac[1]) + +fractions = list(sorted(zip(numerators, denominators), key=fitness, reverse=True)) + +i = 0 + +for point in range(points): + # print(fractions[0][0], "/", fractions[0][1], "=", fractions[0][0]/fractions[0][1]) + fractions[0] = (fractions[i][0]+1, fractions[i][1]+1) + + if len(fractions) >= 2 and fitness(fractions[0]) < fitness(fractions[1]): + fractions.sort(key=fitness, reverse=True) + +total = 0 + +for (num, denom) in fractions: + total += num/denom + +print((total/courses)*100) diff --git a/input.txt b/input.txt new file mode 100644 index 0000000..c4f70e2 --- /dev/null +++ b/input.txt @@ -0,0 +1,3 @@ +2 +1 2 3 4 5 6 +4 3 2 1 6 4 \ No newline at end of file diff --git a/magic_barrier.py b/magic_barrier.py new file mode 100644 index 0000000..5be6b98 --- /dev/null +++ b/magic_barrier.py @@ -0,0 +1,27 @@ +import sys + +barrier = {} + +rows, columns, questions = [int(x) for x in input("").split()] + +for row in range(rows): + line = sys.stdin.readline() + for (column, value) in enumerate(map(int, line.split(" "))): + barrier[value] = (row+1, column+1) + +# print(barrier) + +for i in range(questions): + k, minrow, mincol, maxrow, maxcol = (int(x) for x in sys.stdin.readline().split(" ")) + + if k not in barrier: + print("no") + continue + + row, col = barrier[k] + + if (minrow <= row <= maxrow) and (mincol <= col <= maxcol): + print("yes") + continue + + print("no") diff --git a/modern_art.py b/modern_art.py new file mode 100644 index 0000000..5c4efaa --- /dev/null +++ b/modern_art.py @@ -0,0 +1,28 @@ +width = int(input("")) +height = int(input("")) +num_strokes = int(input("")) + +rows = [0] * width +columns = [0] * height + +for stroke in range(num_strokes): + target, number = input("").split(" ") + + if target == "C": + for i in range(height): + print(i, int(number)) + cells[i][int(number)-1] = not cells[i][int(number)-1] + print(cells) + else: + for i in range(width): + print(i, int(number)) + cells[int(number)-1][i] = not cells[int(number)-1][i] + print(cells) + +total = 0 +for row in cells: + for cell in row: + if cell: + total += 1 + +print(total) \ No newline at end of file diff --git a/parking.py b/parking.py new file mode 100644 index 0000000..6bd2f97 --- /dev/null +++ b/parking.py @@ -0,0 +1,12 @@ +num = int(input()) + +day1 = list(input()) +day2 = list(input()) + +total = 0 + +for first, second in zip(day1, day2): + if first == "C" and second == "C": + total += 1 + +print(total) \ No newline at end of file diff --git a/partners.py b/partners.py new file mode 100644 index 0000000..9d0e454 --- /dev/null +++ b/partners.py @@ -0,0 +1,24 @@ +num = int(input()) + +person1 = input().split(" ") +person2 = input().split(" ") + +partners = {} + +for partner1, partner2 in zip(person1, person2): + if partner1 in partners and partners[partner1] != partner2: + print("bad") + break + + if partner2 in partners and partners[partner2] != partner1: + print("bad") + break + + if partner1 == partner2: + print("bad") + break + + partners[partner1] = partner2 + +else: + print("good") \ No newline at end of file diff --git a/permutations.py b/permutations.py new file mode 100644 index 0000000..e69de29 diff --git a/prefix_array.py b/prefix_array.py new file mode 100644 index 0000000..6d2ee9a --- /dev/null +++ b/prefix_array.py @@ -0,0 +1,22 @@ +import sys +input_data = sys.stdin.read().split('\n') + +num_trees = int(input_data[0]) +tree_masses = tuple(map(int, input_data[1:num_trees+1])) + +num_queries = int(input_data[num_trees+1]) +queries = tuple(map(lambda x: tuple(map(int, x.split(" "))), input_data[num_trees+2:])) + +# print(f"trees: {tree_masses} ({num_trees})") +# print(f"queries: {num_queries} ({num_queries})") + +psa = [0] + +for i in range(1, num_trees+1): + psa.append(psa[i-1] + tree_masses[i-1]) + +# print(psa) + +for (start, end) in queries: + # print(start, end) + print(psa[end+1] - psa[start]) \ No newline at end of file diff --git a/rhyme.py b/rhyme.py new file mode 100644 index 0000000..db8609b --- /dev/null +++ b/rhyme.py @@ -0,0 +1,11 @@ +for i in range(int(input(""))): + x, y = input("").split(" ") + + if x.endswith("17") or y.endswith("17"): + print("NO") + + elif (x.endswith("7") and y.endswith("11")) or (x.endswith("11") and y.endswith("7")): + print("YES") + + else: + print("NO") \ No newline at end of file diff --git a/secret_instructions.py b/secret_instructions.py new file mode 100644 index 0000000..e95eee2 --- /dev/null +++ b/secret_instructions.py @@ -0,0 +1,20 @@ +last_direction = None + +while True: + instruction = input() + + if instruction == "99999": + break + + direction = int(instruction[0]) + int(instruction[1]) + amount = int(instruction[2:]) + + if amount == 0: + direction = last_direction + + if direction % 2 == 0: + print("right", amount) + else: + print("left", amount) + + last_direction = direction \ No newline at end of file diff --git a/snowflakes.py b/snowflakes.py new file mode 100644 index 0000000..982c228 --- /dev/null +++ b/snowflakes.py @@ -0,0 +1,13 @@ +num = int(input()) + +snowflakes = {} + +for i in range(num): + snowflake = sum(int(x) for x in input().split(" ")) + if snowflake in snowflakes: + print("Twin snowflakes found.") + quit() + + snowflakes[snowflake] = True + +print("No two snowflakes are alike.") \ No newline at end of file diff --git a/special_day.py b/special_day.py new file mode 100644 index 0000000..01eafd4 --- /dev/null +++ b/special_day.py @@ -0,0 +1,17 @@ +month = int(input("")) +day = int(input("")) + +if month > 2: + print("After") + +elif month < 2: + print("Before") + +elif day < 18: + print("Before") + +elif day > 18: + print("After") + +else: + print("Special") \ No newline at end of file diff --git a/spooky.py b/spooky.py new file mode 100644 index 0000000..d55ebcc --- /dev/null +++ b/spooky.py @@ -0,0 +1 @@ +print("sp" + "o" * int(input("")) + "ky") \ No newline at end of file diff --git a/spooky4you.py b/spooky4you.py new file mode 100644 index 0000000..9a3700c --- /dev/null +++ b/spooky4you.py @@ -0,0 +1,29 @@ +""" +make a bunch tuples of range() objects for each decoration and then if in the object add n +""" + +n, l, max_spook = tuple(map(int, input().split(" "))) + +candy = 0 + +decorations = [] + +for _ in range(n): + a, b, s = tuple(map(int, input().split(" "))) + decorations.append((range(a, b+1), s)) + +for i in range(l): + spook_factor = 0 + + for deco, spookiness in decorations: + if i in deco: + spook_factor += abs(spookiness) + + if spook_factor < max_spook: + candy += 1 + + +if candy == 1: + print(0) #off by one error lol +else: + print(candy) \ No newline at end of file diff --git a/test_anxiety.py b/test_anxiety.py new file mode 100644 index 0000000..b83c820 --- /dev/null +++ b/test_anxiety.py @@ -0,0 +1,19 @@ +average = int(input("")) + +assignments = int(input("")) + +""" +(average*2+x)/3=80 +average*2+x=240 +x=240-average*2 + +""" + +required = 80*(assignments+1) - average*assignments + +if required > 100: + print("-1") +elif required < 0: + print("0") +else: + print(required) \ No newline at end of file diff --git a/trident.py b/trident.py new file mode 100644 index 0000000..979d93a --- /dev/null +++ b/trident.py @@ -0,0 +1,13 @@ +tines = int(input("")) +spacing = int(input("")) +handle = int(input("")) + +for i in range(tines): + print((("*" + " " * spacing) * 3).strip()) + +width = 3+(spacing*2) + +print(("*" * width).strip()) + +for i in range(handle): + print(" " * (width//2) + "*") \ No newline at end of file diff --git a/votes.py b/votes.py new file mode 100644 index 0000000..451c0ff --- /dev/null +++ b/votes.py @@ -0,0 +1,20 @@ +a = 0 +b = 0 + +n = input("") + +votes = input("") + +for vote in votes: + if vote == "A": + a += 1 + elif vote == "B": + b += 1 + + +if a > b: + print("A") +elif a < b: + print("B") +else: + print("Tie") \ No newline at end of file