Created
January 13, 2016 16:47
-
-
Save dzitkowskik/525b62c2d02634de8df8 to your computer and use it in GitHub Desktop.
Ramsey STH
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
def fun(tab, pos, col, depth): | |
rtab = [] | |
if depth == 9: | |
return check(tab), rtab | |
tab.insert(pos, col) | |
for j in range(depth): | |
r=0 | |
for i in [1,2,3]: | |
[ret, rtab] = fun(list(tab), j, i, depth+1) | |
if ret > 0: | |
r += 1 | |
print(tab) | |
print(rtab) | |
if r == 3: | |
return 1, rtab.append(j) | |
return 0, rtab | |
def check(tab): | |
k1 =[] | |
k2=[] | |
k3=[] | |
for i in range(len(tab)): | |
if tab[i] == 1: | |
k1.append(i) | |
if tab[i]==2: | |
k2.append(i) | |
if tab[i]==3: | |
k3.append(i) | |
if len(k1) > 2: | |
if k1[2] - k1[1] == k1[1] - k1[0]: | |
return 1 | |
if len(k2) > 2: | |
if k2[2] - k2[1] == k2[1] - k2[0]: | |
return 1 | |
if len(k3) > 2: | |
if k3[2] - k3[1] == k3[1] - k3[0]: | |
return 1 | |
return 0 | |
tab = [] | |
#for i in [1,2,3]: | |
print(fun([1], 0, 1, 2)) | |
print(fun([1], 0, 2, 2)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment