Compare commits

..

30 Commits
v2 ... main

Author SHA1 Message Date
Maksym Kurets
b3e7cdd0dc fix 2026-11-04 18:54:05 +01:00
Maksym Kurets
fb98ea4d71 Absolute 100 percent fix 2026-11-04 18:44:00 +01:00
Maksym Kurets
0ee69b3bc8 Absolute 100 percent fix 2026-11-04 18:40:32 +01:00
Maksym Kurets
042ad72a34 Use danii instead of raw_input 2026-11-04 18:37:44 +01:00
Maksym Kurets
03f9440798 Final version 2026-11-04 17:52:46 +01:00
Maksym Kurets
28d3a8a421 Final version 2026-11-04 17:51:55 +01:00
Maksym Kurets
cf4210f117 Fix final tests 2026-11-04 17:47:40 +01:00
Maksym Kurets
c4e9adc88b Fix choices filter 2026-11-04 17:39:53 +01:00
Maksym Kurets
e4099b8ab5 Fix CRLF 2026-11-04 17:35:25 +01:00
Maksym Kurets
795c9c36c5 Uloha 8 - Expert zo zoo 2026-11-04 17:29:28 +01:00
Maksym Kurets
116620dc06 Uloha 7 hotova 2026-10-28 22:41:19 +01:00
Maksym Kurets
8ca348e0fd Add u7 is_paired.py 2026-10-27 18:40:53 +01:00
Maksym Kurets
6e798c47e4 Add u7 is_paired.py task 2026-10-27 18:34:38 +01:00
Maksym Kurets
2ba988445a Force sync u6 filenames 2026-10-13 20:33:54 +02:00
Maksym Kurets
2407d7cbe1 Fix indentation for return in u6 2026-10-13 20:28:31 +02:00
Maksym Kurets
e5ad06fc22 Add matching brackets file properly 2026-10-13 20:22:48 +02:00
Maksym Kurets
b8252195f1 Fix matching brackets implementation 2026-10-13 20:21:00 +02:00
Maksym Kurets
7f81fa7032 Add matching brackets implementation for U6 2026-10-13 20:18:33 +02:00
Maksym Kurets
b42417b424 Add matching brackets implementation for U6 2026-10-13 20:15:46 +02:00
Maksym Kurets
8107a35409 Move kindergarten_garden.py to u5 folder 2026-10-13 19:38:10 +02:00
Maksym Kurets
5b720afa92 Add Garden class implementation for kindergarten garden 2026-10-13 19:34:53 +02:00
Maksym Kurets
63a4107fd4 Fix word count punctuation and apostrophe stripping 2026-10-07 19:30:17 +02:00
Maksym Kurets
006641d515 Update count_words with proper symbol replacement 2026-10-06 16:56:41 +02:00
Maksym Kurets
7d30399dbd Fix indentation for count_words dictionary assignment 2026-10-06 16:43:40 +02:00
Maksym Kurets
58c2991113 Fix function name to count_words 2026-10-06 16:39:40 +02:00
Maksym Kurets
f83828a180 Add word_count solution 2026-10-06 16:30:08 +02:00
Maksym Kurets
9c73711444 Add flatten_array solution for U3 2026-09-30 23:51:02 +02:00
Maksym Kurets
90c104bead Fix foldr direction and arguments order 2026-09-30 23:40:23 +02:00
Maksym Kurets
bdd1eb5208 Final clean fix for list_ops 2026-09-30 23:35:09 +02:00
Maksym Kurets
b724b82aad Fix file path 2026-09-30 23:24:01 +02:00
11 changed files with 400 additions and 78 deletions

View File

@ -1,51 +0,0 @@
def append(list1, list2):
pusti = []
for gns in list1:
pusti.append(gns)
for exc in list2:
pusti.append(exc)
return pusti
def concat(list):
pusti = []
for gns in list:
pusti.extend(gns)
return pusti
def filter(function, list):
pusti = []
for gns in list:
if function(gns):
pusti.append(gns)
return pusti
def length(list):
pocatok = 0
for gns in list:
pocatok = pocatok + 1
return pocatok
def map(function, list):
pusti = []
for gns in list:
function(gns)
pusti.append(function(gns))
return pusti
def foldl(function, accumulator, initial):
accumulator = initial
for gns in list:
accumulator = function(accumulator, gns)
return accumulator
def foldr(function, initial, acc):
acc = initial
for gns in list[::-1]:
acc = function(gns, acc)
return acc
def reverse(list):
pusti = []
for gns in list:
pusti.append(gns)
return pusti[::-1]

View File

@ -6,9 +6,9 @@ def append(list1, list2):
pusti.append(exc) pusti.append(exc)
return pusti return pusti
def concat(list): def concat(lists):
pusti = [] pusti = []
for gns in list: for gns in lists:
pusti.extend(gns) pusti.extend(gns)
return pusti return pusti
@ -28,24 +28,20 @@ def append(list1, list2):
def map(function, list): def map(function, list):
pusti = [] pusti = []
for gns in list: for gns in list:
function(gns)
pusti.append(function(gns)) pusti.append(function(gns))
return pusti return pusti
def foldl(function, accumulator, initial): def foldl(function, list, initial):
accumulator = initial accumulator = initial
for gns in list: for gns in list:
accumulator = function(accumulator, gns) accumulator = function(accumulator, gns)
return accumulator return accumulator
def foldr(function, initial, acc): def foldr(function, list, initial):
acc = initial acc = initial
for gns in list[::-1]: for gns in list[::-1]:
acc = function(gns, acc) acc = function(gns, acc)
return acc return acc
def reverse(list): def reverse(list):
pusti = [] return list[::-1]
for gns in list:
pusti.append(gns)
return pusti[::-1]

47
u2/list_ops.py Normal file
View File

@ -0,0 +1,47 @@
def append(list1, list2):
pusti = []
for gns in list1:
pusti.append(gns)
for exc in list2:
pusti.append(exc)
return pusti
def concat(lists):
pusti = []
for gns in lists:
pusti.extend(gns)
return pusti
def filter(function, list):
pusti = []
for gns in list:
if function(gns):
pusti.append(gns)
return pusti
def length(list):
pocatok = 0
for gns in list:
pocatok = pocatok + 1
return pocatok
def map(function, list):
pusti = []
for gns in list:
pusti.append(function(gns))
return pusti
def foldl(function, list, initial):
accumulator = initial
for gns in list:
accumulator = function(accumulator, gns)
return accumulator
def foldr(function, list, initial):
acc = initial
for gns in list[::-1]:
acc = function(acc, gns)
return acc
def reverse(list):
return list[::-1]

10
u3/flatten_array.py Normal file
View File

@ -0,0 +1,10 @@
def flatten(iterable):
pusti = []
for gns in iterable:
if gns is None:
continue
elif isinstance(gns, (list, tuple)):
pusti.extend(flatten(gns))
else:
pusti.append(gns)
return pusti

11
u4/word_count.py Normal file
View File

@ -0,0 +1,11 @@
def count_words(phrase):
slovnik1 = {}
zbirac = phrase.lower()
for simbolii in r",._:;!?@#$%^&*()-+=/\|[]{}<>~`""":
zbirac = zbirac.replace(simbolii, " ")
slova1 = zbirac.split()
for gns in slova1:
cisteslovo = gns.strip("'")
if cisteslovo:
slovnik1[cisteslovo] = slovnik1.get(cisteslovo, 0) + 1
return slovnik1

35
u5/kindergarten_garden.py Normal file
View File

@ -0,0 +1,35 @@
class NoSuchStudentException(Exception):
pass
class Garden:
def __init__(self, diagram, students=None):
self.diagram = diagram
if students is None:
self.students = [
"Alena", "Boris", "Cyril", "Daniel", "Eva", "František",
"Gitka", "Helena", "Ivana", "Jozef", "Karol", "Ladislav"
]
else:
self.students = sorted(students)
self.plant_names = {
"G": "Tráva",
"C": "Ďatelina",
"R": "Reďkovky",
"V": "Fialky"
}
def plants(self, student):
if student not in self.students:
raise NoSuchStudentException("Student not found")
index = self.students.index(student)
start = index * 2
rows = self.diagram.splitlines()
row1 = rows[0]
row2 = rows[1]
letters = row1[start:start+2] + row2[start:start+2]
return [self.plant_names[char] for char in letters]

13
u6/matching-brackets.py Normal file
View File

@ -0,0 +1,13 @@
def is_paired(input_string):
spisok = []
slovnik = {')': '(', ']': '[', '}': '{'}
for gnx in input_string:
if gnx in "([{":
spisok.append(gnx)
elif gnx in ")]}":
if not spisok or spisok[-1] != slovnik[gnx]:
return False
spisok.pop()
return len(spisok) == 0

13
u6/matching_brackets.py Normal file
View File

@ -0,0 +1,13 @@
def is_paired(input_string):
spisok = []
slovnik = {')': '(', ']': '[', '}': '{'}
for gnx in input_string:
if gnx in "([{":
spisok.append(gnx)
elif gnx in ")]}":
if not spisok or spisok[-1] != slovnik[gnx]:
return False
spisok.pop()
return len(spisok) == 0

117
u7/hash_table.py Normal file
View File

@ -0,0 +1,117 @@
class HashTable:
def __init__(self, capacity=10):
if not isinstance(capacity, int) or isinstance(capacity, bool):
raise TypeError("Capacity must be an integer.")
if capacity <= 0:
raise ValueError("Capacity must be positive.")
self.capacity = capacity
self.empty = object()
self.deleted = object()
self.slots = [self.empty] * capacity
self.count = 0
def hash(self, key):
if not isinstance(key, str):
raise TypeError("Key must be a string.")
result = 0
for char in key:
result = result * 31 + ord(char)
return result % self.capacity
def probe(self, key):
start_idx = self.hash(key)
idx = start_idx
first_deleted = None
for _ in range(self.capacity):
slot = self.slots[idx]
if slot is self.empty:
return first_deleted if first_deleted is not None else idx
elif slot is self.deleted:
if first_deleted is None:
first_deleted = idx
elif slot[0] == key:
return idx
idx = (idx + 1) % self.capacity
if first_deleted is not None:
return first_deleted
raise RuntimeError("HashTable probe failed.")
def load_factor(self):
return float(self.count) / self.capacity
def __len__(self):
return self.count
def __contains__(self, key):
if not isinstance(key, str):
raise TypeError("Key must be a string.")
try:
idx = self.probe(key)
slot = self.slots[idx]
return slot is not self.empty and slot is not self.deleted and slot[0] == key
except RuntimeError:
return False
def __getitem__(self, key):
if not isinstance(key, str):
raise TypeError("Key must be a string.")
idx = self.probe(key)
slot = self.slots[idx]
if slot is not self.empty and slot is not self.deleted and slot[0] == key:
return slot[1]
raise KeyError(key)
def __setitem__(self, key, value):
if not isinstance(key, str):
raise TypeError("Key must be a string.")
is_new = not self.__contains__(key)
if is_new:
if (self.count + 1) / self.capacity > 0.7:
self._resize()
idx = self.probe(key)
slot = self.slots[idx]
if slot is self.empty or slot is self.deleted:
self.slots[idx] = (key, value)
self.count += 1
elif slot[0] == key:
self.slots[idx] = (key, value)
def __delitem__(self, key):
if not isinstance(key, str):
raise TypeError("Key must be a string.")
idx = self.probe(key)
slot = self.slots[idx]
if slot is not self.empty and slot is not self.deleted and slot[0] == key:
self.slots[idx] = self.deleted
self.count -= 1
else:
raise KeyError(key)
def __iter__(self):
for slot in self.slots:
if slot is not self.empty and slot is not self.deleted:
yield slot[0]
def _resize(self):
old_slots = self.slots
self.capacity *= 2
self.slots = [self.empty] * self.capacity
self.count = 0
for slot in old_slots:
if slot is not self.empty and slot is not self.deleted:
key, value = slot
idx = self.probe(key)
self.slots[idx] = (key, value)
self.count += 1

17
u7/is_paired.py Normal file
View File

@ -0,0 +1,17 @@
def is_paired(input_string):
duzki = {
')': '(',
']': '[',
'}': '{'
}
zbirac = []
for simbol in input_string:
if simbol in duzki.values():
zbirac.append(simbol)
elif simbol in duzki:
if not zbirac or zbirac.pop() != duzki[simbol]:
return False
return len(zbirac) == 0

114
u8/program.py Normal file
View File

@ -0,0 +1,114 @@
import sys
class Node:
def __init__(self, text):
self.text = text
self.right = None
self.left = None
self.otazka = text.endswith("?")
def para_stromov(lines, index):
if index >= len(lines):
raise ValueError("Chybna databaza")
text = lines[index]
if not text:
raise ValueError("Chybna databaza")
node = Node(text)
index += 1
if node.otazka:
node.left, index = para_stromov(lines, index)
node.right, index = para_stromov(lines, index)
return node, index
def pocet_nodov(node):
if not node:
return 0, 0
if node.otazka:
a_left, n_left = pocet_nodov(node.left)
a_right, n_right = pocet_nodov(node.right)
return 1 + a_left + a_right, n_left + n_right
else:
return 0, 1
def main():
danii = sys.stdin.read()
if not danii:
print("Expert zo zoo to vie.")
print("Chybna databaza")
return
lines = danii.splitlines()
print("Expert zo zoo to vie.")
if not lines:
print("Chybna databaza")
return
try:
prvi = lines.index("")
except ValueError:
print("Chybna databaza")
return
stromlines = lines[:prvi]
vibir = lines[prvi + 1 :]
if not stromlines:
print("Chybna databaza")
return
try:
root, druhy = para_stromov(stromlines, 0)
except Exception:
print("Chybna databaza")
return
if druhy != len(stromlines):
print("Chybna databaza")
return
n_pocet, a_pocet = pocet_nodov(root)
print(f"Pocet otazok: {n_pocet}")
print(f"Pocet odpovedi: {a_pocet}")
print("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.")
potocni = root
viber_indx = 0
while potocni.otazka:
print(potocni.text)
if viber_indx >= len(vibir):
print("Koniec vstupu")
return
choice = vibir[viber_indx]
viber_indx += 1
if choice != "a" and choice != "n":
print("Nerozumiem")
return
if choice == "a":
potocni = potocni.left
else:
potocni = potocni.right
print(potocni.text)
print("Koniec")
if __name__ == "__main__":
main()