Ramsey's theorem: Difference between revisions

Content added Content deleted
(Updated and hopefully fixed the D entry)
(→‎{{header|J}}: test if correct)
Line 220: Line 220:


=={{header|J}}==
=={{header|J}}==
{{incorrect|J|The task has been changed to also require demonstrating that the graph is a solution.}}
Interpreting this task as "reproduce the output of all the other examples", then here's a stroll to the goal through the J interpreter: <lang j> i.@<.&.(2&^.) N =: 17 NB. Count to N by powers of 2
Interpreting this task as "reproduce the output of all the other examples", then here's a stroll to the goal through the J interpreter: <lang j> i.@<.&.(2&^.) N =: 17 NB. Count to N by powers of 2
1 2 4 8
1 2 4 8
Line 267: Line 266:
1 0 1 0 0 0 1 1 0 0 0 1 0 1 1 _ 1
1 0 1 0 0 0 1 1 0 0 0 1 0 1 1 _ 1
1 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1 _</lang>
1 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1 _</lang>

Yes, this is really how you solve problems in J.
To test if all combinations of 4 rows and columns contain both a 0 and a 1
<lang j>
comb=: 4 : 0 M. NB. All size x combinations of i.y
if. (x>:y)+.0=x do. i.(x<:y),x else. (0,.x comb&.<: y),1+x comb y-1 end.
)

NB. returns 1 iff the subbmatrix of y consisting of the columns and rows labelled x contains both 1 and 0
checkRow =. 4 : 0 "1 _
*./ 0 1 e. ,x{"1 x{y
)

*./ (4 comb 17) checkRow a
1
</lang>


=={{header|Mathematica}}==
=={{header|Mathematica}}==