Created
November 19, 2018 17:44
-
-
Save maysam/4040fd9245e0b5d1c21dcf593cc6c610 to your computer and use it in GitHub Desktop.
Hide and Seek Safari Puzzle Game Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
# https://www.amazon.co.uk/Smart-Games-Hide-Safari-Puzzle-x/dp/B000H5V6U6 | |
# https://www.amazon.com/Smart-Tangoes-USA-SG-101/dp/B004TGVIXY | |
# https://righttolearn.com.sg/collections/iq-games/products/iq-game-animal-puzzle-433 | |
import numpy as np | |
from itertools import permutations | |
import collections | |
boards=[ | |
np.array( | |
[ | |
[ 'E', None, 'L' ], | |
[ 'Z', 'D', 'Z' ], | |
[ 'R', 'L', 'E' ], | |
]), | |
np.array( | |
[ | |
[ 'D', None, 'L' ], | |
[ None, 'Z', 'E' ], | |
[ 'L', 'R', 'D' ], | |
]), | |
np.array( | |
[ | |
[ 'R', 'E', 'Z' ], | |
[ 'D', None, 'D' ], | |
[ 'L', None, 'R' ], | |
]), | |
np.array( | |
[ | |
[ None, None, None ], | |
[ None, 'R', 'L' ], | |
[ 'D', 'E', 'Z' ], | |
]), | |
] | |
bars = [ | |
np.array([ | |
[True, False, True], | |
[True, True, True], | |
[True, False, True], | |
]), | |
np.array([ | |
[True, True, False], | |
[True, True, False], | |
[False, True, True], | |
]), | |
np.array([ | |
[True, True, True], | |
[True, False, True], | |
[True, False, True], | |
]), | |
np.array([ | |
[True, True, False], | |
[True, True, True], | |
[True, False, True], | |
]), | |
] | |
def calc(boards, bars, orientation, placement): | |
replaced_bars = list(map(lambda i: bars[placement[i]], range(4))) | |
rotated_bars = list(map(lambda i: np.rot90(replaced_bars[i], orientation[i]), range(4))) | |
count = collections.defaultdict(lambda : 0) | |
for i in range(4): | |
for j in range(3): | |
for k in range(3): | |
if rotated_bars[i][j][k] == False: | |
key = boards[i][j][k] | |
if key != None: | |
count[key] += 1 | |
return count | |
pattern = {'D': 6, 'L': 1} | |
count = 0 | |
placements = list(permutations(range(4))) | |
for placement in placements: | |
for i in range(4**4): | |
rotation = [i%4, i//4%4, i//4//4%4, i//4//4//4%4] | |
result = calc(boards, bars, rotation, placement) | |
# piece zero is isometric, so skip the identical rotations | |
i = 0 | |
if rotation[i] > 1 and placement[i] == 0: | |
continue | |
i = 1 | |
if rotation[i] > 1 and placement[i] == 0: | |
continue | |
i = 2 | |
if rotation[i] > 1 and placement[i] == 0: | |
continue | |
i = 3 | |
if rotation[i] > 1 and placement[i] == 0: | |
continue | |
check = True | |
for key, value in pattern.items(): | |
if result[key] != value: | |
check = False | |
for key, value in result.items(): | |
if key not in pattern: | |
check = False | |
elif pattern[key] != value: | |
check = False | |
if check: | |
print(placement) | |
print(rotation) | |
print(dict(result)) | |
count += 1 | |
print(str(count) + ' solutions') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment