add to gothib

This commit is contained in:
Ultrablob 2025-01-20 11:37:00 -05:00
commit 523f45b46a
28 changed files with 419 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.venv/
input.txt

13
aoc/day3.py Normal file
View file

@ -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)

17
art_frame.py Normal file
View file

@ -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}")

5
binary_search_example.py Normal file
View file

@ -0,0 +1,5 @@
from bisect import bisect_left
items = [5, 8, 2, 3]
print(bisect_left(sorted(items), 2))

20
boba.py Normal file
View file

@ -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")

4
book_sorting.py Normal file
View file

@ -0,0 +1,4 @@
# i gave up :skull:
for book in input(""):

10
chess.py Normal file
View file

@ -0,0 +1,10 @@
VALUES = {
"queen": 9,
"rook": 5,
"bishop": 3,
"knight": 3,
"pawn": 1,
"king": "priceless"
}
print(VALUES[input("")])

12
coal_counting.py Normal file
View file

@ -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)

0
dmoj_test.py Normal file
View file

36
doubleo7.py Normal file
View file

@ -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)

17
enraged.py Normal file
View file

@ -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")

24
hacking_grades.py Normal file
View file

@ -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)

3
input.txt Normal file
View file

@ -0,0 +1,3 @@
2
1 2 3 4 5 6
4 3 2 1 6 4

27
magic_barrier.py Normal file
View file

@ -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")

28
modern_art.py Normal file
View file

@ -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)

12
parking.py Normal file
View file

@ -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)

24
partners.py Normal file
View file

@ -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")

0
permutations.py Normal file
View file

22
prefix_array.py Normal file
View file

@ -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])

11
rhyme.py Normal file
View file

@ -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")

20
secret_instructions.py Normal file
View file

@ -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

13
snowflakes.py Normal file
View file

@ -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.")

17
special_day.py Normal file
View file

@ -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")

1
spooky.py Normal file
View file

@ -0,0 +1 @@
print("sp" + "o" * int(input("")) + "ky")

29
spooky4you.py Normal file
View file

@ -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)

19
test_anxiety.py Normal file
View file

@ -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)

13
trident.py Normal file
View file

@ -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) + "*")

20
votes.py Normal file
View file

@ -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")