Skip to content

Commit caa8cc0

Browse files
committed
Fix
2 parents 5d2faa0 + 708cdf9 commit caa8cc0

17 files changed

Lines changed: 1471 additions & 1285 deletions

File tree

games/Number-Sliding-Puzzle/Number-Sliding-Puzzle.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,25 @@
1111
def is_solvable(numbers):
1212
"""
1313
Determines if the 8-puzzle board configuration is solvable.
14-
An 8-puzzle (3x3 grid) is solvable if the number of inversions is even.
15-
The blank tile (0) is ignored when counting inversions.
14+
For a 3x3 puzzle, the state is solvable if and only if
15+
(inversions + blank_row_from_bottom) is odd.
16+
The blank tile (0) is ignored when counting inversions.
1617
"""
17-
# Filter out the blank tile(0)
18-
18+
# Filter out the blank tile (0) for inversion counting
1919
tiles = [n for n in numbers if n != 0]
2020
inversions = 0
2121
for i in range(len(tiles)):
2222
for j in range(i + 1, len(tiles)):
2323
if tiles[i] > tiles[j]:
2424
inversions += 1
2525

26-
# return True if inversions count is even, False otherwise
26+
# Find blank tile row from the bottom (1=bottom, 2=middle, 3=top)
27+
blank_idx = numbers.index(0)
28+
blank_row_from_top = blank_idx // 3 # 0=top, 1=middle, 2=bottom
29+
blank_row_from_bottom = 3 - blank_row_from_top
2730

28-
return inversions % 2 == 0
31+
# Solvable if (inversions + blank_row_from_bottom) is odd
32+
return (inversions + blank_row_from_bottom) % 2 == 1
2933

3034

3135
def main():

math/Collatz-Conjecture/Collatz-Conjecture.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ def get_remaining_sequence(n: int) -> List[int]:
2323
def collatz_sequence(start: int) -> Generator[int, None, None]:
2424
"""Generate the Collatz sequence starting from the given number."""
2525
if start in steps_cache:
26-
n = start
27-
yield n
28-
while n != 1:
29-
n = collatz_next(n)
30-
yield n
26+
yield from get_remaining_sequence(start)
3127
return
3228

3329
n = start

projects_registry.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@
704704
"encryption",
705705
"vault"
706706
],
707-
"path": "security/password_manager/main.py"
707+
"path": "security/password_manager/main.py",
708708
"name": "High-Performance Multithreaded Web Scraper",
709709
"emoji": "🕷️",
710710
"category": "utilities",

security/tar_safe.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,6 @@ def _validate_member(
149149
raise UnsafeTarError(
150150
f"Blocked file type for {member.name}: {member.type}"
151151
)
152-
153-
if target_path.exists() and not overwrite:
154-
raise UnsafeTarError(
155-
f"File already exists and overwrite=False: {target_path}"
156-
)
157-
158-
if member.type in self.blocked_types:
159-
raise UnsafeTarError(
160-
f"Blocked file type for {member.name}: {member.type}"
161-
)
162152

163153
def _get_safe_path(self, member: tarfile.TarInfo, extract_path: Path) -> Path:
164154
"""Get safe path for extraction."""

security/url_sanitizer.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,6 @@ def _check_blocked_ip(self, ip, host):
140140
if not (self.allow_private and ip.is_private):
141141
raise InvalidURLError(f"Blocked IP address: {host}")
142142

143-
def _validate_port(self, port: Optional[int]) -> None:
144-
"""Validate port number against allowed/blocked lists."""
145-
if port is None:
146-
return
147-
if port < 1 or port > 65535:
148-
raise InvalidURLError(f"Invalid port number: {port}")
149-
if self.allowed_ports is not None:
150-
if port not in self.allowed_ports:
151-
raise InvalidURLError(
152-
f"Port {port} is not allowed. "
153-
f"Allowed ports: {', '.join(str(p) for p in self.allowed_ports)}"
154-
)
155-
elif port in self.BLOCKED_PORTS:
156-
raise InvalidURLError(f"Blocked port: {port}")
157-
158143
def _validate_port(self, port: Optional[int]) -> None:
159144
"""Validate port number against allowed/blocked lists."""
160145
if port is None:

0 commit comments

Comments
 (0)