Skip to content

Commit 2f853d1

Browse files
authored
Merge branch 'master' into master
2 parents e062a5f + 1672dea commit 2f853d1

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

‎graphs/dijkstra_2.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ def print_dist(dist, v) -> None:
99

1010

1111
def min_dist(mdist, vset, v):
12+
"""
13+
Returns the vertex with the minimum distance from the source vertex\
14+
that has not been visited.
15+
16+
>>> min_dist([0, 1, 6], [True, False, False], 3)
17+
1
18+
"""
1219
min_val = float("inf")
1320
min_ind = -1
1421
for i in range(v):
@@ -19,6 +26,20 @@ def min_dist(mdist, vset, v):
1926

2027

2128
def dijkstra(graph, v, src) -> None:
29+
"""
30+
Calculate the shortest path from source to all other vertices\
31+
using Dijkstra's algorithm.
32+
33+
>>> graph = [[0.0, 1.0, 6.0],\
34+
[float("inf"), 0.0, 3.0],\
35+
[float("inf"), float("inf"), 0.0]]
36+
>>> dijkstra(graph, 3, 0) # doctest: +NORMALIZE_WHITESPACE
37+
<BLANKLINE>
38+
Vertex Distance
39+
0 0
40+
1 1
41+
2 4
42+
"""
2243
mdist = [float("inf") for _ in range(v)]
2344
vset = [False for _ in range(v)]
2445
mdist[src] = 0.0
@@ -35,7 +56,7 @@ def dijkstra(graph, v, src) -> None:
3556
):
3657
mdist[i] = mdist[u] + graph[u][i]
3758

38-
print_dist(mdist, i)
59+
print_dist(mdist, v)
3960

4061

4162
if __name__ == "__main__":

‎hashes/chaos_machine.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def push(seed: float) -> None:
3131
Args:
3232
seed: A numeric seed to push into the machine.
3333
"""
34-
global buffer_space, params_space, machine_time, K, m, t
34+
global buffer_space, params_space, machine_time
3535

3636
# Choosing Dynamical Systems (All)
3737
for key, value in enumerate(buffer_space):
@@ -70,7 +70,7 @@ def pull() -> int:
7070
>>> 0 <= pull() <= 0xFFFFFFFF
7171
True
7272
"""
73-
global buffer_space, params_space, machine_time, K, m, t
73+
global buffer_space, params_space, machine_time
7474

7575
# PRNG (Xorshift by George Marsaglia)
7676
def xorshift(x: int, y: int) -> int:
@@ -99,12 +99,16 @@ def xorshift(x: int, y: int) -> int:
9999
# Machine Time
100100
machine_time += 1
101101

102-
return xorshift(x, y) % 0xFFFFFFFF
102+
# PRNG (Xorshift by George Marsaglia)
103+
x ^= y >> 13
104+
y ^= x << 17
105+
x ^= y >> 5
106+
return x & 0xFFFFFFFF
103107

104108

105109
def reset() -> None:
106110
"""Reset the chaos machine to its initial state."""
107-
global buffer_space, params_space, machine_time, K, m, t
111+
global buffer_space, params_space, machine_time
108112

109113
buffer_space = K.copy()
110114
params_space = [0] * m

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies = [
2222
"numpy>=2.1.3",
2323
"pandas>=2.3.3",
2424
"pillow>=11.3",
25+
"polars>=1.44.2",
2526
"rich>=13.9.4",
2627
"scikit-learn>=1.9.1",
2728
"scipy>=1.18.1",

0 commit comments

Comments
 (0)