Created
March 3, 2018 09:31
-
-
Save neoatlantis/9a9a609b61fe8b81edd3d450faf720d6 to your computer and use it in GitHub Desktop.
Solution to: https://pbs.twimg.com/media/DXNgwyUWkAIdhtu.jpg
This file contains hidden or 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 python3 | |
import itertools | |
A, B, C, D = [1, 2, 3, 4] | |
iterer = itertools.product([A, B, C, D], repeat=10) | |
for comb in iterer: | |
q1, q2, q3, q4, q5, q6, q7, q8, q9, q10 = comb | |
countA = len([i for i in comb if i == A]) | |
countB = len([i for i in comb if i == B]) | |
countC = len([i for i in comb if i == C]) | |
countD = len([i for i in comb if i == D]) | |
minOpt = min([countA, countB, countC, countD]) | |
maxOpt = max([countA, countB, countC, countD]) | |
if not ( | |
(q2 == A and q5 == C) or | |
(q2 == B and q5 == D) or | |
(q2 == C and q5 == A) or | |
(q2 == D and q5 == B) | |
): continue | |
if not ( | |
(q3 == A and q3 != q6 and q3 != q2 and q3 != q4) or | |
(q3 == B and q6 != q3 and q6 != q2 and q6 != q4) or | |
(q3 == C and q2 != q3 and q2 != q6 and q2 != q4) or | |
(q3 == D and q4 != q3 and q4 != q6 and q4 != q2) | |
): continue | |
if not ( | |
(q4 == A and q1 == q5) or | |
(q4 == B and q2 == q7) or | |
(q4 == C and q1 == q9) or | |
(q4 == D and q6 == q10) | |
): continue | |
if not ( | |
(q5 == A and q5 == q8) or | |
(q5 == B and q5 == q4) or | |
(q5 == C and q5 == q9) or | |
(q5 == D and q5 == q7) | |
): continue | |
if not ( | |
(q6 == A and q8 == q2 and q8 == q4) or | |
(q6 == B and q8 == q1 and q8 == q6) or | |
(q6 == C and q8 == q3 and q8 == q10) or | |
(q6 == D and q8 == q5 and q8 == q9) | |
): continue | |
if not( | |
(q7 == A and countC == minOpt) or | |
(q7 == B and countB == minOpt) or | |
(q7 == C and countA == minOpt) or | |
(q7 == D and countD == minOpt) | |
): continue | |
if not( | |
(q8 == A and abs(q1 - q7) > 1) or | |
(q8 == B and abs(q1 - q5) > 1) or | |
(q8 == C and abs(q1 - q2) > 1) or | |
(q8 == D and abs(q1 - q10) > 1) | |
): | |
continue | |
if not ( | |
(q9 == A and ((q1 == q6) ^ (q6 == q5))) or | |
(q9 == B and ((q1 == q6) ^ (q10 == q5))) or | |
(q9 == C and ((q1 == q6) ^ (q2 == q5))) or | |
(q9 == D and ((q1 == q6) ^ (q9 == q5))) | |
): continue | |
if not ( | |
(q10 == A and 3 == maxOpt - minOpt) or | |
(q10 == B and 2 == maxOpt - minOpt) or | |
(q10 == C and 4 == maxOpt - minOpt) or | |
(q10 == D and 1 == maxOpt - minOpt) | |
): continue | |
print(comb) | |
print("done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment