Справочная информация: число Рамсея дает минимальное количество вершин v в полном графе K v , так что раскраска краев в красный / синий цвет K v имеет хотя бы один красный K r или один синий K s . Оценки для увеличения г , с очень трудно установить.
Ваша задача - вывести число для 1 ≤ r , s ≤ 5 .
вход
Два целых числа с 1 ≤ r ≤ 5 и 1 ≤ s ≤ 5 .
Выход
как указано в этой таблице:
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
Обратите внимание, что и s являются взаимозаменяемыми: R ( r , s ) = R ( s , r ) .
Для вы можете вывести любое целое число от 43 до 48 включительно. На момент публикации этого вопроса это самые известные границы.
5,5
), что это может подходить для колмогоровской сложности (или подходит только для ввода без фиксированного вывода?)Ответы:
JavaScript (ES6),
5149 байтПринимает ввод в синтаксисе карри
(r)(s)
.Попробуйте онлайн!
Как?
В первом приближении используем формулу:
Если у нас , мы просто добавляем 1 :min(r,s)<3 1
В противном случае, мы добавим значения выбираются из справочной таблицы, ключ определяется по формуле:k
источник
JavaScript (Node.js) ,
5655 байтПопробуйте онлайн! Я заметил, что таблица напоминает треугольник Паскаля, но с поправочными коэффициентами. Редактировать: 1 байт сохранен благодаря @sundar.
источник
x*y>19
withx+y>8
.Jelly,
1716 bytesTry it online! Or see a test-suite.
Replace theR(5,5) equal to 43 , 44 , 45 , 46 , or 47 respectively (rather than the 48 here).
0
with+
,,
,-
,.
, or/
to setHow?
SinceR(r,s)≤R(r−1,s)+R(r,s−1) we may find that:
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
.источник
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...
источник
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.
источник
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
источник
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!
источник
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
источник
Python 3, 74 bytes
Try it online!
источник
Proton, 52 bytes
Near-port of my Python answer.
Try it online!
источник
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.
источник
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.
источник