mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 10:28:39 +00:00
Compare commits
4 Commits
629eb86ce0
...
f8fe72dc37
Author | SHA1 | Date | |
---|---|---|---|
|
f8fe72dc37 | ||
|
5cf34d901e | ||
|
90a8e6e0d2 | ||
|
0b0214c42f |
@ -236,8 +236,8 @@
|
|||||||
* [Double Ended Queue](data_structures/queue/double_ended_queue.py)
|
* [Double Ended Queue](data_structures/queue/double_ended_queue.py)
|
||||||
* [Linked Queue](data_structures/queue/linked_queue.py)
|
* [Linked Queue](data_structures/queue/linked_queue.py)
|
||||||
* [Priority Queue Using List](data_structures/queue/priority_queue_using_list.py)
|
* [Priority Queue Using List](data_structures/queue/priority_queue_using_list.py)
|
||||||
|
* [Queue By List](data_structures/queue/queue_by_list.py)
|
||||||
* [Queue By Two Stacks](data_structures/queue/queue_by_two_stacks.py)
|
* [Queue By Two Stacks](data_structures/queue/queue_by_two_stacks.py)
|
||||||
* [Queue On List](data_structures/queue/queue_on_list.py)
|
|
||||||
* [Queue On Pseudo Stack](data_structures/queue/queue_on_pseudo_stack.py)
|
* [Queue On Pseudo Stack](data_structures/queue/queue_on_pseudo_stack.py)
|
||||||
* Stacks
|
* Stacks
|
||||||
* [Balanced Parentheses](data_structures/stacks/balanced_parentheses.py)
|
* [Balanced Parentheses](data_structures/stacks/balanced_parentheses.py)
|
||||||
|
@ -10,7 +10,7 @@ Python:
|
|||||||
- 3.5
|
- 3.5
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
- $python3 game_o_life <canvas_size:int>
|
- $python3 game_of_life <canvas_size:int>
|
||||||
|
|
||||||
Game-Of-Life Rules:
|
Game-Of-Life Rules:
|
||||||
|
|
||||||
@ -52,7 +52,8 @@ def seed(canvas: list[list[bool]]) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def run(canvas: list[list[bool]]) -> list[list[bool]]:
|
def run(canvas: list[list[bool]]) -> list[list[bool]]:
|
||||||
"""This function runs the rules of game through all points, and changes their
|
"""
|
||||||
|
This function runs the rules of game through all points, and changes their
|
||||||
status accordingly.(in the same canvas)
|
status accordingly.(in the same canvas)
|
||||||
@Args:
|
@Args:
|
||||||
--
|
--
|
||||||
@ -60,7 +61,7 @@ def run(canvas: list[list[bool]]) -> list[list[bool]]:
|
|||||||
|
|
||||||
@returns:
|
@returns:
|
||||||
--
|
--
|
||||||
None
|
canvas of population after one step
|
||||||
"""
|
"""
|
||||||
current_canvas = np.array(canvas)
|
current_canvas = np.array(canvas)
|
||||||
next_gen_canvas = np.array(create_canvas(current_canvas.shape[0]))
|
next_gen_canvas = np.array(create_canvas(current_canvas.shape[0]))
|
||||||
@ -70,10 +71,7 @@ def run(canvas: list[list[bool]]) -> list[list[bool]]:
|
|||||||
pt, current_canvas[r - 1 : r + 2, c - 1 : c + 2]
|
pt, current_canvas[r - 1 : r + 2, c - 1 : c + 2]
|
||||||
)
|
)
|
||||||
|
|
||||||
current_canvas = next_gen_canvas
|
return next_gen_canvas.tolist()
|
||||||
del next_gen_canvas # cleaning memory as we move on.
|
|
||||||
return_canvas: list[list[bool]] = current_canvas.tolist()
|
|
||||||
return return_canvas
|
|
||||||
|
|
||||||
|
|
||||||
def __judge_point(pt: bool, neighbours: list[list[bool]]) -> bool:
|
def __judge_point(pt: bool, neighbours: list[list[bool]]) -> bool:
|
||||||
|
@ -7,6 +7,7 @@ class SegmentTree:
|
|||||||
self.st = [0] * (
|
self.st = [0] * (
|
||||||
4 * self.N
|
4 * self.N
|
||||||
) # approximate the overall size of segment tree with array N
|
) # approximate the overall size of segment tree with array N
|
||||||
|
if self.N:
|
||||||
self.build(1, 0, self.N - 1)
|
self.build(1, 0, self.N - 1)
|
||||||
|
|
||||||
def left(self, idx):
|
def left(self, idx):
|
||||||
|
@ -20,7 +20,7 @@ def check_circuit_or_path(graph, max_node):
|
|||||||
odd_degree_nodes = 0
|
odd_degree_nodes = 0
|
||||||
odd_node = -1
|
odd_node = -1
|
||||||
for i in range(max_node):
|
for i in range(max_node):
|
||||||
if i not in graph.keys():
|
if i not in graph:
|
||||||
continue
|
continue
|
||||||
if len(graph[i]) % 2 == 1:
|
if len(graph[i]) % 2 == 1:
|
||||||
odd_degree_nodes += 1
|
odd_degree_nodes += 1
|
||||||
|
@ -60,7 +60,7 @@ def newtons_second_law_of_motion(mass: float, acceleration: float) -> float:
|
|||||||
>>> newtons_second_law_of_motion(2.0, 1)
|
>>> newtons_second_law_of_motion(2.0, 1)
|
||||||
2.0
|
2.0
|
||||||
"""
|
"""
|
||||||
force = float()
|
force = 0.0
|
||||||
try:
|
try:
|
||||||
force = mass * acceleration
|
force = mass * acceleration
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
def bubble_sort(collection):
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
def bubble_sort(collection: list[Any]) -> list[Any]:
|
||||||
"""Pure implementation of bubble sort algorithm in Python
|
"""Pure implementation of bubble sort algorithm in Python
|
||||||
|
|
||||||
:param collection: some mutable ordered collection with heterogeneous
|
:param collection: some mutable ordered collection with heterogeneous
|
||||||
@ -28,9 +31,9 @@ def bubble_sort(collection):
|
|||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
length = len(collection)
|
length = len(collection)
|
||||||
for i in range(length - 1):
|
for i in reversed(range(length)):
|
||||||
swapped = False
|
swapped = False
|
||||||
for j in range(length - 1 - i):
|
for j in range(i):
|
||||||
if collection[j] > collection[j + 1]:
|
if collection[j] > collection[j + 1]:
|
||||||
swapped = True
|
swapped = True
|
||||||
collection[j], collection[j + 1] = collection[j + 1], collection[j]
|
collection[j], collection[j + 1] = collection[j + 1], collection[j]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user