Contexte: le nombre de Ramsey donne le nombre minimum de sommets v dans le graphique complet K v de telle sorte qu'une coloration de bord rouge / bleu de K v ait au moins un rouge K r ou un bleu K s . Les limites pour des r , s plus grands sont très difficiles à établir.
Votre tâche consiste à sortir le nombre pour 1 ≤ r , s ≤ 5 .
Contribution
Deux entiers avec 1 ≤ r ≤ 5 et 1 ≤ s ≤ 5 .
Production
comme indiqué dans ce tableau:
s 1 2 3 4 5
r +--------------------------
1 | 1 1 1 1 1
2 | 1 2 3 4 5
3 | 1 3 6 9 14
4 | 1 4 9 18 25
5 | 1 5 14 25 43-48
Notez que et s sont interchangeables: R ( r , s ) = R ( s , r ) .
Pour vous pouvez sortir n'importe quel entier entre 43 et 48 inclus. Au moment de la publication de cette question, ce sont les limites les plus connues.
5,5
) que cela peut correspondre à la complexité de kolmogorov (ou ne convient- il qu'à une sortie fixe non entrée?)Réponses:
JavaScript (ES6),
5149 octetsPrend des entrées dans la syntaxe de curry
(r)(s)
.Essayez-le en ligne!
Comment?
En première approximation, nous utilisons la formule:
Si nous avons , nous ajoutons simplement 1 :min(r,s)<3 1
Sinon, nous ajoutons une valeur choisie dans une table de recherche dont la clé est définie par:k
la source
JavaScript (Node.js) ,
5655 octetsEssayez-le en ligne! J'ai remarqué que le tableau ressemble au triangle de Pascal mais avec des facteurs de correction. Edit: 1 octet enregistré grâce à @sundar.
la source
x*y>19
parx+y>8
.Gelée ,
1716 octetsEssayez-le en ligne! Ou consultez une suite de tests .
0
+
,
-
.
/
Comment?
This is
’ScḢƊ
and would produce:If we subtract one for each time nine goes into the result we align three more with our goal (this is achieved with
_:¥9
):The remaining two incorrect values,32 and 63 may then be translated using Jelly's
y
atom and code-page indices with“ ı?0‘y
.la source
Python 2, 62 bytes
Try it online!
Python 2, 63 bytes
Try it online!
This is ridiculous, I will soon regret having posted this... But eh, ¯\_(ツ)_/¯. Shaved off 1 byte thanks to our kind Jonathan Allan :). Will probably be outgolfed by about 20 bytes shortly though...
la source
Julia 0.6,
71615957 bytesTry it online!
Ungolfed (well, a bit more readable):
What does it do?
Takes input as array
A
containing r and s. Unpacks the array into r and s with the smaller number as r, using(r,s)=sort(A)
.If r is 1, output should be 1. If r is 2, output should be whatever s is.
sr−1 will be s0=1 for r=1, and s1=s for r = 2.
So,
r<3?s^(r-1)
or shorter,r<3?s^~-r
For the others, I started with noticing that the output is:
(I initially worked with f(5,5)=45 for convenience.)
This looked like a potentially usable pattern - they all have
2r
in common, 17 is 8*2+1, 35 is 17*2+1, 10 is 3*3+1. I started with extracting the base value from [0, 3, 8], as[0 3 8][s-2]
(this later became the shorter(s^2-4s+3)
).Attempting to get correct values for r = 3, 4, and 5 with this went through many stages, including
and
Expanding the latter and simplifying it led to the posted code.
la source
x86,
4937 bytesNot very optimized, just exploiting the properties of the first three rows of the table. While I was writing this I realized the code is basically a jump table so a jump table could save many bytes. Input in
eax
andebx
, output ineax
.-12 by combining cases of
r >= 3
into a lookup table (originally justr >= 4
) and using Peter Cordes's suggestion ofcmp
/jae
/jne
with the flags still set so thatr1,r2,r3
are distinguished by only onecmp
! Also indexing into the table smartly using a constant offset.Hexdump
la source
r1: cmp $2, %al
/jae r2
will set flags such that you can user2: jne r3
without anothercmp
. The jump target inr1
can be aret
somewhere else, and fall through tor2
. (Reverse the condition). BTW, this is the first code-golf question I looked at after answering your Short jump offset table usage question on SO. I guess I picked the right one from HNQ :)r4
can be one instruction:mov table-8(%ebx,%eax), %al
. IDK why you used a separate instruction to mov the table address into a register. But one of the key things is that constant offsets from symbols don't cost anything extra because it already assembles to a 32-bit absolute address. Object file formats can represent symbol refs with an offset for when the linker fills in the final address so compilers don't have to put separate labels on every field of a struct, or every array element...ret
for r1 and r2.mov %ebx, %eax
toexit
, so it always runs after r3, and r2 jumps there or falls through into r3? Then r3 produces its result in BL withsub %bl, %al
/cmp $10, %al
/jne exit
/add $4, %bl
(neutral size change: cmp vs. add can use the al,imm8 short form). The gain is that it removes theret
from r2 as well. Hmm no that doesn't work, well maybe if you negate the table entries or something? And that probably clobbers something you need. I haven't thought this through and unfortunately don't have time to do so :/Python 2, 70 bytes
Try it online!
la source
MATL,
2521 bytesTry it on MATL Online
Attempt to port Jonathan Allan's Jelly answer to MATL.
+2-lGqXn
- same as that answer: computet8/k
- duplicate that, divide by 8 and floor-
- subtract that from previous result (We subtract how many times 8 goes in the number, instead of 9 in the Jelly answer. The result is the same for all but the 35 and 70, which here give 31 and 62.)t20/k
- duplicate that result too, divide that by 20 and floor (gives 0 for already correct results, 1 for 31, 3 for 62)6*
- multiply that by 6-
- subtract that from the result (31 - 6 = 25, 62 - 18 = 44)Older:
Try it on MATL Online
la source
Python 3, 74 bytes
Try it online!
la source
Proton, 52 bytes
Near-port of my Python answer.
Try it online!
la source
Java 8, 62 bytes
Lambda function, port of Arnauld's JavaScript answer. Try it online here.
Java, 83 bytes
Recursive function, port of Neil's JavaScript answer. Try it online here.
la source
C (gcc), 57 bytes
Recursive function, port of Neil's JavaScript answer. Try it online here.
C (gcc), 63 bytes
Port of Arnauld's JavaScript answer. Try it online here.
la source