This is a cops-and-robbers 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
If your cop answer has not been cracked within 7 days (168 hours), you may reveal your own B solution, at which point your answer is considered safe. As long as you don't reveal your solution, it may still be cracked by robbers, even if the 7 days have already passed. If your answer does get cracked, please indicate this in the header of your answer, along with a link to the corresponding robber's answer.
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 code-golf so all usual golfing rules apply.
16 Answers 16
(削除) Brain-Flak, 28 bytes, Distance of 4, A002817, A090809 (削除ここまで) Cracked
This answer uses 1-indexing
(({({}[()])}{}){({}[()])}{})
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.
-
\$\begingroup\$ It'd probably be shorter and quicker to read if you have
X = 4
instead ofLevenshtein distance of 4
. \$\endgroup\$mbomb007– mbomb0072017年02月13日 19:17:38 +00:00Commented Feb 13, 2017 at 19:17 -
1\$\begingroup\$ @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. \$\endgroup\$2017年02月13日 19:19:49 +00:00Commented Feb 13, 2017 at 19:19
-
\$\begingroup\$ shrug. If everyone read the question, they should get it.
X
is really the only variable they need to know. \$\endgroup\$mbomb007– mbomb0072017年02月13日 19:20:38 +00:00Commented Feb 13, 2017 at 19:20 -
\$\begingroup\$ @mbomb007 Although, the question also asks for a byte count. \$\endgroup\$DLosc– DLosc2017年02月14日 04:13:05 +00:00Commented Feb 14, 2017 at 4:13
-
1\$\begingroup\$ Cracked! \$\endgroup\$DJMcMayhem– DJMcMayhem2017年02月19日 07:31:24 +00:00Commented Feb 19, 2017 at 7:31
7, 33 characters, 13 bytes, X = 10, A000124 → A000142, Safe
171720514057071616777023671335133
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
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.
(削除)
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)
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
(削除ここまで)
Safe!
{[+] [,] ^$_}
- 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.
(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... :)
-
\$\begingroup\$ This is begging to be brute forced, if I had the time or the inclination (and the knowledge of perl). \$\endgroup\$Rohan Jhunjhunwala– Rohan Jhunjhunwala2017年02月19日 01:53:14 +00:00Commented Feb 19, 2017 at 1:53
-
\$\begingroup\$ This has survived long enough to be marked as safe \$\endgroup\$fəˈnɛtɪk– fəˈnɛtɪk2017年02月21日 14:13:07 +00:00Commented Feb 21, 2017 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.
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}
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}
-
-
3
-
\$\begingroup\$ ^ Use tio.run/nexus instead. \$\endgroup\$mbomb007– mbomb0072017年02月13日 22:56:32 +00:00Commented Feb 13, 2017 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)
(Confirmed to work with the Perl 6 version running on TIO.)
(削除) WolframAlpha, 18 bytes, X = 1 (削除ここまで)
(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.
-
\$\begingroup\$ Cracked! \$\endgroup\$math junkie– math junkie2017年02月14日 19:12:49 +00:00Commented Feb 14, 2017 at 19:12
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.)
-
-
\$\begingroup\$ 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) \$\endgroup\$DJMcMayhem– DJMcMayhem2017年02月14日 21:44:16 +00:00Commented Feb 14, 2017 at 21:44
-
\$\begingroup\$ 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. \$\endgroup\$DJMcMayhem– DJMcMayhem2017年02月14日 21:50:53 +00:00Commented Feb 14, 2017 at 21:50
-
\$\begingroup\$ 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. \$\endgroup\$fəˈnɛtɪk– fəˈnɛtɪk2017年02月14日 21:53:09 +00:00Commented Feb 14, 2017 at 21:53
Brain-Flak, 16 bytes, Levenshtein distance of 4, A000217 and A002378 -- Cracked by Martin Ender!
({({}[()])()}{})
This should be fairly easy to crack.
-
1\$\begingroup\$ Cracked. \$\endgroup\$Martin Ender– Martin Ender2017年02月14日 23:05:38 +00:00Commented Feb 14, 2017 at 23:05
-
\$\begingroup\$ @WheatWizard Oh, whoops, I didn't realize I forgot too. \$\endgroup\$DJMcMayhem– DJMcMayhem2017年02月16日 20:41:19 +00:00Commented Feb 16, 2017 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}
-
1\$\begingroup\$ This is
x**2
and not2**x
\$\endgroup\$user41805– user418052017年02月13日 19:54:50 +00:00Commented Feb 13, 2017 at 19:54 -
-
\$\begingroup\$ @KritixiLithos it is supposed to be both. I changed the wrong sequence link on the top when I changed the other end. \$\endgroup\$fəˈnɛtɪk– fəˈnɛtɪk2017年02月13日 20:00:48 +00:00Commented Feb 13, 2017 at 20:00
-
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}
-
1\$\begingroup\$ I was able to get my crack codegolf.stackexchange.com/a/109976/64505 to behave inconsistently between two different environments. \$\endgroup\$fəˈnɛtɪk– fəˈnɛtɪk2017年02月13日 21:12:37 +00:00Commented Feb 13, 2017 at 21:12
(削除)
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)
(Confirmed to work with the Perl 6 version running on TIO.)
-
1\$\begingroup\$ Am I doing this right? <codegolf.stackexchange.com/a/110001/60793> \$\endgroup\$Joey Marianer– Joey Marianer2017年02月14日 04:26:17 +00:00Commented Feb 14, 2017 at 4:26
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!
-
\$\begingroup\$ @LliwTelracs did that for the first 15 non-negative integers, see my updated answer. \$\endgroup\$peech– peech2017年02月14日 16:29:12 +00:00Commented Feb 14, 2017 at 16:29
-
Explore related questions
See similar questions with these tags.
(0.5*len(A))
\$\endgroup\$