Data fixup

This commit is contained in:
Boyan 2024-12-25 03:31:41 +02:00
parent 27a80e3f3a
commit 2a96262583
3 changed files with 78764 additions and 3147 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,87 @@
import json
def rotate_90(position):
"""
Rotate (pinA, pinB) by 90 degrees around the center of a 5x5 board.
Formula: (pinA, pinB) -> (pinB, 4 - pinA)
"""
pinA, pinB = position
return (pinB, 4 - pinA)
def rotate_all_rotations(pins):
"""
Generate all unique rotations (90, 180, 270 degrees) of the given pin positions.
Returns a list of rotated pin sets.
"""
rotated_pins = []
current_pins = pins.copy()
for _ in range(3): # Rotate 3 times (90, 180, 270 degrees)
current_pins = [rotate_90(pin) for pin in current_pins]
rotated_pins.append(current_pins.copy())
return rotated_pins
def pins_to_tuple(entry):
# Convert each pin's coordinates to tuples for immutability
return (
tuple(entry['pinA']),
tuple(entry['pinB']),
tuple(entry['pinC'])
)
def main():
# Load existing data
with open('data.json', 'r') as f:
data = json.load(f)
# Initialize a set to track existing forbidden pin sets to avoid duplicates
existing_pins_set = set()
# Populate the existing_pins_set with the original data
for entry in data:
pins_tuple = pins_to_tuple(entry)
existing_pins_set.add(pins_tuple)
# List to hold new rotated entries
new_entries = []
# Iterate over the existing data and generate rotated entries
for entry in data:
pinA = tuple(entry['pinA'])
pinB = tuple(entry['pinB'])
pinC = tuple(entry['pinC'])
base_pins = [pinA, pinB, pinC]
# Generate all rotated versions
rotated_versions = rotate_all_rotations(base_pins)
for rotated in rotated_versions:
rotated_pinA, rotated_pinB, rotated_pinC = rotated
rotated_entry = {
'pinA': list(rotated_pinA),
'pinB': list(rotated_pinB),
'pinC': list(rotated_pinC),
'solution_count': entry['solution_count']
}
rotated_pins_tuple = (
tuple(rotated_entry['pinA']),
tuple(rotated_entry['pinB']),
tuple(rotated_entry['pinC'])
)
if rotated_pins_tuple not in existing_pins_set:
new_entries.append(rotated_entry)
existing_pins_set.add(rotated_pins_tuple)
print(f"Added {len(new_entries)} rotated entries.")
# Combine original data with new rotated entries
extended_data = data + new_entries
# Save the extended data to a new JSON file
with open('data_extended.json', 'w') as f:
json.dump(extended_data, f, indent=4)
print("Extended data saved to 'data_extended.json'.")
if __name__ == "__main__":
main()