Hardcoding the Cops and Robbers (Cops)

28

4

This is a challenge. The robbers' thread is here.

An interesting question to think about is the following:

If I have a sequence of numbers how many of them do I have to provide before it is clear what sequence I am talking about?

For example if I want to talk about the positive integers in order starting from \$1\$, I could say \$1,2,3, \dots\$, but is that really enough?

I have one way of answering this question, and being a code-golfer it involves code-golf. You have provided enough terms of a sequence if the shortest code that produces those terms produces all the terms of the sequence. If we think about this in terms of code-golf, this would mean you have provided enough test cases such that the shortest code that passes the test-cases does the desired task.

Challenge

This challenge is a challenge. In which cops will be presenting test-cases and robbers will have to find a shorter way to spoof the test-cases other than the intended sequence. Cops will present the following things:

  • A piece of code that takes a non-negative integer as input and produces an integer as output. This code will define your sequence. Your code does not need to support 0 as an input, opting to instead take 1 as the smallest input. It should be clear if this is the case in your answer.

  • Any relevant platform or language requirements that might affect the output, for example the size of longint.

  • A number \$n\$, along with the first \$n\$ terms of the sequence as calculated by the code. These will act as "test-cases".

You are encouraged to explain what your sequence does and link OEIS if it exists, however it is your code that defines the sequence not the description.

Robbers will be finding a program in the same language that is shorter than the one presented and passes all the test cases (produces the same output for the first \$n\$ inputs as the cop's code). The robber's code must also differ in output from the cop's program for some number larger than \$n\$.

Cops must be able to crack their own answers before submitting them.

After one week a cop may reveal their crack and mark their answer as Safe. Answers marked as such can no longer be cracked.

Scoring

Cops answers will be scored by the number of bytes with fewer bytes being better. Cracked answers score an infinite score.

Post Rock Garf Hunter

Posted 2018-06-29T15:07:41.120

Reputation: 55 382

It's clear there are ways to un-mathematically crack a problem, like just printing all the test cases, but that issue is conditional on the cops' provided cases. Should there be a rule about that? Is there a restriction against computability of the sequences or anything from Ramsey Theory? (i.e. do you need to be able to crack on your machine?) – theREALyumdub – 2018-06-29T17:56:46.530

2@theReallyumdub the question stipulates you must be able to crack your own submission. – Post Rock Garf Hunter – 2018-06-29T18:02:36.053

@CatWizard Thanks, I went ahead and that's already on an obvious meta post, it impedes some of these guys apparently. So it isn't in the spirit of the tag to make a crack take over an hour to compute or something – theREALyumdub – 2018-06-29T18:12:45.707

4http://spikedmath.com/062.html – Giuseppe – 2018-06-29T20:35:49.800

Is there a "although theorically your solution must work for all numbers in practice it only need to work for ..." condition? – user202729 – 2018-06-30T01:54:09.127

@user202729 No there is not. You're sequence is defined simply by how your code works so if it diverges from whatever sequence you might intend to model because of the innacurracy of floating point numbers than that is that. The sequence is what your code outputs. – Post Rock Garf Hunter – 2018-06-30T02:55:45.450

Can the code use unary for I/O, or does it have to be decimal? – DLosc – 2018-06-30T05:16:08.083

@DLosc I'm just going to defer to the standard methods of IO. I believe that unary is allowed in some cases. – Post Rock Garf Hunter – 2018-06-30T14:46:30.767

Answers

6

cQuents, 4 bytes (Cracked)

"::$

Try it online!

Here are eight (n=8) cases:

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

Code explanation:

"      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

So the sequence is 1,2,3,4,5 ..., it is joined on "" so it becomes 12345 ..., and :: means that it prints up to the input.

Stephen

Posted 2018-06-29T15:07:41.120

Reputation: 12 293

Cracked. – Bubbler – 2018-06-30T07:08:54.827

5

Python 3, 66 57 bytes (Cracked)

cracked by xnor
also cracked by Cat Wizard before an edit

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

Try it online!

Hello! Here is a sequence to crack for \$n=40\$. It gives these first 40 elements with 0-indexing, it's not an OEIS sequence

[-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]

crashoz

Posted 2018-06-29T15:07:41.120

Reputation: 611

I forgot to remove the whitespace, I'm not an expert golfer yet :p Do you mind if I edit to fix that ? – crashoz – 2018-06-29T20:08:26.557

Sure go ahead. I'll remove my crack. – Post Rock Garf Hunter – 2018-06-29T20:16:13.103

Cracked – xnor – 2018-06-30T06:49:19.977

5

Python 2, 44 bytes (cracked)

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

Try it online!

The prime numbers. What sequence could be purer? Or more overdone? Your goal is to produce the first 50 primes for n=1 to n=50.

The code is a Wilson's Theorem generator copied exactly from this tip.

The different values for the alternative sequence are not due to machine limitations like overflows and precision. No 3rd party libraries.


Cracked by Arnauld, @PoonLevi, and Mr. Xcoder.

xnor

Posted 2018-06-29T15:07:41.120

Reputation: 115 687

Pretty sure you did not mean to get cracked by this; maybe specify "Python (with no 3rd party libraries)" or "Python (with no imports)" or something?

– Jonathan Allan – 2018-07-01T11:05:29.110

@JonathanAllan Thanks, I edited that there's no 3rd party libraries. – xnor – 2018-07-01T19:31:40.050

I haven't been able to crack this yet (my best attempt at the moment is 47 bytes or so), but I think there's something interesting to note about those particular primes. For each $p_i$, with $i\in[1, 50]\cap \mathbb{N}$, this holds: $2^{p_i}\equiv 2 (\text{mod } p_i)$. At the same time, this isn't true for any number which is not prime (in the range noted above), but it does so for higher values. I'm leaving this idea here so that others may try their hand at a crack using the mentioned technique, and perhaps obtain a better score :) – Mr. Xcoder – 2018-07-02T05:55:43.450

@Mr.Xcoder Here is my best attempt based on your proposed method. It successfully diverges at N=69, returning 341 (the first Fermat pseudoprime to base 2, or first Poulet number) but it also fails for N=1. I doubt I can fix it on my own, so I thought I'd better share what I have. (My best fix is 46 bytes...)

– Arnauld – 2018-07-03T07:19:18.807

1

@Arnauld I found a 44-byte solution using this method. I can't seem to go any further. Maybe someone else will be able to figure this out.

– Poon Levi – 2018-07-04T21:17:10.597

@PoonLevi Nicely done! By rearranging it some more, here is a 43-byte crack.

– Arnauld – 2018-07-04T23:19:51.390

Now, since it was a team work, I'm not sure how the crack should be posted. – Arnauld – 2018-07-04T23:25:08.923

I went ahead and posted this crack.

– Arnauld – 2018-07-05T08:45:42.553

4

Wolfram Language (Mathematica), 39 34 bytes (Safe)

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

Try it online!

Looks simple, solution should be hard.

1-indexed and \$n = 99\$. This sequence is not available on the OEIS.

{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}

This above list is equal to:

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

Here's a template for checking your solution: Try it online!

Intended Crack

The catch here is that the output increases by 1 when the number of digit increases by 1, with the exception for the first three terms; the intended solution has something to do with string conversion.

Hence, reading the documentation on Converting between Expressions & String, one could find the function SpokenString.

The solution is simply the length of the spoken-string version of the expression x^n for various inputs: StringLength@SpokenString[x^#]&

JungHwan Min

Posted 2018-06-29T15:07:41.120

Reputation: 13 290

3

Haskell, 29 bytes (Cracked: 1,2)

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

Try it online!

This is A093005: \$ a(n)=n\lceil \frac{n}{2} \rceil\$.

Test cases for \$0 \leq n \leq 20 \$, that is map a [0..20]:

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

Intended solution (20 bytes)

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

Try it online! Differs at \$ n=23 \$, with \$ a(23) = 276 \$ and \$ b(23) = 253\$.

This function is equivalent to \$b(n) = n\ len(3^n) = n \lceil log_{10}(1+3^n)\rceil\$. Thanks to the ceiling, both functions overlap for integer arguments in the range from \$0\$ to \$22\$:

source

Laikoni

Posted 2018-06-29T15:07:41.120

Reputation: 23 676

cracked – ბიმო – 2018-06-30T13:54:31.187

@Laikoni, if the intended crack is shorter, then someone else could potentially claim the robber from BMO. – fəˈnɛtɪk – 2018-07-01T00:07:14.020

@fəˈnɛtɪk Thanks, I was not aware of this rule. – Laikoni – 2018-07-01T19:09:10.107

@BMO re-cracked

– Ørjan Johansen – 2018-07-02T07:27:35.253

Given that @ØrjanJohansen was able to beat 20 bytes and I failed to find the other solution, you could reveal it now (I'm really interested) :) – ბიმო – 2018-07-02T12:32:57.170

2@BMO There you go :) – Laikoni – 2018-07-02T17:46:25.927

2

JavaScript (ES6), 12 bytes (Cracked)

This one is rather easy.

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

Try it online!

This is A139275:

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

Your code must support \$0\le n<9\$:

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

And as per the challenge rules, it must diverge beyond.

Arnauld

Posted 2018-06-29T15:07:41.120

Reputation: 111 334

n=>8*n*n+n differs for n=94906273, is this a valid crack? – ngn – 2018-06-30T11:32:52.197

@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 – 2018-06-30T11:57:18.390

@CatWizard ^­­­ – ngn – 2018-06-30T13:05:14.493

I'd say it is a valid crack. – Post Rock Garf Hunter – 2018-06-30T13:21:27.670

2cracked (| instead of +) – ngn – 2018-06-30T13:51:12.753

2

Jelly, 6 bytes, Safe!

<4+ạ2ȯ

This defines a zero-indexed sequence where:

$$ a(n) = \begin{cases} 1 & n<3 \\ 2 & n=3 \\ n-2 & n>3 \end{cases}$$

As such the first sixteen values \$a(0)\cdots 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 \$17^{\text{th}}\$ term of A062569, however, is \$107004539285280\$ which has \$15\$ digits, not \$14=a(16)\$.

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

Jonathan Allan

Posted 2018-06-29T15:07:41.120

Reputation: 67 804

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

crashoz

Posted 2018-06-29T15:07:41.120

Reputation: 611

How does one run the program to yield a single output for a given n (as required by the question)? – Jonathan Allan – 2018-06-30T17:22:02.937

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 – 2018-06-30T17:54:49.870

More importantly, do you have a crack that fits the same input indexing which yields the single output? – Jonathan Allan – 2018-06-30T18:03:32.517

1I 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 – 2018-06-30T21:18:15.060

Cracked – Jo King – 2018-07-01T07:30:22.113

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].

Doorknob

Posted 2018-06-29T15:07:41.120

Reputation: 68 138

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!

fəˈnɛtɪk

Posted 2018-06-29T15:07:41.120

Reputation: 4 166

Cracked. – Mr. Xcoder – 2018-06-29T18:00:01.580

Your example snippet's output starts at 1, not at 0? – Paŭlo Ebermann – 2018-06-29T21:23:59.297

@PaŭloEbermann Fixed that – fəˈnɛtɪk – 2018-06-29T21:28:38.920

1

JavaScript, 16 bytes (Cracked)

g=
x=>Math.exp(x)|0

tmp=[0,1,2,3,4]
console.log(tmp.map(g).join(','))

First 5 elements of OEIS149 (\$\lfloor e^n\rfloor\$)

Required inputs to match are 0,1,2,3,4.

Try it online!

fəˈnɛtɪk

Posted 2018-06-29T15:07:41.120

Reputation: 4 166

Cracked – Mr. Xcoder – 2018-06-29T21:36:50.243

1

APL (Dyalog Unicode), 17 15 bytes

⌈∊∘1 5+.633*5-⊢

Try it online!

The first 13 terms (1-based) are:

2 1 1 1 2 2 3 4 7 10 16 25 39

Hint: The intended solution uses one of the least used built-in functions.

Bubbler

Posted 2018-06-29T15:07:41.120

Reputation: 16 616

cracked – ngn – 2018-06-30T10:59:07.013

@ngn Updated the cop submission :) – Bubbler – 2018-06-30T12:12:05.057

1

Husk, 5 bytes (cracked by Jonathan Allan)

This one is A000030 shifted by \$16\$:

←d+16

Try it online!

The sequence is 0-indexed, output for \$ 0 \leq n < 23 \$:

$$ 1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3 $$

Explanation

←d+16  -- example input:  23
  +16  -- add 16:         39
 d     -- digits:         [3,9]
←      -- extract first:  3

Solution

LdΣ

ბიმო

Posted 2018-06-29T15:07:41.120

Reputation: 15 345

cracked – Jonathan Allan – 2018-06-30T16:30:08.320

1

JavaScript, 25 bytes (Cracked 21 bytes)

f=
x=>[7,11,12,13,13][x]||14

for(i=0;i<15;i++)
  console.log(i+"->"+f(i))

Sequence of 7,11,12,13,13 followed by infinite 14s.

Intended solution 22 bytes:

x=Math.atan(x+1)*10|0

Try it online!

fəˈnɛtɪk

Posted 2018-06-29T15:07:41.120

Reputation: 4 166

Cracked – Arnauld – 2018-06-30T19:15:41.583

0

JavaScript, 22 bytes (Cracked)

f=
x=>(3-(5/63)**.5)**x|1

for(y=0;y<16;y++)
  console.log(y +"->"+f(y))

This is 0 indexed and accuracy is required up to an input of 15. It can not be found on OEIS

My solution 20 bytes

x=>163**(32*x/163)|1

Try it online!

fəˈnɛtɪk

Posted 2018-06-29T15:07:41.120

Reputation: 4 166

Cracked. – Mr. Xcoder – 2018-06-29T21:56:48.260

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.

Aidan F. Pierce

Posted 2018-06-29T15:07:41.120

Reputation: 1 365

Cracked – Jo King – 2018-07-04T15:23:26.557

Usually the robbers should be hard coding the output – Jo King – 2018-07-04T15:30:06.603

@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 – 2018-07-04T15:52:14.937

1I've updated my answer to produce a different value for 4 – Jo King – 2018-07-04T21:33:33.550

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!

AlexRacer

Posted 2018-06-29T15:07:41.120

Reputation: 979

cracked – Post Rock Garf Hunter – 2018-08-18T14:32:45.370

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.

Jo King

Posted 2018-06-29T15:07:41.120

Reputation: 38 234