Jump to content

Ramsey's theorem: Difference between revisions

(→‎{{header|PARI/GP}}: add checking code)
Line 350:
 
=={{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>if __name__ == '__main__':
 
<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
 
 
<lang python>if __name__ == '__main__':
for i in range17:
a[i][i] = '-'
Line 360 ⟶ 388:
j = (i + pow(2, k)) % 17
a[i][j] = a[j][i] = '1'
 
# testcase breakage
# a[2][1] = a[1][2] = '0'
 
for row in a:
print(' '.join(row))</lang>
 
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}}
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.