Compare commits

...

10 Commits

Author SHA1 Message Date
38610bdd11 Luhn's Checksum Algorithm 2023-10-17 22:46:33 +02:00
de8643b5f2 Loo Rolls 2023-10-17 22:34:39 +02:00
786cf4dc88 Joint Jog Jam 2023-10-17 22:10:00 +02:00
a3320343ef School Spirit 2023-10-17 21:50:25 +02:00
a309dad256 Triple Texting 2023-10-17 21:34:52 +02:00
f5925dedeb Birthday Memorization 2023-10-17 21:26:11 +02:00
2ebdbbc5b5 Goomba Stacks 2023-10-17 21:15:09 +02:00
986dc102d7 Arithmetic Functions 2023-10-17 21:08:16 +02:00
26347645b6 Basketball One-on-One 2023-10-17 20:59:27 +02:00
49a86bff16 Conformity 2023-10-17 20:42:54 +02:00
11 changed files with 171 additions and 0 deletions

21
arithmeticfunctions.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include "arithmeticfunctions.h"
#include <cmath>
// Compute x^3
int cube(int x){
return pow(x, 3);
}
// Compute the maximum of x and y
int max(int x, int y){
if (x>y) {
return x;
} else {
return y;
}
}
// Compute x - y
int difference(int x, int y){
return x - y;
}

20
arithmeticfunctions.h Normal file
View File

@@ -0,0 +1,20 @@
#include <iostream>
int cube(int x);
int max(int x, int y);
int difference(int x, int y);
int main() {
int cube2 = cube(2);
if (cube2 != 8) {
std::cout << "ERROR: cube(2) = " << cube2 << ", expected 8" << std::endl;
}
int max85 = max(8, 5);
if (max85 != 8) {
std::cout << "ERROR: max(8, 5) = " << max85 << ", expected 8" << std::endl;
}
int diff102 = difference(10, 2);
if (diff102 != 8) {
std::cout << "ERROR: difference(10, 2) = " << diff102 << ", expected 8" << std::endl;
}
}

19
basketballoneonone.py Normal file
View File

@@ -0,0 +1,19 @@
def end_game(winner):
print(winner)
exit()
game_records = input()
a_score = 0
b_score = 0
for i in range(0, len(game_records), 2):
if game_records[i] == "A":
a_score += int(game_records[i + 1])
else:
b_score += int(game_records[i + 1])
if a_score >= 11 and (b_score < 10 or a_score - b_score >= 2):
end_game("A")
if b_score >= 11 and (a_score < 10 or b_score - a_score >= 2):
end_game("B")

21
conformity.py Normal file
View File

@@ -0,0 +1,21 @@
n = int(input())
combinations = {}
maxcombi = 0
combinations[maxcombi] = 0
for _ in range(n):
combi = "".join(sorted(input().strip().split()))
if combi in combinations.keys():
combinations[combi] += 1
if combinations[maxcombi] < combinations[combi]:
maxcombi = combi
else:
combinations[combi] = 1
max_value = combinations[maxcombi]
most_popular = sum(
[max_value for key in combinations if combinations[key] == max_value]
)
print(most_popular if most_popular > 0 else len(combinations.keys()) - 1)

View File

@@ -0,0 +1,21 @@
n = int(input())
memory = {}
names = []
for _ in range(n):
name, likes, birthday = input().split()
likes = int(likes)
if birthday in memory.keys():
if memory[birthday][1] < likes:
names.remove(memory[birthday][0])
memory[birthday] = (name, likes)
names.append(name)
else:
memory[birthday] = (name, likes)
names.append(name)
print(len(memory.keys()))
names.sort()
for name in names:
print(name)

9
goombastacks.py Normal file
View File

@@ -0,0 +1,9 @@
n = int(input())
g_total = 0
for _ in range(n):
g, b = map(int, input().split())
g_total += g
if b > g_total:
print("impossible")
exit()
print("possible")

5
jointjogjam.py Normal file
View File

@@ -0,0 +1,5 @@
ksx, ksy, osx, osy, kex, key, oex, oey = map(int, input().split())
d1 = ((ksx - osx) ** 2 + (ksy - osy) ** 2) ** (0.5)
d2 = ((kex - oex) ** 2 + (key - oey) ** 2) ** (0.5)
print(max((d1, d2)))

11
loorolls.py Normal file
View File

@@ -0,0 +1,11 @@
L, N = map(int, input().split())
rollen = 0
prev_taken = 0
while True:
rollen += 1
restant = L % (N - prev_taken)
if restant == 0:
print(rollen)
exit()
prev_taken += restant

21
luhnchecksum.py Normal file
View File

@@ -0,0 +1,21 @@
def luhn_checksum(card_number):
def digits_of(n):
return [int(d) for d in str(n)]
digits = digits_of(card_number)
odd_digits = digits[-1::-2]
even_digits = digits[-2::-2]
checksum = 0
checksum += sum(odd_digits)
for d in even_digits:
checksum += sum(digits_of(d * 2))
return checksum % 10
def is_luhn_valid(card_number):
return luhn_checksum(card_number) == 0
n = int(input())
for _ in range(n):
print("PASS" if is_luhn_valid(input()) else "FAIL")

17
schoolspirit.py Normal file
View File

@@ -0,0 +1,17 @@
n = int(input())
scores = [int(input()) for _ in range(n)]
def calculate_score(scores: list) -> float:
return (1 / 5) * sum([score * ((4 / 5) ** i) for i, score in enumerate(scores)])
print(calculate_score(scores))
new_scores = []
for score in scores:
cpy_scores = scores.copy()
cpy_scores.remove(score)
new_scores.append(calculate_score(cpy_scores))
print(sum(new_scores) / len(new_scores))

6
tripletexting.py Normal file
View File

@@ -0,0 +1,6 @@
s = input()
wordlen = len(s) // 3
s1 = s[:wordlen]
s2 = s[wordlen : wordlen * 2]
s3 = s[wordlen * 2 :]
print(s1 if s1 == s2 or s1 == s3 else s2)