Ramsey's theorem: Difference between revisions
m
syntax highlighting fixup automation
(Ramsey's theorem in Yabasic) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 10:
{{trans|Python}}
<
V idx = [0] * 4
Line 50:
L.break
L.was_no_break
print(‘all good’)</
{{out}}
Line 76:
=={{header|360 Assembly}}==
{{trans|C}}
<
RAMSEY CSECT
USING RAMSEY,R13 base register
Line 220:
XDEC DS CL12 temp xdeco
YREGS
END RAMSEY</
{{out}}
<pre>
Line 244:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f RAMSEYS_THEOREM.AWK
# converted from Ring
Line 270:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 294:
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<
k = 1
dim a(18,18)
Line 357:
next i
return false
end function</
{{out}}
<pre>Same as FreeBASIC entry.</pre>
Line 365:
No issue with the code or the output, there seems to be a bug with Rosettacode's tag handlers. - aamrun
<
int a[17][17], idx[4];
Line 426:
puts("all good");
return 0;
}</
{{out}} (17 x 17 connectivity matrix):
<pre>
Line 451:
=={{header|D}}==
{{trans|Tcl}}
<
/// Generate the connectivity matrix.
Line 507:
writefln("%-(%(%c %)\n%)", mat);
mat.ramseyCheck.writeln;
}</
{{out}}
<pre>- 1 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1
Line 530:
=={{header|Elixir}}==
{{trans|Erlang}}
<
def main(n\\17) do
vertices = Enum.to_list(0 .. n-1)
Line 585:
end
Ramsey.main</
{{out}}
Line 611:
=={{header|Erlang}}==
{{trans|C}} {{libheader|Erlang digraph}}
<
-export([main/0]).
Line 683:
++ [{wholly_connected,V1,V2,V3,V4}
|| {V1,V2,V3,V4,_,false} <- ListConditions]}
end.</
{{out}}
<pre>- 1 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1
Line 708:
{{trans|Ring}}
{{trans|Go}}
<
Dim Shared As Integer i, j, k = 1
Dim Shared As Integer a(17,17), idx(4)
Line 771:
Print Chr(10) & "Satisface el teorema de Ramsey."
End
</syntaxhighlight>
{{out}}
<pre>
Line 797:
=={{header|Go}}==
{{trans|C}}
<
import "fmt"
Line 871:
}
fmt.Println("All good.")
}</
{{out}}
Line 896:
=={{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: <
1 2 4 8
1 #~ 1 j. 0 _1:} i.@<.&.(2&^.) N =: 17 NB. Turn indices into bit mask
Line 941:
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 _ 1
1 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1 _</
To test if all combinations of 4 rows and columns contain both a 0 and a 1
<syntaxhighlight 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.
Line 956:
*./ (4 comb 17) checkRow ramsey 17
1
</syntaxhighlight>
=={{header|Java}}==
Translation of Tcl via D
{{works with|Java|8}}
<
import java.util.stream.IntStream;
Line 1,022:
System.out.println(ramseyCheck(mat));
}
}</
<pre>[-, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1]
Line 1,045:
=={{header|Julia}}==
{{trans|C}}
<
function findgroup(typ, nmin, nmax, depth)
Line 1,102:
testnodes()
</
<pre>
- 1 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1
Line 1,126:
=={{header|Kotlin}}==
{{trans|C}}
<
val a = Array(17) { IntArray(17) }
Line 1,178:
}
println("\nRamsey condition satisfied.")
}</
{{out}}
Line 1,204:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
vl = VertexList[g];
ss = Subsets[vl, {4}];
NoneTrue[ss, CompleteGraphQ[Subgraph[g, #]] &]
NoneTrue[ss, Length[ConnectedComponents[Subgraph[g, #]]] == 4 &]</
{{out}}
[[File:Ramsey.png]]
Line 1,216:
=={{header|Mathprog}}==
{{lines too long|Mathprog}}
<syntaxhighlight lang="text">/*Ramsey 4 4 17
This model finds a graph with 17 Nodes such that no clique of 4 Nodes is either fully
Line 1,229:
clique{a in 1..(Nodes-3), b in (a+1)..(Nodes-2), c in (b+1)..(Nodes-1), d in (c+1)..Nodes} : 1 <= Arc[a,b] + Arc[a,c] + Arc[a,d] + Arc[b,c] + Arc[b,d] + Arc[c,d] <= 5;
end;</
This may be run with:
<
The solution may be viewed on [[Solution Ramsey Mathprog|this page]].
In the solution file, the first section identifies the number of nodes connected in this clique. In the second part of the solution, the status of each arc in the graph (connected=<tt>1</tt>, unconnected=<tt>0</tt>) is shown.
Line 1,238:
=={{header|Nim}}==
{{trans|Kotlin}}
<
var idx: array[4, int]
Line 1,282:
quit "\nRamsey condition not satisfied.", QuitFailure
echo "\nRamsey condition satisfied."</
{{out}}
Line 1,307:
=={{header|PARI/GP}}==
This takes the [[#C|C]] solution to its logical extreme.
<
check(M)={
Line 1,328:
M=matrix(17,17,x,y,my(t=abs(x-y)%17);t==2^min(valuation(t,2),3))
check(M)</
=={{header|Perl}}==
{{trans|Raku}}
{{libheader|ntheory}}
<
use Math::Cartesian::Product;
Line 1,355:
print join(' ' ,@$_) . "\n" for @a;
print 'OK'</
{{out}}
<pre>- 1 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1
Line 1,378:
=={{header|Phix}}==
{{trans|Go}}
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'0'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">17</span><span style="color: #0000FF;">),</span><span style="color: #000000;">17</span><span style="color: #0000FF;">),</span>
Line 1,437:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">all_good</span><span style="color: #0000FF;">?</span><span style="color: #008000;">"Satisfies Ramsey condition.\n"</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"No good.\n"</span><span style="color: #0000FF;">))</span>
<!--</
{{out}}
<pre>
Line 1,466:
{{trans|C}}
<
a = [['0'] * 17 for i in range17]
idx = [0] * 4
Line 1,514:
exit()
print("all good")</
{{out|Output same as C}}
Line 1,525:
Kind of a translation of C (ie, reducing this problem to generating a printout of a specific matrix).
<
(define N 17)
Line 1,538:
(λ(j) (case (dist i j) [(0) '-] [(1 2 4 8) 1] [else 0]))))))
(for ([row v]) (displayln row))</
=={{header|Raku}}==
(formerly Perl 6)
{{Works with|rakudo|2018.08}}
<syntaxhighlight lang="raku"
my @a = [ 0 xx $n ] xx $n;
@a[$_;$_] = '-' for ^$n;
Line 1,557:
die "Bogus!" unless 0 < $links < 6;
}
say "OK";</
{{out}}
<pre>- 1 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1
Line 1,580:
=={{header|REXX}}==
Mainline programming was borrowed from '''C'''.
<
/*────────────────────────────────────────── totally connected nor totally unconnected. */
@.=0; #=17 /*initialize the node graph to zero. */
Line 1,615:
end /*h*/ /* divide the total by two. */
say /*stick a fork in it, we're all done. */
say space("Ramsey's condition is"word("'nt", 1+ok) 'satisfied.') /*show yea─or─nay.*/</
{{out|output|text= ('''17x17''' connectivity matrix):}}
<pre>
Line 1,640:
=={{header|Ring}}==
<
# Project : Ramsey's theorem
Line 1,666:
see nl
next
</syntaxhighlight>
Output:
<pre>
Line 1,689:
=={{header|Ruby}}==
<
17.times{|i| a[i][i] = '-'}
4.times do |k|
Line 1,704:
end
puts "Ok"
</syntaxhighlight>
{{out}}
<pre>
Line 1,729:
=={{header|Run BASIC}}==
{{incorrect|Run BASIC|The task has been changed to also require demonstrating that the graph is a solution.}}
<
for i = 1 to 17: a(i,i) = -1: next i
k = 1
Line 1,745:
next j
print
next i</
<pre>-1 1 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1
1 -1 1 1 0 1 0 0 0 1 1 0 0 0 1 0 1
Line 1,766:
=={{header|Sidef}}==
{{trans|Ruby}}
<
17.times {|i| a[i][i] = '-' }
Line 1,782:
((0 < links) && (links < 6)) || die "Bogus!"
})
say "Ok"</
{{out}}
<pre>
Line 1,807:
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
<
# Generate the connectivity matrix
Line 1,851:
puts [join $matrix \n]
ramseyCheck4 $matrix</
{{out}}
<pre>
Line 1,877:
{{trans|C}}
{{libheader|Wren-fmt}}
<
var a = List.filled(17, null)
Line 1,937:
}
}
System.print("All good.")</
{{out}}
Line 1,962:
=={{header|Yabasic}}==
<
// by Jjuanhdez, 06/2022
Line 2,027:
next i
print color("gre") "\nSatisface el teorema de Ramsey.\n"
end</
{{out}}
<pre>Same as FreeBASIC entry.</pre>
|