Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is the cops' thread. The robbers' thread goes here.

The last thread was already 4 months ago.

The cop's task

  • The cop's task is to write a program/function that takes a positive (or non-negative) integer and outputs/returns another integer.
  • The cop must state it if the program is intolerant towards zero.
  • The cop will provide at least 2 sample inputs/outputs.
  • For example, if I have decided to write the Fibonacci sequence, I would write this in my answer:
a(0) returns 0
a(3) returns 2
  • The number of examples is up to the cop's discretion.
  • However, the sequence must actually exist in the On-Line Encyclopedia of Integer Sequences®, so no pseudo-random number generator for you. :(
  • The cop can hide as many characters as is so wished.
  • For example, if my program is:

function a(n)
    if n>2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end

  • Then I would hide these characters as I want:

function a(n)
    if ### then
        ########
    else
        ######################
    end
end

The robber's task

  • is obviously to find the original source code.
  • However, any proposed source code that produces the same set of output also counts as valid, as long as it is also found in OEIS.

Tips for the cops

  • The search function in the OEIS only works for consecutive terms, so if you want to hide your sequence, then just leave a hole anywhere.
  • Apparently there is no way to hide the sequence. Put this in mind when you choose the sequence.

Your score is the number of bytes in your code.

The winner will be the submission with the lowest score that hasn't been cracked in 7 days.

Only submissions that are posted in 2016 April are eligible for the win. Submissions that are posted later than this are welcome, but cannot win.

In order to claim the win you need to reveal the full code and the OEIS sequence (after 7 days).

Your post should be formatted like this (NN is the number of characters):


Lua, 98 bytes

Output:

a(0) returns 0
a(3) returns 2

Code (# marks unrevealed characters):

function a(n)
    if ### then
        ########
    else
        ######################
    end
end

If the code is cracked, insert [Cracked](link to cracker) in the header. If the submission is safe, insert "Safe" in the header and reveal the full code in your answer. Only answers that have revealed the full code will be eligible for the win.

share|improve this question
2  
Also, OEIS search can have blanks with _, fyi – Sp3000 2 days ago
1  
In your example you choose to reveal the spaces. Does that mean that you could just add as many spaces as you need in your submission to not reveal anything important? – user81655 2 days ago
7  
It may be too late to change, but allowing sequences that are multiples of an OEIS sequence, and/or only include every nth term would have made this challenge much better. sandbox, hint, hint – Nathan Merrill 2 days ago
5  
Can I, for example, pick the Fibonacci sequence and provide only a(1000)? (which is part of the sequence, but too large to be searchable on OEIS) – Sp3000 2 days ago
2  
"Intolerant towards zero" makes no sense. What is that supposed to mean? – feersum 7 hours ago

42 Answers 42

Vim 36 keystrokes

i****<esc>:let @q="^*i****$**@***"<cr><n>@qbD

(Note: <n> is where you type your input)

Here is the code unrelated to number generation:

          :let @q="              "<cr><n>@qbD

Meaning I am revealing 5 out of 19 characters.

<n> is the input. Here are some sample outputs:

1@q:    1
2@q:    3
6@q:    18
share|improve this answer
    
I know the sequence, I think. I just don't know how to turn it into Vim keystrokes. – QPaysTaxes yesterday

05AB1E, 5 bytes

Last one for today :p. Output:

a(0) = 9
a(5) = 4
a(10) = 89

Code:

___m_

Obfuscated characters are indicated with _. Try it online!-link. Uses CP-1252 encoding.

share|improve this answer
    
I know the sequence, just not how to generate it in so few bytes... – LegionMammal978 yesterday
    
@LegionMammal978 Yes, I think that is going to be the hardest part of this one. – Adnan yesterday
    
I can get it in 5 bytes with g°<¹- but I can't figure out any way to use m at this size! D: – user81655 5 hours ago
    
@user81655 Yes, that was the alternative solution :). – Adnan 1 hour ago

Element, 7 bytes, cracked

Output:

a(3) = 111
a(7) = 1111111

The # are hidden characters, and they are all printable ASCII. I think this one is actually reasonably difficult (for only having 5 missing characters).

###,##}

For convenience, here's the Try It Online and Esolang wiki pages.


My original program was:

_'[,$ ` }

The trick is that

] and } are functionally identical (both translate to } in Perl). Also, I used ,$ to produce a 1 as an additional layer of confusion, although it is possible to ignore the , completely by doing ,1 instead.

share|improve this answer
    
(I know I shouldn't ask this, but) are you sure that it is correct? In particular, } instead of ]? – Kenny Lau 2 days ago
    
@KennyLau The } is correct, and my program (as far as I know) works in every version of Element. – PhiNotPi 2 days ago
    
Cracked. – Kenny Lau 2 days ago
    
I think the formatting is wrong in your original code? – Easterly Irk yesterday
    
@EasterlyIrk It is. If you know how to fix it, be my guest. – PhiNotPi yesterday

Jolf, 5 bytes, cracked

Output:

a(2) = 8
a(10) = 4738245926336

All of it is crucial, and I have shown 1 of 5.

####x

Original code:

mPm$x
mP     cube
  m$   catalan number
    x  input

Try it online!

share|improve this answer
    
Cracked! – Kenny Lau 2 days ago
    
For anyone interested, it's this sequence: oeis.org/A033536 – Blue 2 days ago

05AB1E, 4 bytes (Cracked)

Sample output :

a(5) = 51
a(8) = 257

And for the code :

###^

I revealed the last one. Should be easy enough though, I had quite a hard time finding a sequence :(

All hidden characters are printable.

share|improve this answer
1  
Cracked! :) – Adnan yesterday

MATL, 5 bytes, cracked

Hidden characters are indicated by %.

%5%*%

Output:

a(1) = 3
a(2) = 6
a(4) = 12

Input 0 is valid.


Original code:

35B*s

that is,

35    % push number 35
B     % convert to binary: array [1 0 0 0 1 1]
*     % multiply element-wise by implicit input n: gives [n 0 0 0 n n]
s     % sum of array: gives 3*n
share|improve this answer
2  
Hmmm, the five in code is very annoying! – Adnan yesterday
    
Technically this could be brute-forced by a program... but I won't do that. – Kenny Lau yesterday
1  
cracked – flawr yesterday

05AB1E, 3 bytes, cracked

Output:

a(9) = 165
a(10) = 220

Hidden code:

##O

Try it online might come in handy.

share|improve this answer
    
Cracked. – Kenny Lau yesterday

Hexagony, 7 bytes, cracked

Output:

a(1) = 2
a(2) = 4

Hidden code:

?#####@

Or alternatively:

 ? #
# # #
 # @

Try it online might come in handy.

share|improve this answer
    
Cracked. – Martin Büttner yesterday
    
Uhhh wait, does your code work for input 0? – Martin Büttner yesterday
    
@MartinBüttner Oh, it doesn't, my bad. Your solution was the right one though. – Adnan yesterday

PHP, 41 bytes, cracked

Yeah, finally another Cops and Robbers challenge. Hope I didn't make it to easy.

Output

a(5)   = 0
a(15)  = 1
a(35)  = 0
a(36)  = 1
a(45)  = 1

Source

____________________$argv[1]____________;
####################        ############

Notes


Cracked

I obviously made it to easy and provided not enough examples. The sequence I had in mind was A010054:

a(n) = 1 if n is a triangular number else 0.

Here's my original source code:

echo(int)($r=sqrt(8*$argv[1]+1))==$r?1:0;

It tests whether the input is a triangular number and outputs 1 or 0 accordingly.

share|improve this answer
    
Cracked. – LegionMammal978 yesterday

Jolf, 11 bytes, Cracked , A011551

c*______x__

c*mf^+91x~P

Original code:

c*^c"10"x~P

Examples:

0 -> 1

12 -> 1618033988749
share|improve this answer
    
Cracked. – Adnan yesterday
    
@Adnan Good job, though different from mine. And you couldn't figure out first op. :P – Easterly Irk yesterday
    
Yeah, I couldn't figure out what it does :p – Adnan yesterday
    
@Adnan it was a cast to int function, misused as a floor one. – Easterly Irk yesterday

MATL, 9 bytes, Cracked

Code:

3#2###*##

Output:

a(1)  = 3
a(2)  = 6
a(4)  = 12
a(12) = 37

a(0) is valid.


Cracked

Original sequence: A059563

Original code:

3L2^Ze*sk
3L          % Push [1 -1j] from the clipboard
  2^        % square
    Ze      % exp
      *     % times input
       s    % sum
        k   % floor
share|improve this answer
    
Cracked. – Adnan yesterday

Octave, 34 bytes, cracked

@(m)(m###m#####m##)&isprime(#)####

Outputs:

ans(1) = 0
ans(6) = 5
ans(7) = 10
ans(8) = 15

The sequence starts at ans(1) in OEIS.

share|improve this answer
    
Does it start at 1 on OEIS, or you start your code at 1? – Easterly Irk yesterday
    
The sequence starts at ans(1) = 0 in OEIS. Is that what your asking for, or...? – Stewie Griffin yesterday
    
Cracked. – feersum 10 hours ago

Element, 10 bytes, cracked

Output:

a(3) = 6561
a(4) = 4294967296

There's probably only a few ways to compute this sequence in Element. I found a 9-char solution, but I figured this 10-char solution is actually more difficult. The # are hidden characters.

#_####@^#`

For convenience, here's the Try It Online and Esolang wiki pages.


The original was

2_3:~2@^^`
share|improve this answer
    
Show one more byte. – Kenny Lau 2 days ago
    
@KennyLau I thought it was 1 out of 5? It's 10 bytes and I'm showing 3. – PhiNotPi 2 days ago
    
Inputs and outputs don't count, so you have 8 bytes and you showed 1. – Kenny Lau 2 days ago
    
@KennyLau done. – PhiNotPi 2 days ago
    
Cracked. – Kenny Lau 2 days ago

Pyke, 15 bytes

Output

a(2) = 21
a(15) = 17

Revealed code:

#R#D######+##)#
share|improve this answer
    
The sequence in question starts from n=1 not n=0 by the way – muddyfish yesterday

Pyth, 18 bytes

# marks unrevealed characters.

L?Jtb##5#m##S#2 #y

Outputs (starts from 1):

1 -> 2
2 -> 3
3 -> 5
4 -> 7

Online interpreter

share|improve this answer
    
Primes, no? If not... – Blue yesterday
    
If not... what? – Kenny Lau yesterday
    
then I have no idea – Blue yesterday

05AB1E, 5 bytes, cracked

I hope that this submission isn't as easy as my other ones :p. Outputs:

a(0) = 0
a(1) = 1
a(2) = 6
a(3) = 24
a(4) = 80
a(5) = 240

Obfuscated code:

####O

Contains some non-ASCII characters though, uses CP-1252 encoding.

Try it online! might come in handy :p.

share|improve this answer
    
Cracked. – LegionMammal978 yesterday
    
Why do I feel like I've seen it before? – Kenny Lau yesterday
    
@KennyLau ¯\_(ツ)_/¯ – Adnan yesterday

C, 71 bytes

############
#####
main(){
 scanf("%d",##);
 ###6#;
 printf("%d",##);
}

Output:

a(1) = 0   a(2) = 0   a(5) = 1
a(6) = 1   a(7) = 1   a(9) = 2

This works with gcc, and is a full program. It accepts 0 as input.

share|improve this answer
    
Cracked. – feersum 6 hours ago

Jolf, 11 bytes, Cracked.

Output:

a(10) = 4
a(20) = 6
a(30) = 8

And the partially hidden code:

####xd###x#

Hint:

When I looked through the sequences in order, I didn't go very far before finding this one.

The cracked version isn't quite the same as my original code. I'm not currently at my computer, so I don't have it exactly, but it was something like this:

l fzxd!m%xH

(The only part I'm unsure about is the !m. It's whatever checks if a variable is zero.)

share|improve this answer
    
I found the sequence... Pity I don't know Jolf or javascript very well :( – muddyfish yesterday
    
@muddyfish, Same here... – LegionMammal978 yesterday
    
Well, I guess it's time for the master to do it... may I? – Cᴏɴᴏʀ O'Bʀɪᴇɴ yesterday
    
@CᴏɴᴏʀO'Bʀɪᴇɴ If everyone else is stumped – and it looks like they are – feel free. – QPaysTaxes yesterday
    

Pyke, 6 bytes, Cracked

###X#s

Output:

a(2) = 8
a(8) = 80
a(10) = 120

This doesn't work with N<1

Original solution:

hSmX$s

share|improve this answer
    
Welp, I found an easier alternate to what I had – muddyfish yesterday
    
Cracked. – LegionMammal978 yesterday

Jolf, 16 bytes

Outputs:

a(0) = 0
a(4) = -2
a(51) = 26

Code:

#.‘###4#x##32#mA
share|improve this answer

Java, 479 bytes, Cracked

Outputs:

a(10) = 81
a(20) = 35890

(Inputs are provided via command line arguments)

Code (# marks hidden characters):

import java.util.*;
public class A{

    public static int#########
    public boolean###########

    static A a = new A();

    public static void main(String[] args){
        int input = Integer.parseInt(args[0]);

        LinkedList<Integer> l = new LinkedList<>();
        l.add(1);
        l.add(0);
        l.add(0);

        for(int ix = 0; ################if(##>##{
            ###########d#
            #######+##p##########+##########(#######
        }

        System.out.println(#########################
            ###(A.#############(#5#####)));
    }
}

The program starts at index 0.

(Note that SE replaces all of the \t indents with 4 spaces, bringing the byte total to 569. Click here to see the program with \t indents instead of space indents.)

Original code:

import java.util.*;
public class A{
    public static interface B{
    public boolean C(int i);} 

    static A a = new A();

    public static void main(String[] args){
        int input = Integer.parseInt(args[0]);

        LinkedList<Integer> l = new LinkedList<>();
        l.add(1);
        l.add(0);
        l.add(0);

        for(int ix = 0; ix<input; ix++)cif(i->  {
            return l.add(
            l.pop()+l.peekFirst()+l.peekLast());});{    
        }

        System.out.println(l.get(1));}static boolean 
            cif(A.B b5){return (b5.C((0)));
    }
}

(Same code, but formatted normally):

import java.util.*;

public class A {
    public static interface B { //functional interface for lambda expression
        public boolean C(int i); //void would have given it away
    }

    static A a = new A(); //distraction

    public static void main(String[] args) {
        int input = Integer.parseInt(args[0]);//Input

        LinkedList<Integer> l = new LinkedList<>();
        l.add(1);//Set up list
        l.add(0);
        l.add(0);

        for (int ix = 0; ix < input; ix++)
            cif(i -> { //Fake if statement is really a lambda expression
                return l.add(l.pop() + l.peekFirst() + l.peekLast());
            });
        { //Distraction
        }

        System.out.println(l.get(1));//Output
    }

    static boolean cif(A.B b5) { //Used to pass in lambda expression.
                  //The A. and b5 were both distractions
        return (b5.C((0)));
    }
}
share|improve this answer
    
Hm, how do you come to a byte count of 488? I count 545 from i to }? And please specify 0-tolerance. – Björn Kautler yesterday
    
Aren't your examples a(9) and a(19) or a(8) and a(18), according to which version of it on OEIS you took? – Björn Kautler yesterday
    
@BjörnKautler I'll post a link to the byte counter when I get home. What do you mean by 0-tolerance? The first value is a(1) = 0 – Daniel M. yesterday
    
From the OP: "The cop's task is to write a program/function that takes a positive (or non-negative) integer and outputs/returns another integer. The cop must state it if the program is intolerant towards zero." So I guess you take the input 1 as 0 and this also explains the shift in position, according to the OEIS sequence. – Björn Kautler yesterday
    
@BjörnKautler OK, thanks. The program doesn't crash if 0 is entered but the sequence starts at index 1, so I guess it's zero-intolerant. – Daniel M. yesterday

JavaScript ES6, 119 bytes, Cracked.

Output:

a(0) = 0
a(5) = 10000

Code:

x=>##=#=>[[[##x####r(###f#n###;#####n####h.##w###<1##].c####t.##pl##[####nc#######y([###(###(#]###)######`#######h####`

Returns an anonymous function.

Original sequence: A016744.

Original code:

x=>{f=n=>[[[1,x] for(x of n)]];return Math.pow(x<<1,[].concat.apply([].concat.apply([],f(f(f([]))))).join``.length)}//`

I need to show more characters of obsfucated code next time :P

share|improve this answer
    
Cracked. I wasn't sure which sequence you were going for though, so I had to just choose the easiest one then ignore the rest of the characters. :( – user81655 23 hours ago

Pyth, 70 bytes, Cracked

DhbI|qb"#"qb"#"R!1Iqb"#"#####+""s####2###;##lY+Q1Ih+""Z#####)=Z+Z1;@YQ

# are the hidden characters

Has been cracked, so here is the versionn without hidden chars :

DhbI|qb"4"qb"0"R!1Iqb"1"R!0Rh+""sm^sd2cb1;W<lY+Q1Ih+""Z=Y+YZ)=Z+Z1;@YQ

Sample outputs :

a(1) -> 7
a(2) -> 10
a(4) -> 19

Good luck to find this on OEIS, I personally failed to find it from those examples (even tho the sequence is quite easy to spot.)

share|improve this answer
    
Cracked. – Adnan 10 hours ago

J, 7 bytes, cracked

Output:

a(0) = 6
a(2) = 27

Code (I have shown more for added difficulty):

#+#:###

Is a tacit verb.

share|improve this answer
    
Cracked. – Dennis 2 days ago

Python 2, 87 bytes, cracked

n=input()
#####################################################################
print _

Output:

a(5) = 2
a(10) = 2
a(15) = 1
a(20) = 1
a(25) = 1

I really should have checked for other sequences before I posted, here's another one that works (A014709):

n=input()
g=lambda n:~n%2*(n/2%2+1)or g(n/2);_=g(n)############################
print _
share|improve this answer
    
Cracked. – LegionMammal978 yesterday

Jolf, 13 bytes

Outputs:

a(5) = 40
a(8) = 128

Code:

#+~##~####xx#

Interpreter.

share|improve this answer
    
Ooh, Jolf. I'm gonna have a crack at this one. Please don't steal it, Kenny. – QPaysTaxes yesterday
    
@QPaysTaxes Any luck? :3 – Cᴏɴᴏʀ O'Bʀɪᴇɴ 14 hours ago
    
I might've had some of you didn't have undocumented functions everywhere :P. As it is, I've got two candidates for the sequence, and some idea of how to make them, but it's a pain in the butt :P – QPaysTaxes 14 hours ago
    
@QPaysTaxes I don't think this code uses any undocumented features. – Cᴏɴᴏʀ O'Bʀɪᴇɴ 13 hours ago
    
But they still make reading the source hard. Anyway, I'm just complaining. Feel free to ignore me. – QPaysTaxes 13 hours ago

Jolf, 3 bytes Cracked, A001477

___

Examples:

0 -> 0

1 -> 1

4 -> 4

9 -> 9

Original Code:

 "%"
share|improve this answer
    
Cracked. – LegionMammal978 yesterday

Reng v.3.3, 36 bytes. Cracked, A005449

Output:

a(1) = 2
a(3) = 15

# denotes a gone character. There are no other #s in the program.

i#:#+##-##)####¡#~
##########!</div>

Alright this is the last one for a while. Other people need to answer >_>. A description of each character can be found in the source code, where all the ops are defined. A comment proceeds each operator.

Original code:

i>:1+(1-?v)v/a+¡n~
~^<$:$:$:>!</div>
share|improve this answer
    
Cracked. – Kenny Lau 2 days ago
    
What is the original sequence? – Kenny Lau yesterday

J, 8 bytes, cracked

# marks unrevealed characters

(##-#)#.

(Online interpreter here.)

Output:

No, I'm not hiding anything by using a long sample. If the input is 0, it outputs 0, if the input is between 1 and 29, it outputs 1.

The outputs for the negative inputs do not match with the actual sequence.

   (##-#)#.0
0
   (##-#)#.1
1
   (##-#)#.2
1
   (##-#)#.3
1
   (##-#)#.4
1
   (##-#)#.5
1
   (##-#)#.6
1
   (##-#)#.7
1
   (##-#)#.8
1
   (##-#)#.9
1
   (##-#)#.10
1
   (##-#)#.11
1
   (##-#)#.12
1
   (##-#)#.13
1
   (##-#)#.14
1
   (##-#)#.15
1
   (##-#)#.16
1
   (##-#)#.17
1
   (##-#)#.18
1
   (##-#)#.19
1
   (##-#)#.20
1
   (##-#)#.21
1
   (##-#)#.22
1
   (##-#)#.23
1
   (##-#)#.24
1
   (##-#)#.25
1
   (##-#)#.26
1
   (##-#)#.27
1
   (##-#)#.28
1
   (##-#)#.29
1
share|improve this answer
    
Cracked. – jimmy23013 20 hours ago

JavaScript (ES7), 10 bytes

Output

f(0) -> 1
f(1) -> -1

Code

t=>~t##**#

The code is an anonymous function. This will probably be easy since there's only three characters hidden, but at least it's short! :P

share|improve this answer
    
Cracked – FliiFe 9 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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