Ramsey's theorem: Difference between revisions
→{{header|J}}: test if correct
(Updated and hopefully fixed the D entry) |
(→{{header|J}}: test if correct) |
||
Line 220:
=={{header|J}}==
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
Line 267 ⟶ 266:
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>
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}}==
|