Ramsey's theorem: Difference between revisions

m
→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations.
(Added Elixir)
m (→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations.)
Line 656:
=={{header|REXX}}==
Mainline programming was borrowed from '''C'''.
<lang rexx>/*REXX programsprogram finds and displays a 17 node graph such that any four nodes are neither */
/*────── nodes are neither ─────────────────────────────────────────── totally connected nor totally unconnected.*/
@.=0; #=17 /*initialize the node graph to zero. */
do d=0 for #; @.d.d=2; end /*d*/ /*set the diagonal elements to 2two. */
 
do do k=1 by 0 while k<=8 /*K is doubled each time through loop.*/
do i=0 for # /*process each column in the array. */
j= (i+k) // # /*set a row,colcolumn and colcolumn,row. */
@.i.j=1; @.j.i=1 /*set two array elements to unity. */
end /*i*/
k=k+k /*double the value of K for each loop*/
end /*while k≤8*/
/* [↓] display a connection grid. */
do r=0 for #; _=; do c=0 for # /*show each row, build colcolumn by colcolumn*/
_=_ @.r.c /*add this (append) the column to the row. */
end /*c*/
 
say left('', 9) translate(_,' "-'", 2) /*display the constructed row. */
end /*r*/
/*verify the sub-graphs connections. */
!.=0; ok=1 /*Ramsey's connections; OK (so far).*/
/* [↓] check columncol. with row connconnections*/
do v=0 for # /*check sub-graphs #number connections. */
do h=0 for # /*check column connectionconnections to rowthe rows.*/
if @.v.h==1 then !._v.v=!._v.v+1 /*if connected, then bump the counter.*/
end /*h*/ /* [↑] Note: we're counting each */
ok=ok & !._v.v==#%2 /* each connection twice, so divide */
end /*v*/ /* so dividethe total by two. */
/* [↓] check columncol. with row connconnections*/
do h=0 for # /*check the sub-graphs # of connections.*/
do v=0 for # /*check the row connection to a column.*/
if @.h.v==1 then !._h.h=!._h.h+1 /*if connected, then bump the counter.*/
end /*v*/ /* [↑] Note: we're counting each */
ok=ok & !._h.h==#%2 /* each connection twice, so divide */
end /*h*/ /* so dividethe total by two. */
say /* [↓] a yea─or─nay message. */
say; say space("Ramsey's condition" word('not', 1+ok) ' "satisfied.'")
/*stick a fork in it, we're all done. */</lang>
'''output''' &nbsp; ('''17x17''' connectivity matrix):
<pre>