对警察和强盗进行硬编码(警察)


28

这是挑战。强盗的线索在这里

需要考虑的一个有趣问题是:

如果我有一个数字序列,那么在清楚我在说什么序列之前,我必须提供几个数字?

例如,如果我想谈的正整数,以便从开始1,我可以说,1,2,3,,但事实是否真的足够了吗?

我有一个回答这个问题的方法,而作为代码窃贼,它涉及代码高尔夫球。如果产生这些术语的最短代码产生了序列的所有术语,则您已提供了足够的序列术语。如果我们从代码高尔夫的角度来考虑这一点,那意味着您已经提供了足够的测试用例,从而使通过测试用例的最短代码可以完成所需的任务。

挑战

这个挑战是挑战。警察将在其中展示测试用例,而强盗将不得不寻找一种比预期序列更短的欺骗测试用例的方法。警察将提出以下内容:

  • 一段代码,将非负整数作为输入,并产生一个整数作为输出。此代码将定义您的顺序。您的代码不需要支持0作为输入,而是选择将1作为最小输入。如果您的答案是这种情况,则应该很清楚。

  • 任何可能影响输出的相关平台或语言要求,例如longint的大小。

  • 一个数字n,以及该代码计算出的序列的前n项。这些将充当“测试用例”。

鼓励您解释序列的作用并链接OEIS(如果存在),但是定义序列的是您的代码,而不是描述。

强盗将使用比所介绍的语言短的语言来找到一个程序,并通过所有测试用例(对于前n输入产生与警察代码相同的输出)。强盗的代码在输出上还必须与警察的程序有所不同,即大于某个数字n

警察在提交之前必须能够破解自己的答案。

一周后,警察可能会发现他们的裂缝并将答案标记为“安全”。标记为这样的答案将不再被破解。

计分

警察的答案将根据字节数进行评分,而字节数越少越好。破解答案的得分是无限的。


显然,有一些方法可以非数学方式破解问题,例如仅打印所有测试用例,但是该问题取决于警察提供的案例。是否应该有一个规则?对序列的可计算性有限制吗?还是从拉姆齐理论中得到任何限制?(即,您是否需要能够破解您的计算机?)
THEREALyumdub

2
@theReallyumdub问题规定您必须能够破解自己的提交。
小麦巫师

@CatWizard谢谢,我继续了,那已经是显而易见的meta了,它显然阻碍了其中一些人。因此,使裂纹花费一个多小时来进行计算或类似工作并不符合标签的精神
THEREALyumdub


是否存在“尽管从理论上讲您的解决方案必须在实践中适用于所有数字,但仅适用于...”条件?
user202729

Answers:


6

cQuents,4个字节(已破解

"::$

在线尝试!

以下是八(n=8)种情况:

1 1
2 12
3 123
4 1234
5 12345
6 123456
7 1234567
8 12345678

代码说明:

"      Stringify sequence (join on "", remove it and see what happens)
 ::    Given input n, output all items in the sequence up to and including n
   $   Each item in the sequence equals the index

这样的序列是1,2,3,4,5 ...,它被连接""起来就变成12345 ...,并::表示它打印到输入。



5

Python 3 66 57个字节(裂纹

在编辑之前,xnor
破解也由Cat Wizard破解

def f(n):x=n/10-2;return int(x*60-x**3*10+x**5/2-x**7/84)

在线尝试!

你好!这是要破解的序列。它为前40个元素赋予0索引,而不是OEIS序列n=40

[-54, -56, -58, -59, -59, -59, -59, -57, -55, -53, -50, -46, -43, -38, -33, -28, -23, -17, -11, -5, 0, 5, 11, 17, 23, 28, 33, 38, 43, 46, 50, 53, 55, 57, 59, 59, 59, 59, 58, 56]

我忘记删除空白了,我还不是专业高尔夫球手:p您介意我是否进行修改以解决此问题?
crashoz

好,去吧。我将消除裂缝。
小麦巫师


5

Python 2,44个字节(已破解

f=lambda n,i=1,p=1:n and-~f(n-p%i,i+1,p*i*i)

在线尝试!

质数。什么顺序可能更纯正?还是更过分了?你的目标是生产出第50个为质数n=1,以n=50

该代码是从本技巧完全复制的威尔逊定理生成器

替代顺序的不同值不是由于机器限制(例如溢出和精度)引起的。没有第三方图书馆。


破解由阿尔诺,@PoonLevi和Xcoder先生。


敢肯定你不是故意的话,被破获 ; 也许指定“ Python(无第三方库)”或“ Python(无导入)”或其他内容?
乔纳森·艾伦

@JonathanAllan谢谢,我编辑过没有第三方图书馆。
xnor

我还无法破解(目前我的最佳尝试是47个字节左右),但是我认为关于这些特殊的素数需要注意一些有趣的事情。对于每个,与[ 1 50 ] Ñ,这成立:2 p 2 MOD  p 。同时,对于不是非质数(在上述范围内)的任何数字,这都是不正确的,但确实如此pii[1,50]N2pi2(mod pi)因此,对于更高的值。我将这个想法留在这里,以便其他人可以使用所提到的技术来
尽力而为

@ Mr.Xcoder 是根据您提出的方法的最佳尝试。它在N = 69处成功发散,返回341(第一个以2为底的Fermat伪素数或第一个Poulet数),在N = 1时也失败。我怀疑自己可以自己解决此问题,所以我认为最好分享自己的东西。(我的最佳解决方法是46个字节...)
Arnauld

1
@Arnauld 使用此方法找到了一个44字节的解决方案。我似乎再也走不了了。也许其他人将能够解决这个问题。
Poon Levi '18年

4

Wolfram语言(Mathematica)39 34字节(安全)

Check[{1,9,7}[[#]],18+Boole[#>9]]&

在线尝试!

看起来很简单,解决方案应该很困难。

1索引并且。该序列在OEIS上不可用。n=99

{1, 9, 7, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19}

上面的列表等于:

Join[{1, 9, 7}, Table[18, 6], Table[19, 90]]

这是用于检查您的解决方案的模板:在线尝试!

预期裂纹

这里的问题是,当位数增加1时,输出增加1,前三个项除外;预期的解决方案与字符串转换有关。

因此,阅读有关在表达式和字符串之间转换的文档,您可以找到该函数SpokenString

解决方案只是x^n针对各种输入的表达式的口语字符串版本的长度:StringLength@SpokenString[x^#]&


3

Haskell中,29个字节(裂纹:12

a n=n*ceiling(realToFrac n/2)

在线尝试!

这是A093005a(n)=nn2

测试用例,即:0n20map a [0..20]

[0,1,2,6,8,15,18,28,32,45,50,66,72,91,98,120,128,153,162,190,200]

预期解决方案(20字节)

b n=sum$n<$show(3^n)

在线尝试!处不同,其中a 23 = 276b 23 = 253n=23a(23)=276b(23)=253

此函数等同于。由于上限,两个函数对于022范围内的整数参数重叠:b(n)=n len(3n)=nlog10(1+3n)022

资源



@Laikoni,如果预期的裂缝更短,那么其他人可能会向BMO索要强盗。
fəˈnɛtɪk

@ fəˈnɛtɪk谢谢,我不知道这个规则。
Laikoni '18


2
@BMO你去了:)
Laikoni '18

2

JavaScript(ES6),12个字节(已破解

这很容易。

n=>n*(8*n+1)

在线尝试!

这是A139275

a(n)=n(8n+1)

0n<9

0,9,34,75,132,205,294,399,520

按照挑战规则,它必须超越。


n=>8*n*n+n differs for n=94906273, is this a valid crack?
ngn

@ngn It looks valid to me according to the challenge rules, but maybe you should ask the OP whether loss of precision does count as a valid divergence? The intended crack differs for n=9, though.
Arnauld

@CatWizard ^­­­
ngn

I'd say it is a valid crack.
Wheat Wizard

2
cracked (| instead of +)
ngn

2

Malbolge, 10 bytes

ub&;$9]J6

Note that the code ends with an 0x14 (device control 4) byte.

Try it online!

The 0-indexed sequence to crack is [9, 19, 29].


2

><>, 276 bytes (Cracked)

1$1-:?!v$:      1[0$          >:?!va2[$:{:@%:{$-{,]v
       >$n; v              <  ^   >~{]02.1+1+ffr+1r<
 :}[r]{  [01>:{*@@+$a*l2=?!^~]+ff+9+1g"3"=?v"3"ff+9+1pf0.
 :}[l01-$>    $:0(?v$@$:@@:@)?v@@1-$}v     >"2"ff+9+1p00.
>.       ^-1l v!?} <  .4a}$@@$<   .4a<
^26{]r0[}:{]~{<

Try it online! Call this one with -v n to get the n-th element (1-indexed)

1$1-:?!;$::n84*o1[0$          >:?!va2[$:{:@%:{$-{,]v
            v              <  ^   >~{]02.1+1+ffr+1r<
 :}[r]{  [01>:{*@@+$a*l2=?!^~]+ff+9+1g"3"=?v"3"ff+9+1pf0.
 :}[l01-$>    $:0(?v$@$:@@:@)?v@@1-$}v     >"2"ff+9+1p00.
>.       ^-1l v!?} <  .4a}$@@$<   .4a<
^26{]r0[}:{]~{<

Try it online! Call with -v n to get a list of n-1 elements starting at 1

Online Fish Interpreter

A long and complex one, this is OEIS A004000.

Let a(n) = k, form m by Reversing the digits of k, Add m to k Then Sort the digits of the sum into increasing order to get a(n+1).

Example: 668 -> 668 + 866 = 1534 -> 1345.

Because the code in ><> is quite long, the challenge is to crack it for n=34. These 34 elements make a total of 290 bytes, just a bit too much to hardcode the result ;)
Here are the 34 first elements 1-indexed

1 2 4 8 16 77 145 668 1345 6677 13444 55778 133345 666677 1333444 5567777 12333445 66666677 133333444 556667777 1233334444 5566667777 12333334444 55666667777 123333334444 556666667777 1233333334444 5566666667777 12333333334444 55666666667777 123333333334444 556666666667777 1233333333334444 5566666666667777

How does one run the program to yield a single output for a given n (as required by the question)?
Jonathan Allan

As there are not really "functions" in fish, I added a version you can call to get the n-th (which is essentially the same, because it has to compute the n-1 previous elements)
crashoz

More importantly, do you have a crack that fits the same input indexing which yields the single output?
Jonathan Allan

1
I think so, I can do a function that does the same sequence for 1<=n<=34 but is different for n>34 while being ~30 bytes shorter
crashoz


2

Jelly, 6 bytes, Safe!

<4+ạ2ȯ

This defines a zero-indexed sequence where:

a(n)={1n<32n=3n2n>3

As such the first sixteen values a(0)a(15) are 1,1,1,2,2,3,4,5,6,7,8,9,10,11,12,13

Try it online! (here is a single value version)

This is not currently in the OEIS (although A34138 will work as a crack if short enough)

Intended Crack

The sequence above agrees with the count of decimal digits of the first 16 terms of A062569, the sum of the divisors of the factorial of n (also zero-indexed).
The 17th term of A062569, however, is 107004539285280 which has 15 digits, not 14=a(16).

The required code is five bytes in Jelly, !ÆsDL.


1

JavaScript, 26 bytes (Cracked)

let f=x=>x>1?f(x-1)*f(x-2)+1:1

for (x of [0,1,2,3,4,5,6,7]) {
  console.log(x + ' -> ' + f(x))
}

OEIS A007660

Output is the first 6 elements with 0 indexing (1,1,2,3,7,22)

(somewhat shifted from what OEIS has it listed as)

Just creating a simple to solve answer to kick things off

Try it online!



Your example snippet's output starts at 1, not at 0?
Paŭlo Ebermann

@PaŭloEbermann Fixed that
fəˈnɛtɪk






0

><>, 42 bytes, cracked

i3%0v
642 .
840
789
159
a 1
v<<
n
l
?
\/
;

Try it online!

Sequence to crack (0-indexed): 101786, 5844, 19902 (not on OEIS).

Intended solution, for reference.



Usually the robbers should be hard coding the output
Jo King

@JoKing Your crack doesn't seem to produce any values different from mine (or maybe I haven't tested it thoroughly enough to find which values differ), but that's probably easily rectifiable. While there doesn't seem to be anything in the rules forbidding hardcoding, I agree that it may not fit the spirit of the challenge -- in any case you've demonstrated that hardcoding (for a cop) comes with its own risks.
Aidan F. Pierce

1
I've updated my answer to produce a different value for 4
Jo King

0

Perl 6, 53 bytes

{(1,2,2,{$!=++$;prepend(@,2-$!%2 xx$_).pop}...*)[$_]}

Try it online!

Anonymous code-block that returns the 0-indexed Kolakoski sequence (OEIS A000002). Solutions are required to match the first 130 elements, so that for some n > 129 it differs from the Kolakoski sequence.


0

Pascal (FPC), 86 bytes (cracked)

var n:word;begin read(n);write(n div 2+n div 4+n div 8+n div 16+n div 32+n div 64)end.

Try it online!

The sequence must be equal up to n=120. The sequence from input 0 to input 120 is

0   0   1   1   3   3   4   4   7   7   8   8  10  10  11  11  15  15  16  16  18  18  19  19  22  22  23  23  25  25  26  26  31  31  32  32  34  34  35  35  38  38  39  39  41  41  42  42  46  46  47  47  49  49  50  50  53  53  54  54  56  56  57  57  63  63  64  64  66  66  67  67  70  70  71  71  73  73  74  74  78  78  79  79  81  81  82  82  85  85  86  86  88  88  89  89  94  94  95  95  97  97  98  98 101 101 102 102 104 104 105 105 109 109 110 110 112 112 113 113 116


My original solution was

var n,i,s:word;begin read(n);i:=2;repeat s:=s+n div i;i:=i*2until i>n;write(s)end.

but r_64 made it even better!


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.