# Find the program that prints this integer sequence (Robbers' thread)

In the cops thread, the task was to write a program/function that takes a positive (or non-negative) integer and outputs/returns another number (not necessarily integer). The robbers task is to unscramble the code the cops used to produce this output.

The cracked code doesn't have to be identical, as long as it has the same length and any revealed characters are in the correct positions. The language must also be the same (version numbers can be different). The output must of course be identical.

No-ops can be used in robber's solution.

The winner of the robbers thread will be the user who has cracked the most submissions by May 7th 2016. If there's a tie, the user who has cracked submissions with the longest combined code will win.

The submission should be formatted like this:

Code:

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


Output

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


• These rules here are different from the cops thred, where it says: 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. Apr 9, 2016 at 18:52
• What happens if the examples match multiple OEIS series ? This Just happened with Adnan and me
– THC
Apr 10, 2016 at 20:06
• @FliiFe Under the current rules, any code which matches the cop's code and outputs an OEIS sequence whose values coincide with the cop's examples is a valid crack.
– user45941
Apr 11, 2016 at 20:22
• Has this finished? Is there a winner? May 16, 2016 at 2:38

# MATL, 5 bytes, Luis Mendo

H5-*|


This code calculates abs((2-5)*input) which is just a(n)=3*n for positive numbers, which is http://oeis.org/A008585

• Well done! My original code was 35B*s :-) Apr 9, 2016 at 20:35

## Hexagony, 7 bytes, Adnan, A005843

?{2'*!@


or

 ? {
2 ' *
! @


Try it online!

Simply doubles the input (and assumes positive input). The code is (for once) simply executed in reading order. The code uses three memory edges A, B, C with the memory pointer starting out as shown: ?    Read integer from STDIN into edge A.
{    Move memory pointer forwards to edge B.
2    Set edge B to 2.
'    Move memory pointers backwards to edge C.
*    Multiply edges A and B and store result in C.
!    Print result to STDOUT.
@    Terminate program.

• The exact same with what I had! :) Apr 9, 2016 at 10:00
• @KennyLau I think the solution is unique up to swapping the roles of B and C. Apr 9, 2016 at 10:01

# J, 7 bytes, Cᴏɴᴏʀ O'Bʀɪᴇɴ

### Code

2+*:@p:


### Output

   f =: 2+*:@p:
f 0
6
f 2
27


Try it with J.js.

### How it works

Sequence A061725 is defined as a(n) := pn² + 2, where pn is the (n + 1)th prime number.

2+*:@p:  Monadic verb. Argument: n

@    Atop; combine the verbs to the right and to the left, applying one after
the other.
p:  Compute the (n+1)th prime number.
*:     Square it.
2+       Add 2 to the result.

• Nice job! You understand the code more than I did XD Apr 9, 2016 at 14:39

# 05AB1E, 5 bytes, Adnan, A001788

Læ€OO


Try it online! This uses an alternative definition given on the page. Explanation:

Læ€OO
L     range;      [1..n]
æ    powerset;   [[], , ..., [1..n]]
€O  mapped sum; [0, 1, ..., T(n)]
O sum;        [a(n)]


# JavaScript, 10 bytes, user81655, A033999

I think I got it. Yeah. This one was really hard. I like the submission because it relies heavily on precedences.

It's the sequence A033999:

a(n) = (-1)^n.

Source

t=>~t.z**t


Explanation

If you split this code according to the JavaScript operator precedences you get:

1. . (precedence 18) gets evaluated first and t.z will return undefined.
2. ~ (precedence 15) tries to cast undefined, resulting in 0, and returns -1 after bitwise not.
3. ** (precedence 14) will return -1 ^ t, where t is odd or even, resulting in -1 or 1.

Demo

console.log(
(t=>~t.z**t)(0),
(t=>~t.z**t)(1),
);


I will award a 100 rep bounty on this cool Cop submission.

• You are correct, congratulations! :) Apr 14, 2016 at 8:32
• I consider myself well-versed in javascript, but I have no idea how this works. Apr 14, 2016 at 14:04
• @CᴏɴᴏʀO'Bʀɪᴇɴ I've added an explanation. Hopefully it explains it well enough. Apr 14, 2016 at 14:21
• That's why the brute-force didn't find it. I used a transpiler with wrong op precedence >_< Apr 14, 2016 at 14:39

# Element, 7 bytes, PhiNotPi, A000042

_'[,1}


Notes: I was misled by the } for soooooo long. So it also matches [.

Try it online!

### How it works:

_'[,1}
_        main_stack.push(input());
'       control_stack.push(main_stack.pop());
[      Object temp = control_stack.pop();
for(int i=0;i<temp;i++){
,         Object a = main_stack.pop(); //is actually zero
main_stack.push(a.toChars());
main_stack.push(a);
1        main_stack.push(1);
       System.out.println(main_stack.pop());
}  }

• Nice! I was trying this, but I couldn't figure out how to get the , to stop breaking things.
– anon
Apr 9, 2016 at 6:09
• My trick was to do ,$ to produce a 1, which gave me an excuse to put the really confusing , operator in my program. Apr 9, 2016 at 6:13 • I was stuck at the } for tooooo long :( Apr 9, 2016 at 6:14 # PHP, 41 bytes, insertusernamehere, A079978 echo/* does n%3=0 */$argv%3<1?1:0    ;


Returns 1 if its argument is a multiple of 3, and 0 otherwise. Not much beyond that.

• Apr 9, 2016 at 17:35

# MATL, 9 bytes, beaker, A022844

Code (with a whitespace at the end):

3x2xYP*k


Try it online!

Found the following three matches with a script I wrote:

Found match: A022844
info: "name": "Floor(n*Pi).",

Found match: A073934
info: "name": "Sum of terms in n-th row of triangle in A073932.",

Found match: A120068
info: "name": "Numbers n such that n-th prime + 1 is squarefree.",


I tried to do the first one, which is basically done with YP*k:

3x2x       # Push 3, delete it, push 2 and delete that too
YP     # Push pi
*    # Multiply by implicit input
k   # Floor function


# Jolf, 3 bytes, Easterly Irk, A001477

axx


Consists of a simple cat (ax) followed by a no-op. Not sure what the cop was going for here.

• That is most definitely not the identity function. It's alert the input. There are actual identity functions :P Apr 10, 2016 at 1:23

# Java, 479 bytes, Daniel M., A000073

Code:

import java.util.*;
public class A{

public static int i=0;
public boolean b;

static A a = new A();

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

for(int ix = 0; ix<=input; ix++)if(ix>2){
.get(1)+l.peekFirst()+     l.get(2));
}

System.out.println(input<2?0:l.pop()
+(A.i        +(/*( 5*/ 0 )));
}
}


If you miss non-revealed characters, they are replaced with spaces.

• Very different from the original code, but still, congrats! Apr 10, 2016 at 2:20

# Ruby, 38 bytes, histocrat, A008592

->o{(s="+o++o"*5).sum==03333&&eval(s)}


Could be different from the intended solution as I found this by hand.

• Nicely done! Intended solution was similar: "+f+=f"*5. Apr 12, 2016 at 13:37

# 05AB1E, 4 bytes, Paul Picard, A001317

Code:

$Fx^  Try it online! Explanation: $      # Pushes 1 and input
F     # Pops x, creates a for-loop in range(0, x)
x    # Pops x, pushes x and 2x
^   # Bitwise XOR on the last two elements
# Implicit, ends the for-loop
# Implicit, nothing has printed so the last element is printed automatically


The sequence basically is a binary Sierpinski triangle:

f(0)=      1                    =1
f(1)=     1 1                   =3
f(2)=    1 0 1                  =5
f(3)=   1 1 1 1                 =15
f(4)=  1 0 0 0 1                =17


And translates to the formula a(n) = a(n - 1) XOR (2 × a(n - 1))

Luckily, I remembered this one :)

• And it is the exact same one, indeed :D Apr 9, 2016 at 13:06

# S.I.L.O.S, betseg, A001844

readIO
a=i
a+1
i*2
i*a
i+1
printInt i


Try it online!

• goddamnit you ninjad me Oct 20, 2016 at 9:22

# Jolf, 5 characters, Cᴏɴᴏʀ O'Bʀɪᴇɴ, A033536

Code:

!K!8x


Output:

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

– anon
Apr 9, 2016 at 1:34
• Neither answer is the original, but they are functionally the same. Apr 9, 2016 at 1:34
• @QPaysTaxes Sorry :( Apr 9, 2016 at 1:34

# Reng v3.3, 36 bytes, Cᴏɴᴏʀ O'Bʀɪᴇɴ, A005449

iv:#+##->>)2%æ~¡#~
#>:3*1+*^##</div>


## Output

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


## Explanation

I completely ignored the prespecified commands, except the ) because I did not have enough space.

The actually useful commands are here:

iv      >>)2%æ~
>:3*1+*^


Stretched to a straight line:

i:3*1+*)2%æ~


With explanation:

i:3*1+*)2%æ~ stack
i                  takes input
:           [1,1]    duplicates
3          [1,1,3]  pushes 3
*         [1,3]    multiplies
1        [1,3,1]  pushes 1
*            multiplies
)           shifts (does nothing)
2    [4,2]    pushes 2
%         divides
æ  []       prints
~ []       halts


The formula is a(n) = n(3n+1)/2.

• +1 for </div>, an HTML closing tag that somehow appeared in Reng code. Apr 17, 2016 at 13:05
• @zyabin101 Wrong place? Apr 17, 2016 at 13:06
• Nope. I just like finding hidden secrets in code. :-P Apr 17, 2016 at 13:12
• Well this is in the cop's code, so... Apr 17, 2016 at 13:13

# 05AB1E, 3 bytes, Adnan, A000292

LLO


### Output

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


### How it works

LLO Stack
L   [1,2,3,4,5,6,7,8,9]                         range
L  [1,1,2,1,2,3,1,2,3,4,...,1,2,3,4,5,6,7,8,9] range of range
O sum all of them


The mathematical equivalent is sum(sum(n)), where sum is summation.

• Nice job, that was the exact same solution :) Apr 9, 2016 at 7:52

# Jolf, 11 bytes, QPaysTaxes, A000005

aσ0xxdxxxxx


Simple enough: alert the σ0 (number of divisors of) x, then put useless stuff at the end.

Try it online! The test suite button's a bit broke, but still shows proper results.

(You could've golfed it down to two bytes! Just σ0 would've done nicely.)

• Wow! Le builtins minuscules! +1 Apr 9, 2016 at 14:38
• This is nothing like what I had, but it sure works. Mine was so long because you didn't have any mention of finding divisors in the docs.
– anon
Apr 9, 2016 at 14:40
• @QPaysTaxes I guess I need to update the docs :P But seriously, just Ctrl+F the source code ;) Apr 9, 2016 at 14:40
• I put my original code in my question if you wanna see it. In retrospect, I should have showed different characters :P
– anon
Apr 9, 2016 at 15:35

# Python 2, 87 bytes, Sp3000, A083054

n=input()
_=int(3**.5*n)-3*int(n/3**.5)########################################
print _


Not that hard, actually. Just searched for sequences that met the constraints until I found one that could be generated in the given space.

# Jolf, 11 bytes, RikerW, A011551

Code:

c*mf^+91x~P


Explanation:

     +91     # add(9, 1) = 10
^   x    # 10 ** input
mf         # floor function (no-op)
*       ~P  # multiply by phi
c            # ¯\_(ツ)_/¯

• c is "cast to integer" Apr 14, 2016 at 14:05

# JavaScript (ES6), 119 bytes, Cᴏɴᴏʀ O'Bʀɪᴇɴ, A178501

x=>(n="=>[[["|x|"##r(###f#n###;##")|n?Math.pow("#<1##].c####t.##pl##[####nc#"|10,"y([###(###(#]###)"|x-1|):0|#h####


I'm sure the actual code generates a trickier sequence than this, but with just the two outputs, this OEIS sequence is simple and matches them.

Without all the ignored characters, the algorithm is just x=>x?Math.pow(10,x-1):0.

# 05AB1E, 5 bytes, Luis Mendo, A051696

Code:

Ðms!¿


Explanation:

Ð      # Triplicate input.
m     # Power function, which calculates input ** input.
s    # Swap two top elements of the stack.
!   # Calculate the factorial of input.
¿  # Compute the greatest common divisor of the top two elements.


So, basically this calculates gcd(n!, nn), which is A051696.

# PHP, 18 bytes, insertusernamehere, A023443

Code:

echo$argv+0+~0;  Output: a(0) = -1 a(1) = 0  • Very nice approach. My source was slightly different: echo$argv+-+!0;. :) Apr 10, 2016 at 9:15

# Octave (34 bytes) by Stewie Griffin

The sequence is A066911.

@(m)(mod(m,u=1:m  )&isprime(u))*u'

• Nice =) For the record, I had u=0:m-1. The same sequence. Apr 10, 2016 at 19:52

# PHP, 137 bytes, insertusernamehere, A000959

Code:

for($s=range(1,303);$i<($t=count($s));$s=array_merge($s))for($j=($k=++$i==1?2:$s[$i-1])-1;$j<$t;$j+=$k )unset($s[$j]);echo$s[\$argv-1];


Output:

a(3)  =   7
a(7)  =  21
a(23) =  99

• Nicely done. Your source is slightly different and you even saved one byte. :) Apr 11, 2016 at 8:13

## 05AB1E, 10 bytes, George Gibson, A003215

Code:

Ds3*s1+*1+


Explanation:

Computes 3*n*(n+1)+1 which is the oeis sequence A003215.

# Element, 10 bytes, PhiNotPi, A097547

2_4:/2@^^


Try it online!

## Output

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


# Pyke, 6 bytes, muddyfish, A005563

0QhXts


Yay hacks! The 0Qh and s are no-ops. hXt just computes (n + 1) ^ 2 - 1.

# J, 8 bytes, Kenny Lau, A057427

Code:

(-%- )\.


Output:

a(0) = 0
a(1..29) = 1


I don't think this is intended. And I don't know why J had this behavior. But it works.

• Gonna add one more restriction xd Apr 10, 2016 at 9:45

# Pyth, 70 bytes, FliiFe, A070650

Code (with obfuscated version below):

DhbI|qb"#"qb"#"R!1Iqb"#";=^Q6+""s ]%Q27  ;.qlY+Q1Ih+""Z##;.q)=Z+Z1;@YQ
DhbI|qb"#"qb"#"R!1Iqb"#"#####+""s####2###;##lY+Q1Ih+""Z#####)=Z+Z1;@YQ (obfuscated)


This basically does:

=^Q6%Q27


It calculates a(n) = n6 % 27, which is A070650. Explanation:

=^Q6       # Assign Q to Q ** 6
%Q27   # Compute Q % 27
# Implicit output


Try it here

• Oops, that's not the one. I updated my answer with another one
– THC
Apr 10, 2016 at 20:03
• From the rules, this is valid. Congrats !
– THC
Apr 10, 2016 at 20:08
• I guess I can tell you the sequence now, It's A007770 (0-indexed)
– THC
Apr 10, 2016 at 20:31
• @FliiFe Oh, I would never have guessed that :p Apr 10, 2016 at 20:32
• Actually, if you know the sequence, it's easily spottable, but if you don't, it becomes really hard
– THC
Apr 10, 2016 at 20:39

def a(n):
if n == 0: return 0
f=a(n-1)-n
return f if f>0 and not f in(a(i)for i in range(n))else a(n-1)+n


Obfuscated code :

def a(n):
###n####0######n#0
f=a#######
return f #f#####a###### f ####a(##f###i#i###a####n##else a#######


Outputs:

>>> a(0)
0
>>> a(4)
2
>>> a(16)
8
>>> a(20)
42

• Exactly what I had. Expected it to be easy, honestly. Apr 10, 2016 at 21:12