# Change the Code, Change the Sequence: Cops

This is a challenge. For the robbers thread, go here.

This challenge involves two OEIS sequences chosen by the cops -- S1, S2 -- and how well those sequences can be golfed and obfuscated.

### The Cops' Challenge

Your challenge as a cop is to pick a freely available language, and two OEIS sequences. Then, write code A in that language that takes input n and produces S1(n). When that code is modified by a Levenshtein distance of X characters (with X no more than 0.5 * (length A)), and turned into code B in the same language, it must then produce S2(n). You must actually write this code B, but don't reveal it until your challenge is safe (see below).

The cops' submissions must include the language name, the full code A, the byte-count of A, the X value of how many changes to get to their secret B code, and the chosen S1 and S2 sequence numbers. You can choose whether each sequence is 0-indexed or 1-indexed, but please specify that in your submission.

To crack a particular submission, robbers must come up with a program C in the same language (and version) that produces S2(n) and is Y character changes away from A (with Y <= X). Robbers do not necessarily need to find the exact same B code that the cop (secretly) produced.

### Winning and Scoring

Cops win by having the uncracked submission with the shortest A. If tied, then the smallest X will be used as tie-breaker. If still tied, the earlier submission will win.

### Further Rules

• You must not use any built-ins for hashing, encryption, or random number generation (even if you seed the random number generator to a fixed value).
• Either programs or functions are allowed, but the code must not be a snippet and you must not assume a REPL environment.
• You may take input and give output in any convenient format. The input/output methods must be the same for both sequences.
• The definitive calculator for the Levenshtein distance for this challenge is this one on Planet Calc.
• In addition to being a CnR challenge, this is so all usual golfing rules apply.
• Also, make sure if you change something in this question, that you update the robbers one. – mbomb007 Feb 13 '17 at 17:36
• What if a cop names a function/variable really big with respect to the actual code generating the sequence? It'll be possible to create any sequence in this case with its lev distance being less that (0.5*len(A)) – hashcode55 Feb 13 '17 at 17:38
• @hashcode55 Two things -- 1) that's not likely going to be a good candidate for winning the cops' thread. 2) if it's enormous like that, it also gives a good leeway for the robbers to crack it. – AdmBorkBork Feb 13 '17 at 17:40
• "this is code-golf so all usual golfing rules apply" Does this mean that code A must be golfed as much as possible, or can it be intentionally written in a too verbose/awkward way to make it more similar to code B? – smls Feb 13 '17 at 18:05
• Search un-cracked answers – mbomb007 Feb 13 '17 at 23:02

# Brain-Flak, 28 bytes, Distance of 4, A002817, A090809Cracked

(({({}[()])}{}){({}[()])}{})


Try it online

For anyone interested there are 27475 valid Brain-Flak programs with Levenshtein distance 4 from this program and 27707 with distance 4 or less. So a brute force solution would be feasible on a consumer grade computer.

• It'd probably be shorter and quicker to read if you have X = 4 instead of Levenshtein distance of 4. – mbomb007 Feb 13 '17 at 19:17
• @mbomb007 I personally get a bit confused when challenges use a bunch of letter variables to stand in for things I was trying to avoid confusion. I have made it shorter now, hopefully without causing any confusion. – Wheat Wizard Feb 13 '17 at 19:19
• shrug. If everyone read the question, they should get it. X is really the only variable they need to know. – mbomb007 Feb 13 '17 at 19:20
• @mbomb007 Although, the question also asks for a byte count. – DLosc Feb 14 '17 at 4:13
• Cracked! – James Feb 19 '17 at 7:31

# 7, 33 characters, 13 bytes, X = 10, A000124 → A000142, Safe

171720514057071616777023671335133


Try it online!

The Levenshtein distance is measured in terms of characters, so I've written the program in terms of the characters it contains above (and Try it online!, including the language itself, is happy to run programs encoded in ASCII). However, the program is stored in disk using 7's sub-byte encoding, meaning that the program itself is actually the following hexdump (thus 13 bytes long):

00000000: 3cf4 2982 f1ce 3bfe 13dc b74b 7f         <.)...;....K.


(Because the Levenshtein distance is measured in terms of characters, you aren't necessarily adding/deleting/changing 10 bytes here, so it's probably best to work with the original ASCII.)

The program as written implements A000124 (triangular numbers + 1); any crack must implement A000142 (factorials). Both programs take input from stdin (as decimal integers), write their output to stdout, and treat an input of 1 as meaning the first element of the sequence (and an input of 2 as the second element, etc.).

Hopefully the very high X value will stop people brute-forcing the program, this time (which is always a risk with cops-and-robbers entries in 7).

## The solution

177172051772664057074056167770236713351353


Try it online!

Differences from the original:

17 172051     405707 1 61677702367133513 3
177172051772664057074056167770236713351353


I don't have explanations prepared for how these work, so it's going to take me a while to get an explanation up, as I'm going to have to figure it out from almost-scratch. Hopefully there will be an explanation eventually.

## Pyke, Levenshtein distance of 1, A036487, A135628.

### Cracked!

X*e


Try it here!

# Perl 6, 10 bytes, X = 1, A000012 → A001477

### Cracked!

*[0]o 1***

• S1 = A000012 = 1,1,1,1,1,... = The all 1's sequence. (0-indexed)

• S2 = A001477 = 0,1,2,3,4,... = The nonnegative integers. (0-indexed)

Try it online!

Confirmed to work with Perl 6 release 2017.01, and with the Perl6 version running on TIO.

(A could be further golfed to 1*** – I hope it it's also allowed as it is.)

# Perl 6, 13 bytes, X = 1, A161680 → A000217

{[+] [,] ^$_}  • S1 = A161680 = 0 0 1 3 6 10 15 21... = Zero followed by the triangular numbers. • S2 = A000217 = 0 1 3 6 10 15 21 28 ... = The triangular numbers. • Zero-indexed. Try it online! (Confirmed to work with the Perl 6 version running on TIO.) ### Solution {[+] [\,] ^$_}


How the original works:

{           }  # A lambda.
$_ # Lambda argument. e.g. 4 ^ # Range from 0 to n-1. e.g. 0, 1, 2, 3 [,] # Reduce with comma operator. e.g. 0, 1, 2, 3 [+] # Reduce with addition operator. e.g. 6  How the solution works: { } # A lambda.$_  # Lambda argument.                     e.g. 4
^    # Range from 0 to n-1.                 e.g. 0, 1, 2, 3
[\,]      # Triangle reduce with comma operator. e.g. (0), (0,1), (0,1,2), (0,1,2,3)
[+]           # Reduce with addition operator.       e.g. 10


Exploits the fact that numeric operators like addition treat a list as its number of elements, so in the example the sum is 1 + 2 + 3 + 4 = 10.

And yeah, the "Reduce with comma operator" no-op in the original is kinda skirting the code-golf rules, but I prefer to look at it as a silly algorithm which has been golfed as much as possible (whitespace etc.) for what it is... :)

• This is begging to be brute forced, if I had the time or the inclination (and the knowledge of perl). – Rohan Jhunjhunwala Feb 19 '17 at 1:53
• This has survived long enough to be marked as safe – fəˈnɛtɪk Feb 21 '17 at 14:13

# Jelly, 11 bytes, X = 5, A005185 → A116881

ịḣ2S;
1Ç¡ḊḢ


This is a full program that takes an integer as command-line argument and prints an integer.

Both sequences are indexed as on OEIS, i.e, A005185 is 1-indexed and A116881 is 0-indexed.

Try it online!

## Javascript, 41 bytes, Distance of 3, A061313, A004526, Cracked

f=x=>{return x>1?x%2?f(x+1)+1:f(x/2)+1:0}


Try it Online

Uses 1 based indexing, solution uses 0 based indexing.

Once again, a different solution...

f=x=>{return x>1?x<2?f(x-1)+1:f(x-2)+1:0}

• Cracked. – Dennis Feb 13 '17 at 21:25
• By the way, you shouldn't use tio.run permalinks. They will stop working soon. – Dennis Feb 13 '17 at 21:26
• ^ Use tio.run/nexus instead. – mbomb007 Feb 13 '17 at 22:56

# Perl 6, 19 bytes, X = 1, A000045 → A000035

### Cracked!

{(0,1,*+*...*)[\$_]}

• S1 = A000045 = 0 1 1 2 3 5 8 13 21 34... = "Fibonacci numbers". (0-indexed)
• S2 = A000035 = 0 1 0 1 0 1 0 1 0 1... = "Period 2". (0-indexed)

Try it online!

(Confirmed to work with the Perl 6 version running on TIO.)

• Cracked. – Dennis Feb 14 '17 at 5:52

# WolframAlpha, 18 bytes, X = 1

Cracked by math_junkie!

(sum1to#of n^1)*2&


Sometimes WolframAlpha will actually be able to display a pure function like this in functional form (other times it gets confused); but it can be cheerfully invoked with a given input—for example, (sum1to#of n^1)*2&@5 yields 30.

S1 = A002378 (pronic numbers)

S2 = A000537 (sum of the first n cubes)

Both sequences are 0-indexed.

## Pyke, Levenshtein distance of 2, A008788, A007526

### Cracked!

'th^


Try it here!

Let's get slightly harder shall we?

The first answer is 1 based and the crack is 0 based.

• Cracked. – Dennis Feb 14 '17 at 21:20

# Javascript, 15704 bytes, distance of 2, A059841 and A000004 - cracked

This solution is extremely long, so you can find the full code at this github gist.

The original answer (this one) is 1 indexed. (I know this is way too long, it is just for fun.)

• Cracked. Also, adding absolutely useless code !+[]-(!+[]) isn't really in the spirit of the rules – fəˈnɛtɪk Feb 14 '17 at 20:59
• Just so you know, this answer is causing some issues for the OP of this challenge. Apparently it causes the whole page to be blocked because it looks like sketchy JavaScript. Could you maybe put the code in an external link? (Gist, pastedump, etc) – James Feb 14 '17 at 21:44
• Actually, I've put it in a gist myself. If you would rather have the code somewhere else, feel free to edit it again if I've overstepped my bounds. – James Feb 14 '17 at 21:50
• I guess that the !+[]-(!+[]) does make it so that you can't just reverse the conversion. But some of the other garbage just makes it longer. The equivalent code is only 15640 bytes. – fəˈnɛtɪk Feb 14 '17 at 21:53

# Brain-Flak, 16 bytes, Levenshtein distance of 4, A000217 and A002378 -- Cracked by Martin Ender!

({({}[()])()}{})


Try it online!

This should be fairly easy to crack.

• Cracked. – Martin Ender Feb 14 '17 at 23:05
• @WheatWizard Oh, whoops, I didn't realize I forgot too. – James Feb 16 '17 at 20:41

## Javascript, 30 bytes, Distance of 4, A000290, A000079, -Cracked!

f=x=>{return x?2*x-1+f(x-1):0}


0-based indexing

@Kritixi Lithos's solution was actually different from mine

f=x=>{return x?f(x-1)+f(x-1):1}


Try it online

• This is x**2 and not 2**x – user41805 Feb 13 '17 at 19:54
• I think it's A000290, not A000079. – betseg Feb 13 '17 at 19:55
• @KritixiLithos it is supposed to be both. I changed the wrong sequence link on the top when I changed the other end. – fəˈnɛtɪk Feb 13 '17 at 20:00
• Cracked – user41805 Feb 13 '17 at 20:05

# Javascript (ES6), distance is 1, A000079 and A000004 - cracked

as=function(){ return 2*2**((11)*-1*~arguments[0]/11-(4-(as+[]).length%89))-(as+[]).length%7}


The original answer (this one) is 0 based. Now that it has been cracked, here is the original B function:

as=function(){ return 2*2**((1^1)*-1*~arguments[0]/11-(4-(as+[]).length%89))-(as+[]).length%7}


# Perl 6, 7 bytes, X = 2, A059841 → A001477

### Cracked!

+(*%%2)

• S1 = A059841 = 1 0 1 0 1 0 1 0... = "*Period 2: Repeat (1,0)". (0-indexed)
• S2 = A001477 = 0 1 2 3 4 5 6 7... = "The nonnegative integers". (0-indexed)

Try it online!

(Confirmed to work with the Perl 6 version running on TIO.)

# Java 7, Levenshtein distance of 4, A094683, A000290, Cracked

int x{double r=1;for(int i=0;i<42;i++)r=r/2+n/r/2;int k=(int)((int)n*(float)n/Math.pow(n,(Math.sin(n)*Math.sin(n)+Math.cos(n)*Math.cos(n))/2));return n%4%2==(int)Math.log10(Math.E)/Math.log((double)'H'-'@')?(int)r:k;}


0-indexed.
Try it here!

• @LliwTelracs did that for the first 15 non-negative integers, see my updated answer. – peech Feb 14 '17 at 16:29
• Cracked – fəˈnɛtɪk Feb 14 '17 at 17:03