Skip to content

Commit 2006ade

Browse files
committed
remove competitive programming solutions; reformat
1 parent b1d3b2c commit 2006ade

File tree

127 files changed

+233
-4824
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+233
-4824
lines changed

algorithms/floyd_warshall.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
from data_structures.graph_no_vertice_object import Graph
33
from typing import List, Dict
44

5+
56
# Takes in graph and builds FW Multi-Dim matrix m, then passes m to floyd_warshall which takes in the matrix.
67
# Because in some cases, we won't actually need to build a graph before we're able to compute so this saves
78
# some compute.
89
def floyd_warshall_g(g: Graph) -> List:
9-
v = g.vertices() # Expects 1...n styled vertices.
10+
v = g.vertices() # Expects 1...n styled vertices.
1011
num_v = len(v)
1112
m = [[math.inf] * num_v for _ in range(num_v)]
1213

@@ -37,4 +38,4 @@ def floyd_warshall(m: List) -> List:
3738
continue
3839
m[i][j] = min(ii[j], ik + kj)
3940

40-
return m
41+
return m

codility/arrays/cyclic_rotation.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

codility/arrays/odd_occurrences_in_array.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

codility/counting_elements/perm_check.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

codility/iterators/binary_gap.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

codility/kmp.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

codility/number_theory/chocolates_by_numbers.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

codility/number_theory/common_prime_divisors.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

codility/time_complexity/file_missing_elem.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

codility/time_complexity/frog_jmp.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

codility/time_complexity/smallest_positive_integer.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

codility/time_complexity/tape_equilibrium.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

data_structures/graph.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2121

22+
2223
class Graph:
2324
"""Representation of a simple graph using an adjacency map."""
2425

2526
# ------------------------- nested Vertex class -------------------------
2627
class Vertex:
2728
"""Lightweight vertex structure for a graph."""
28-
__slots__ = '_element'
29+
30+
__slots__ = "_element"
2931

3032
def __init__(self, x):
3133
"""Do not call constructor directly. Use Graph's insert_vertex(x)."""
@@ -44,7 +46,8 @@ def __str__(self):
4446
# ------------------------- nested Edge class -------------------------
4547
class Edge:
4648
"""Lightweight edge structure for a graph."""
47-
__slots__ = '_origin', '_destination', '_element'
49+
50+
__slots__ = "_origin", "_destination", "_element"
4851

4952
def __init__(self, u, v, x):
5053
"""Do not call constructor directly. Use Graph's insert_edge(u,v,x)."""
@@ -59,9 +62,9 @@ def endpoints(self):
5962
def opposite(self, v):
6063
"""Return the vertex that is opposite v on this edge."""
6164
if not isinstance(v, Graph.Vertex):
62-
raise TypeError('v must be a Vertex')
65+
raise TypeError("v must be a Vertex")
6366
return self._destination if v == self._origin else self._origin
64-
raise ValueError('v not incident to edge')
67+
raise ValueError("v not incident to edge")
6568

6669
def element(self):
6770
"""Return element associated with this edge."""
@@ -71,7 +74,9 @@ def __hash__(self): # will allow edge to be a map/set key
7174
return hash((self._origin, self._destination))
7275

7376
def __str__(self):
74-
return '({0},{1},{2})'.format(self._origin, self._destination, self._element)
77+
return "({0},{1},{2})".format(
78+
self._origin, self._destination, self._element
79+
)
7580

7681
# ------------------------- Graph methods -------------------------
7782
def __init__(self, directed=False):
@@ -86,9 +91,9 @@ def __init__(self, directed=False):
8691
def _validate_vertex(self, v):
8792
"""Verify that v is a Vertex of this graph."""
8893
if not isinstance(v, self.Vertex):
89-
raise TypeError('Vertex expected')
94+
raise TypeError("Vertex expected")
9095
if v not in self._outgoing:
91-
raise ValueError('Vertex does not belong to this graph.')
96+
raise ValueError("Vertex does not belong to this graph.")
9297

9398
def is_directed(self):
9499
"""Return True if this is a directed graph; False if undirected.
@@ -158,7 +163,7 @@ def insert_edge(self, u, v, x=None):
158163
Raise a ValueError if u and v are already adjacent.
159164
"""
160165
if self.get_edge(u, v) is not None: # includes error checking
161-
raise ValueError('u and v are already adjacent')
166+
raise ValueError("u and v are already adjacent")
162167
e = self.Edge(u, v, x)
163168
self._outgoing[u][v] = e
164169
self._incoming[v][u] = e

data_structures/graph_min.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Graph:
22
class Vertex:
3-
__slots__ = '_element'
3+
__slots__ = "_element"
44

55
def __init__(self, x):
66
self._element = x
@@ -15,7 +15,7 @@ def __str__(self):
1515
return str(self._element)
1616

1717
class Edge:
18-
__slots__ = '_origin', '_destination', '_element'
18+
__slots__ = "_origin", "_destination", "_element"
1919

2020
def __init__(self, u, v, x):
2121
self._origin = u
@@ -27,7 +27,7 @@ def endpoints(self):
2727

2828
def opposite(self, v):
2929
if not isinstance(v, Graph.Vertex):
30-
raise TypeError('v must be a Vertex')
30+
raise TypeError("v must be a Vertex")
3131
return self._destination if v == self._origin else self._origin
3232

3333
def element(self):
@@ -37,17 +37,19 @@ def __hash__(self): # will allow edge to be a map/set key
3737
return hash((self._origin, self._destination))
3838

3939
def __str__(self):
40-
return '({0},{1},{2})'.format(self._origin, self._destination, self._element)
40+
return "({0},{1},{2})".format(
41+
self._origin, self._destination, self._element
42+
)
4143

4244
def __init__(self, directed=False):
4345
self._outgoing = {}
4446
self._incoming = {} if directed else self._outgoing
4547

4648
def _validate_vertex(self, v):
4749
if not isinstance(v, self.Vertex):
48-
raise TypeError('Vertex expected')
50+
raise TypeError("Vertex expected")
4951
if v not in self._outgoing:
50-
raise ValueError('Vertex does not belong to this graph.')
52+
raise ValueError("Vertex does not belong to this graph.")
5153

5254
def is_directed(self):
5355
return self._incoming is not self._outgoing # directed if maps are distinct
@@ -99,7 +101,7 @@ def insert_vertex_simple(self, v=None):
99101

100102
def insert_edge(self, u, v, x=None):
101103
if self.get_edge(u, v) is not None: # includes error checking
102-
raise ValueError('u and v are already adjacent')
104+
raise ValueError("u and v are already adjacent")
103105
e = self.Edge(u, v, x)
104106
self._outgoing[u][v] = e
105107
self._incoming[v][u] = e

0 commit comments

Comments
 (0)