Compare commits
No commits in common. "ffcc1e14c056288dd1e661e3a6c4e33956e45abb" and "b2cc1e814c3dea3b2582c2b85726db387acfca3d" have entirely different histories.
ffcc1e14c0
...
b2cc1e814c
@ -236,7 +236,7 @@ class Coordinate(tuple):
|
|||||||
diff = target - self
|
diff = target - self
|
||||||
|
|
||||||
if self[2] is None:
|
if self[2] is None:
|
||||||
steps = gcd(diff[0], diff[1])
|
steps = gcd(diff[0], diff[0])
|
||||||
step_x = diff[0] // steps
|
step_x = diff[0] // steps
|
||||||
step_y = diff[1] // steps
|
step_y = diff[1] // steps
|
||||||
return [
|
return [
|
||||||
|
|||||||
@ -229,20 +229,6 @@ class Grid:
|
|||||||
else:
|
else:
|
||||||
return self.__grid.keys()
|
return self.__grid.keys()
|
||||||
|
|
||||||
def getRegion(self, start: Coordinate, includeDiagonal: bool = False) -> Iterable[Coordinate]:
|
|
||||||
start_value = self.get(start)
|
|
||||||
queue = deque()
|
|
||||||
queue.append(start)
|
|
||||||
visited = set()
|
|
||||||
while queue:
|
|
||||||
next_coord = queue.popleft()
|
|
||||||
if next_coord in visited or not self.isWithinBoundaries(next_coord) or self.get(next_coord) != start_value:
|
|
||||||
continue
|
|
||||||
visited.add(next_coord)
|
|
||||||
yield next_coord
|
|
||||||
for n in self.getNeighboursOf(next_coord, includeDefault=True, includeDiagonal=includeDiagonal):
|
|
||||||
queue.append(n)
|
|
||||||
|
|
||||||
def getActiveRegion(
|
def getActiveRegion(
|
||||||
self,
|
self,
|
||||||
start: Coordinate,
|
start: Coordinate,
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import os.path
|
|||||||
import sys
|
import sys
|
||||||
from fishhook import hook
|
from fishhook import hook
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Any, Iterator
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class Cache(dict):
|
class Cache(dict):
|
||||||
@ -166,18 +166,6 @@ def cache(func):
|
|||||||
return new_func
|
return new_func
|
||||||
|
|
||||||
|
|
||||||
def list_combinations_of_sum(total_sum: int, length: int = None, min_value: int = 0) -> Iterator[tuple[int]]:
|
|
||||||
if length is None:
|
|
||||||
length = total_sum
|
|
||||||
|
|
||||||
if length == 1:
|
|
||||||
yield (total_sum,)
|
|
||||||
else:
|
|
||||||
for value in range(min_value, total_sum + 1):
|
|
||||||
for permutation in list_combinations_of_sum(total_sum - value, length - 1, min_value):
|
|
||||||
yield (value,) + permutation
|
|
||||||
|
|
||||||
|
|
||||||
@hook(list)
|
@hook(list)
|
||||||
def intersection(self, *args) -> list:
|
def intersection(self, *args) -> list:
|
||||||
ret = set(self).intersection(*args)
|
ret = set(self).intersection(*args)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user