30
\$\begingroup\$

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.

\$\endgroup\$
8
  • \$\begingroup\$ 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?) \$\endgroup\$ Commented Jun 29, 2018 at 17:56
  • 2
    \$\begingroup\$ @theReallyumdub the question stipulates you must be able to crack your own submission. \$\endgroup\$
    – Wheat Wizard
    Commented Jun 29, 2018 at 18:02
  • \$\begingroup\$ @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 \$\endgroup\$ Commented Jun 29, 2018 at 18:12
  • 4
    \$\begingroup\$ spikedmath.com/062.html \$\endgroup\$
    – Giuseppe
    Commented Jun 29, 2018 at 20:35
  • \$\begingroup\$ Is there a "although theorically your solution must work for all numbers in practice it only need to work for ..." condition? \$\endgroup\$
    – user202729
    Commented Jun 30, 2018 at 1:54

18 Answers 18

6
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Cracked. \$\endgroup\$
    – Bubbler
    Commented Jun 30, 2018 at 7:08
5
\$\begingroup\$

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]
\$\endgroup\$
3
  • \$\begingroup\$ I forgot to remove the whitespace, I'm not an expert golfer yet :p Do you mind if I edit to fix that ? \$\endgroup\$
    – crashoz
    Commented Jun 29, 2018 at 20:08
  • \$\begingroup\$ Sure go ahead. I'll remove my crack. \$\endgroup\$
    – Wheat Wizard
    Commented Jun 29, 2018 at 20:16
  • \$\begingroup\$ Cracked \$\endgroup\$
    – xnor
    Commented Jun 30, 2018 at 6:49
5
\$\begingroup\$

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.

\$\endgroup\$
8
  • \$\begingroup\$ 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? \$\endgroup\$ Commented Jul 1, 2018 at 11:05
  • \$\begingroup\$ @JonathanAllan Thanks, I edited that there's no 3rd party libraries. \$\endgroup\$
    – xnor
    Commented Jul 1, 2018 at 19:31
  • \$\begingroup\$ 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 :) \$\endgroup\$
    – Mr. Xcoder
    Commented Jul 2, 2018 at 5:55
  • \$\begingroup\$ @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...) \$\endgroup\$
    – Arnauld
    Commented Jul 3, 2018 at 7:19
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Commented Jul 4, 2018 at 21:17
4
\$\begingroup\$

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^#]&

\$\endgroup\$
0
3
\$\begingroup\$

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

\$\endgroup\$
6
  • \$\begingroup\$ cracked \$\endgroup\$ Commented Jun 30, 2018 at 13:54
  • \$\begingroup\$ @Laikoni, if the intended crack is shorter, then someone else could potentially claim the robber from BMO. \$\endgroup\$ Commented Jul 1, 2018 at 0:07
  • \$\begingroup\$ @fəˈnɛtɪk Thanks, I was not aware of this rule. \$\endgroup\$
    – Laikoni
    Commented Jul 1, 2018 at 19:09
  • \$\begingroup\$ @BMO re-cracked \$\endgroup\$ Commented Jul 2, 2018 at 7:27
  • 2
    \$\begingroup\$ @BMO There you go :) \$\endgroup\$
    – Laikoni
    Commented Jul 2, 2018 at 17:46
2
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ n=>8*n*n+n differs for n=94906273, is this a valid crack? \$\endgroup\$
    – ngn
    Commented Jun 30, 2018 at 11:32
  • \$\begingroup\$ @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. \$\endgroup\$
    – Arnauld
    Commented Jun 30, 2018 at 11:57
  • \$\begingroup\$ @CatWizard ^­­­ \$\endgroup\$
    – ngn
    Commented Jun 30, 2018 at 13:05
  • \$\begingroup\$ I'd say it is a valid crack. \$\endgroup\$
    – Wheat Wizard
    Commented Jun 30, 2018 at 13:21
  • 2
    \$\begingroup\$ cracked (| instead of +) \$\endgroup\$
    – ngn
    Commented Jun 30, 2018 at 13:51
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

><>, 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
\$\endgroup\$
5
  • \$\begingroup\$ How does one run the program to yield a single output for a given n (as required by the question)? \$\endgroup\$ Commented Jun 30, 2018 at 17:22
  • \$\begingroup\$ 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) \$\endgroup\$
    – crashoz
    Commented Jun 30, 2018 at 17:54
  • \$\begingroup\$ More importantly, do you have a crack that fits the same input indexing which yields the single output? \$\endgroup\$ Commented Jun 30, 2018 at 18:03
  • 1
    \$\begingroup\$ 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 \$\endgroup\$
    – crashoz
    Commented Jun 30, 2018 at 21:18
  • \$\begingroup\$ Cracked \$\endgroup\$
    – Jo King
    Commented Jul 1, 2018 at 7:30
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

APL (Dyalog Unicode), 17 15 bytes, safe

⌈∊∘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.


The intended code is the following:

APL (Dyalog Unicode), 10 bytes

⌊(2*⍳)⌹⌽∘⍳

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ cracked \$\endgroup\$
    – ngn
    Commented Jun 30, 2018 at 10:59
  • \$\begingroup\$ @ngn Updated the cop submission :) \$\endgroup\$
    – Bubbler
    Commented Jun 30, 2018 at 12:12
1
\$\begingroup\$

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!

\$\endgroup\$
3
  • \$\begingroup\$ Cracked. \$\endgroup\$
    – Mr. Xcoder
    Commented Jun 29, 2018 at 18:00
  • \$\begingroup\$ Your example snippet's output starts at 1, not at 0? \$\endgroup\$ Commented Jun 29, 2018 at 21:23
  • \$\begingroup\$ @PaŭloEbermann Fixed that \$\endgroup\$ Commented Jun 29, 2018 at 21:28
1
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ Cracked \$\endgroup\$
    – Mr. Xcoder
    Commented Jun 29, 2018 at 21:36
1
\$\begingroup\$

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Σ

\$\endgroup\$
1
1
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ Cracked \$\endgroup\$
    – Arnauld
    Commented Jun 30, 2018 at 19:15
0
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ Cracked. \$\endgroup\$
    – Mr. Xcoder
    Commented Jun 29, 2018 at 21:56
0
\$\begingroup\$

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

\$\endgroup\$
4
  • \$\begingroup\$ Cracked \$\endgroup\$
    – Jo King
    Commented Jul 4, 2018 at 15:23
  • \$\begingroup\$ Usually the robbers should be hard coding the output \$\endgroup\$
    – Jo King
    Commented Jul 4, 2018 at 15:30
  • \$\begingroup\$ @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. \$\endgroup\$
    – praosylen
    Commented Jul 4, 2018 at 15:52
  • 1
    \$\begingroup\$ I've updated my answer to produce a different value for 4 \$\endgroup\$
    – Jo King
    Commented Jul 4, 2018 at 21:33
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.