Ramsey's theorem: Difference between revisions
Content added Content deleted
(→{{header|PARI/GP}}: add checking code) |
|||
Line 350: | Line 350: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{incorrect|Python|The task has been changed to also require demonstrating that the graph is a solution.}} |
|||
{{works with|Python|3.4.1}} |
|||
⚫ | |||
<lang python>range17 = range(17) |
|||
a = [['0'] * 17 for i in range17] |
|||
idx = [0] * 4 |
|||
def find_group(mark, min_n, max_n, depth=1): |
|||
if (depth == 4): |
|||
prefix = "" if (mark == '1') else "un" |
|||
print("Fail, found totally {}connected group:".format(prefix)) |
|||
for i in range(4): |
|||
print(idx[i]) |
|||
return True |
|||
for i in range(min_n, max_n): |
|||
n = 0 |
|||
while (n < depth): |
|||
if (a[idx[n]][i] != mark): |
|||
break |
|||
n += 1 |
|||
if (n == depth): |
|||
idx[n] = i |
|||
if (find_group(mark, 1, max_n, depth + 1)): |
|||
return True |
|||
return False |
|||
⚫ | |||
for i in range17: |
for i in range17: |
||
a[i][i] = '-' |
a[i][i] = '-' |
||
Line 360: | Line 388: | ||
j = (i + pow(2, k)) % 17 |
j = (i + pow(2, k)) % 17 |
||
a[i][j] = a[j][i] = '1' |
a[i][j] = a[j][i] = '1' |
||
# testcase breakage |
|||
# a[2][1] = a[1][2] = '0' |
|||
for row in a: |
for row in a: |
||
print(' '.join(row)) |
print(' '.join(row)) |
||
for i in range17: |
|||
idx[0] = i |
|||
if (find_group('1', i + 1, 17) or find_group('0', i + 1, 17)): |
|||
print("no good") |
|||
exit() |
|||
print("all good")</lang> |
|||
{{out|Output same as C}} |
{{out|Output same as C}} |
||