Solved data added
This commit is contained in:
parent
b3023beacd
commit
3a41bff462
Binary file not shown.
Binary file not shown.
3149
iq_mini_4489/src/data.json
Normal file
3149
iq_mini_4489/src/data.json
Normal file
File diff suppressed because it is too large
Load Diff
3149
iq_mini_4489/src/raw.json
Normal file
3149
iq_mini_4489/src/raw.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,8 +3,10 @@
|
||||
from board import Board, generate_orientations
|
||||
from typing import Tuple, List
|
||||
import pieces
|
||||
import sys
|
||||
import numpy as np
|
||||
import colorama
|
||||
import hashlib
|
||||
|
||||
def backtrack(board: Board, pieces_list: List[str], piece_index: int,
|
||||
orientations: dict, solutions: List[np.ndarray]) -> None:
|
||||
@ -31,7 +33,6 @@ def backtrack(board: Board, pieces_list: List[str], piece_index: int,
|
||||
board.remove(orientation, (row, col))
|
||||
|
||||
|
||||
|
||||
def solve(xPin: Tuple[int, int], yPin: Tuple[int, int], zPin: Tuple[int, int]):
|
||||
"""
|
||||
solve the puzzle, avoiding the pins at the specified positions.
|
||||
@ -94,28 +95,74 @@ def colorful_solution(xPin, yPin, zPin) -> str:
|
||||
print("--------------------")
|
||||
print(f"Total solutions: {len(solutions)}")
|
||||
|
||||
def try_all_pegs():
|
||||
def check_rotations(Ax, Ay, Bx, By, Cx, Cy, checked):
|
||||
"""
|
||||
Check if any rotation of these three pins was already in `checked`.
|
||||
If yes, return True; if not, add them and return False.
|
||||
We assume a 5x5 board with valid row/col in [0..4].
|
||||
"""
|
||||
|
||||
def rotate_90(r, c):
|
||||
# Rotate (r, c) by 90 degrees on a 5x5 board => (c, 4 - r)
|
||||
return (c, 4 - r)
|
||||
|
||||
# Start with the 3 pin positions
|
||||
base_pins = [(Ax, Ay), (Bx, By), (Cx, Cy)]
|
||||
# Sort them so (pin1, pin2, pin3) is in a canonical order
|
||||
|
||||
# Generate all 4 rotations
|
||||
rotations = []
|
||||
current = base_pins
|
||||
for _ in range(4):
|
||||
# Rotate each pin in `current` by 90 degrees
|
||||
current = [rotate_90(r, c) for (r, c) in current]
|
||||
# Sort again so we have a canonical ordering
|
||||
rotations.append(tuple(current))
|
||||
|
||||
# Check if any rotation is already in `checked`
|
||||
for pins_tuple in rotations:
|
||||
if pins_tuple in checked:
|
||||
return True
|
||||
|
||||
# If none were found, add *all* rotations to `checked`
|
||||
# so we never re-check or re-add them in the future.
|
||||
for pins_tuple in rotations:
|
||||
checked.add(pins_tuple)
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def try_all_pegs_naive():
|
||||
from tqdm import tqdm
|
||||
all_solutions = []
|
||||
# Solution entry {x: (row, col), y: (row, col), z: (row, col), solution_count: int}
|
||||
|
||||
for xPinA in (range(5)):
|
||||
for yPinA in range(5):
|
||||
# 5^4 = 625 iterations
|
||||
# 3^6 = 729 iterations
|
||||
# 5^6 = 15625 iterations
|
||||
checked = set()
|
||||
for xPinA in tqdm(range(5)):
|
||||
for yPinA in (range(5)):
|
||||
for xPinB in range(5):
|
||||
for yPinB in range(5):
|
||||
for xPinC in tqdm(range(5)):
|
||||
for xPinC in (range(5)):
|
||||
for yPinC in range(5):
|
||||
if (xPinA, yPinA) == (xPinB, yPinB) or (xPinA, yPinA) == (xPinC, yPinC) or (xPinB, yPinB) == (xPinC, yPinC):
|
||||
continue
|
||||
|
||||
if check_rotations(xPinA, yPinA, xPinB, yPinB, xPinC, yPinC, checked):
|
||||
continue
|
||||
|
||||
solutions = solve((xPinA, yPinA), (xPinB, yPinB), (xPinC, yPinC))
|
||||
import sys
|
||||
if solutions:
|
||||
all_solutions.append({
|
||||
print({
|
||||
'x': (xPinA, yPinA),
|
||||
'y': (xPinB, yPinB),
|
||||
'z': (xPinC, yPinC),
|
||||
'solution_count': len(solutions)
|
||||
})
|
||||
return all_solutions
|
||||
}, file=sys.stdout, flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# colorful_solution((0, 2), (2, 0), (3, 3))
|
||||
print(try_all_pegs())
|
||||
colorful_solution((0, 0), (4, 4), (4, 0))
|
||||
# try_all_pegs_naive()
|
Loading…
x
Reference in New Issue
Block a user