Skip to content

Commit

Permalink
hell of an update
Browse files Browse the repository at this point in the history
  • Loading branch information
TheColorman committed Feb 13, 2025
1 parent bb27b67 commit 67ef43e
Show file tree
Hide file tree
Showing 168 changed files with 1,702,168 additions and 1,700,161 deletions.
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# large files
INDBS/7
*.bin
langid-data/
# large files
INDBS/7
*.bin
langid-data/

**/.direnv
826 changes: 413 additions & 413 deletions ALDAS/1/exercises.ipynb

Large diffs are not rendered by default.

690 changes: 345 additions & 345 deletions ALDAS/10/exercises.ipynb

Large diffs are not rendered by default.

224 changes: 112 additions & 112 deletions ALDAS/11/Flights.py
Original file line number Diff line number Diff line change
@@ -1,112 +1,112 @@
from itu.algs4.searching.red_black_bst import RedBlackBST


class Timestamp:
seconds = 0
timestamp = ""

def __init__(self, i) -> None:
if type(i) == int:
self.fromsec(i)
elif type(i) == str:
self.fromtimestamp(i)
else:
raise ValueError("Only supports int or str type, got ", type(i))

def tosec(self) -> int:
HH, MM, SS = [int(i) for i in self.timestamp.split(":")]
seconds = SS + MM*60 + HH*60*60
return seconds

def totimestamp(self) -> str:
HH = self.seconds // (60*60)
MM = (self.seconds - HH*60*60) // 60
SS = self.seconds - HH*60*60 - MM*60
HH, MM, SS = str(HH), str(MM), str(SS)
return HH.zfill(2) + ":" + MM.zfill(2) + ":" + SS.zfill(2)

def fromsec(self, s: int) -> object:
self.seconds = s
self.timestamp = self.totimestamp()

def fromtimestamp(self, t: str) -> object:
self.timestamp = t
self.seconds = self.tosec()

def __eq__(self, __value: object) -> bool:
return self.tosec() == __value.tosec()

def __ne__(self, __value: object) -> bool:
return self.tosec() != __value.tosec()

def __lt__(self, __value: object) -> bool:
return self.tosec() < __value.tosec()

def __gt__(self, __value: object) -> bool:
return self.tosec() > __value.tosec()

def __repr__(self) -> str:
return self.totimestamp() + f" ({self.tosec()})"


n, m = [int(i) for i in input().split(" ")]
_flights = [(Timestamp(dep_time), dest) for i in range(n)
for dep_time, dest in [input().split(" ")]]
operations = [(operation, parameters.split(" ")) for i in range(m)
for operation, parameters in [input().split(" ", 1)]]

flights = RedBlackBST()
[flights.put(dep_time, dest) for dep_time, dest in _flights]

def cancel(p):
s = p[0]

ts = Timestamp(s)
flights.delete(ts)
def delay(p):
s, d = p

ts = Timestamp(s)
dest = flights.get(ts)
flights.delete(ts)
newtime = ts.tosec() + int(d)
flights.put(Timestamp(newtime), dest)
def reroute(p):
s, c = p

ts = Timestamp(s)
flights.delete(ts)
flights.put(ts, c)
def destination(p):
t = p[0]

ts = Timestamp(t)
dest = flights.get(ts)
return dest if dest is not None else "-"
def next(p):
t = p[0]

ts = Timestamp(t)
next_ts = flights.ceiling(ts)
next_dest = flights.get(next_ts)
return f"{next_ts.totimestamp()} {next_dest}"
def count(p):
t1, t2 = p

ts1, ts2 = Timestamp(t1), Timestamp(t2)
return flights.size_range(ts1, ts2)

ops = {
"cancel": cancel,
"delay": delay,
"reroute": reroute,
"destination": destination,
"next": next,
"count": count
}

for operation, parameters in operations:
result = ops[operation](parameters)
if result is not None:
print(result)

from itu.algs4.searching.red_black_bst import RedBlackBST


class Timestamp:
seconds = 0
timestamp = ""

def __init__(self, i) -> None:
if type(i) == int:
self.fromsec(i)
elif type(i) == str:
self.fromtimestamp(i)
else:
raise ValueError("Only supports int or str type, got ", type(i))

def tosec(self) -> int:
HH, MM, SS = [int(i) for i in self.timestamp.split(":")]
seconds = SS + MM*60 + HH*60*60
return seconds

def totimestamp(self) -> str:
HH = self.seconds // (60*60)
MM = (self.seconds - HH*60*60) // 60
SS = self.seconds - HH*60*60 - MM*60
HH, MM, SS = str(HH), str(MM), str(SS)
return HH.zfill(2) + ":" + MM.zfill(2) + ":" + SS.zfill(2)

def fromsec(self, s: int) -> object:
self.seconds = s
self.timestamp = self.totimestamp()

def fromtimestamp(self, t: str) -> object:
self.timestamp = t
self.seconds = self.tosec()

def __eq__(self, __value: object) -> bool:
return self.tosec() == __value.tosec()

def __ne__(self, __value: object) -> bool:
return self.tosec() != __value.tosec()

def __lt__(self, __value: object) -> bool:
return self.tosec() < __value.tosec()

def __gt__(self, __value: object) -> bool:
return self.tosec() > __value.tosec()

def __repr__(self) -> str:
return self.totimestamp() + f" ({self.tosec()})"


n, m = [int(i) for i in input().split(" ")]
_flights = [(Timestamp(dep_time), dest) for i in range(n)
for dep_time, dest in [input().split(" ")]]
operations = [(operation, parameters.split(" ")) for i in range(m)
for operation, parameters in [input().split(" ", 1)]]

flights = RedBlackBST()
[flights.put(dep_time, dest) for dep_time, dest in _flights]

def cancel(p):
s = p[0]

ts = Timestamp(s)
flights.delete(ts)
def delay(p):
s, d = p

ts = Timestamp(s)
dest = flights.get(ts)
flights.delete(ts)
newtime = ts.tosec() + int(d)
flights.put(Timestamp(newtime), dest)
def reroute(p):
s, c = p

ts = Timestamp(s)
flights.delete(ts)
flights.put(ts, c)
def destination(p):
t = p[0]

ts = Timestamp(t)
dest = flights.get(ts)
return dest if dest is not None else "-"
def next(p):
t = p[0]

ts = Timestamp(t)
next_ts = flights.ceiling(ts)
next_dest = flights.get(next_ts)
return f"{next_ts.totimestamp()} {next_dest}"
def count(p):
t1, t2 = p

ts1, ts2 = Timestamp(t1), Timestamp(t2)
return flights.size_range(ts1, ts2)

ops = {
"cancel": cancel,
"delay": delay,
"reroute": reroute,
"destination": destination,
"next": next,
"count": count
}

for operation, parameters in operations:
result = ops[operation](parameters)
if result is not None:
print(result)
580 changes: 290 additions & 290 deletions ALDAS/11/exercises.ipynb

Large diffs are not rendered by default.

640 changes: 320 additions & 320 deletions ALDAS/12/exercises.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 67ef43e

Please sign in to comment.