Ramsey's theorem: Difference between revisions

Ramsey's theorem in BASIC256
m (→‎{{header|Phix}}: syntax coloured)
(Ramsey's theorem in BASIC256)
Line 291:
1101000100000000-1
</pre>
 
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<lang BASIC256>global k, a, idx
k = 1
dim a(18,18)
dim idx(5)
for i = 0 to 17
a[i,i] = 2 #-1
next i
 
while k <= 8
for i = 1 to 17
j = (i + k) mod 17
if j <> 0 then
a[i,j] = 1 : a[j,i] = 1
end if
next i
k *= 2
end while
for i = 1 to 17
for j = 1 to 17
if a[i,j] = 2 then
print "- ";
else
print int(a[i,j]) & " ";
end if
next j
print
next i
 
# Es simétrico, por lo que solo necesita probar grupos que contengan el nodo 0.
for i = 0 to 17
idx[0] = i
if EncontrarGrupo(1, i+1, 17, 1) or EncontrarGrupo(0, i+1, 17, 1) then
print chr(10) & "No satisfecho."
exit for
end if
next i
print chr(10) & "Satisface el teorema de Ramsey."
end
 
function EncontrarGrupo(tipo, min, max, fondo)
if fondo = 0 then
c = ""
if tipo = 0 then c = "des"
print "Grupo totalmente "; c; "conectado:";
for i = 0 to 4
print " " & idx[i]
next i
print
return true
end if
 
for i = min to max
k = 0
for j = k to fondo
if a[idx[k],i] <> tipo then exit for
next j
 
if k = fondo then
idx[k] = i
if EncontrarGrupo(tipo, 1, max, fondo+1) then return true
end if
next i
return false
end function</lang>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|C}}==
2,148

edits