19
\$\begingroup\$

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

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:

Language, nn characters (including link to answer), Cop's username

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

Optional explanation and comments.

\$\endgroup\$
4
  • \$\begingroup\$ 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. \$\endgroup\$
    – flawr
    Apr 9, 2016 at 18:52
  • \$\begingroup\$ What happens if the examples match multiple OEIS series ? This Just happened with Adnan and me \$\endgroup\$
    – THC
    Apr 10, 2016 at 20:06
  • \$\begingroup\$ @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. \$\endgroup\$
    – user45941
    Apr 11, 2016 at 20:22
  • \$\begingroup\$ Has this finished? Is there a winner? \$\endgroup\$ May 16, 2016 at 2:38

57 Answers 57

1
2
1
\$\begingroup\$

C (71 bytes) by mIllIbyte

The sequence is floor(n/4).

x;f(_){x/=4;
    }
main(){
 scanf("%d",&x);
 f( 6);
 printf("%d", x);
}
\$\endgroup\$
1
\$\begingroup\$

Python 3 (58 bytes) by CAD97

The sequence is A062318. There were a lot of unnecessary characters in this one, so I commented some out.

a=lambda n: ~-( -~(n%2)
# if ###### else 
*3**(n//2))#)##)
\$\endgroup\$
1
  • \$\begingroup\$ The original was the slightly more literal a=lambda n:int(3**(n/2)-1 if n%2==0 else 2*3**(n/2-1/2)-1), but this works as well and is golfier. GG \$\endgroup\$
    – CAD97
    Apr 11, 2016 at 3:51
1
\$\begingroup\$

Ruby, 11 bytes, histocrat, A011765

It only needs 5...

->i{i%4/3 }

I'd like to note though that the sequence is off-by-one compared to OEIS (which specifies that the first term corresponds to A(1)).

\$\endgroup\$
3
  • \$\begingroup\$ Argh, could've sworn I checked for solutions of that form. Also, sorry, yes, didn't notice the offset on the sequence entry. \$\endgroup\$
    – histocrat
    Apr 11, 2016 at 20:25
  • 1
    \$\begingroup\$ Intended solution: i[i%2] (the (i mod 2)th least significant bit of i) \$\endgroup\$
    – histocrat
    Apr 11, 2016 at 20:29
  • \$\begingroup\$ @histocrat neat, I didn't even know bits could be indexed like that. :) \$\endgroup\$ Apr 11, 2016 at 20:31
1
\$\begingroup\$

Haskell, 51 bytes, Zgarb, A063866

f e=sum[1|1<-sum<$>mapM(flip(:)=<<pure.(0-))[1..e]]

Output: map f [0..6]: [0,1,1,0,0,3,5].

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

05AB1E, 5 bytes, Adnan, A102669

Code:

TA«-g

Output:

a(0) = 0
a(1) = 0
a(2) = 1
a(3) = 1
a(4) = 1
a(5) = 1
a(6) = 1
a(7) = 1
a(8) = 1
a(9) = 1
a(10) = 0
a(11) = 0

Too bad you have designed the language in this inconvenient way.

\$\endgroup\$
1
  • \$\begingroup\$ Wow, I did not see that coming haha. The original code was 0K1Kg. \$\endgroup\$
    – Adnan
    Apr 12, 2016 at 13:24
1
\$\begingroup\$

Python, 17 bytes, ASCIIThenANSI, A000027

def a(n):return n

Trivial?

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

Python, 60 bytes, ASCIIThenANSI A000930

def a(n):
 if n<3:
  return 1
 else:
  return a(n-1)+a(n-3)

Still trivial

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

05AB1E, (4 bytes) by Adnan

The sequence is A126804, and the code to produce it is

D·ŸP

Try it online

I've never even looked at a program in 05AB1E before, it looks like a pretty cool language!

\$\endgroup\$
1
  • \$\begingroup\$ Very nice! That was the exact same solution :) \$\endgroup\$
    – Adnan
    Apr 13, 2016 at 12:10
1
\$\begingroup\$

Lua, 45 bytes, Katenkyo, A001477

a=function(n)return n-1<1 and 0or 1+a(n-1)end
\$\endgroup\$
1
\$\begingroup\$

Swift, 55 bytes, Nefrin, A103847

The sequence is McCarthy's 91 Function.
It takes the value 91 for any n up to 101 and then continues with 92,93,94 ...

I wonder what it's actually useful for.

func M(n:Int)->Int{
return(n<=100) ?M(M(n+11)):n-10;
}
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 28 bytes, Lause, A256861

Code:

DD>D>D>D>****sD<*6+*6n2n5**/

Explanation:

              # implicit n on stack
DD>D>D>D>     # save n,n+1,n+2,n+3,n+4 on the stack
****          # multiply top 5 on stack together
              #     new stack: n,n(n+1)(n+2)(n+3)(n+4)
sD<*          # rotate, duplicate, decrease, multiply
              #     new stack: n(n+1)(n+2)(n+3)(n+4),n(n-1)
6+*           # add 6 to stack, add top 2, multiply top 2
              #     new stack: n(n+1)(n+2)(n+3)(n+4)(n(n-1)*6)
6n2n5**       # add 720 to stack
/             # divide
              # implicitly print n(n+1)(n+2)(n+3)(n+4)(n(n-1)*6)/720
\$\endgroup\$
1
\$\begingroup\$

Jolf, 3 bytes, Cᴏɴᴏʀ O'Bʀɪᴇɴ, A091940

+QQ

Test it here.

Since the output is off-by-one, the second formula on OEIS reduces to n + n^4. Where we implement n^4 by squaring the input twice.

\$\endgroup\$
3
  • \$\begingroup\$ Oh, this wasn't it. What does off-by-one mean? I think I messed it up \$\endgroup\$ Apr 17, 2016 at 21:03
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ It means that the number you get for a(23) is actually A091940(24). But this code matches all 4 test cases in your cop post, so whether or not this was your original code, I think it's a valid crack. \$\endgroup\$ Apr 17, 2016 at 21:06
  • \$\begingroup\$ Okay then. Nice job! \$\endgroup\$ Apr 17, 2016 at 21:06
1
\$\begingroup\$

05AB1A, 4 bytes, Adnan, A001127

Code:

$FÂ+

Explained:

$          # push 1 and input
 F         # input number of times, do:
  Â        # duplicate and reverse
   +       # add

The sequence starts at 1 and continues by adding the current number to its reverse.

0: 1
1: 1+1 = 2
2: 2+2 = 4
3: 4+4 = 8
4: 8+8 = 16
5: 16+61 = 77
6: 77+77 = 154
7: 154+451= 605
and so on...
\$\endgroup\$
0
1
\$\begingroup\$

05AB1E, 3 bytes, Emigna, A022559

Code:

!ÓO

Explanation:

!    # Compute the factorial of the implicit input.
 Ó   # Compute the exponents of the prime factors.
  O  # Sum that up together.

Resulting into A022559. Try it online!

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

05AB1E, 1 byte, mnbvc, A004085

Code:

Õ

Sequence is the sum of digits of Euler totient function of n.

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

LiveCode, 35 bytes, mnbvc, A001477

I/O:

oeis (0) = 0
oeis (2) = 2

Code:

function oeis n
    return n*1
End oeis

Sequence returns the non-negative integers.

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

Python, 37 bytes, mnbvc, A000290

I/O:

a(2) = 4
a(4) = 16

Code:

def a(n):
    return n*n#__!______n____*_

Sequence return square of input

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

05AB1E, 3 bytes, Emigna, A002994

Code:

3m¬

Explanation:

3m   # Compute input ** 3
  ¬  # Take the first digit

This gives us the initial digits of the cubes, which is A002994.

Uses CP-1252 encoding. Try it online!.

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

05AB1E, 8 bytes, Emigna, A088666

Code (with obfuscated version below):

4m1s+rT%
___s_r__

Explanation:

4m         # Compute input ** 4
  1        # Add one to the stack
   s       # Swap the top two elements
    +      # Add the two numbers (result = input ** 4 + 1)
     r     # Reverse the stack
      T    # Add 10
       %   # Modulo

This comes down to the formula a(n) = (n4 + 1) % 10, which is A088666. I'm excited to see what the original code was.

Try it online!.

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

J, 8 bytes, Kenny Lau, A057427

Code:

(>1-*)<.

Output:

a(0) = 0
a(i) = 1 for 0 < i < 30

The sequence is simply signum(n). The program computes floor(n) > 1 - signum(floor(n)), which is signum(n) for non-negative integers n.

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

Python 3, 50 bytes, CAD97, A004242

from math import    *
a=lambda n:ceil(1000*log(n))

Try it online

Output:

a(1) => 0
a(10) => 2303
\$\endgroup\$
2
  • \$\begingroup\$ That was fast (though I honestly did not make it very difficult) \$\endgroup\$
    – CAD97
    Apr 11, 2016 at 1:45
  • \$\begingroup\$ @CAD97 I got tripped up slightly because originally I was only importing ceil from math, because I forgot log was in math and not __builtins__. I liked that trick. :) \$\endgroup\$
    – user45941
    Apr 11, 2016 at 1:46
0
\$\begingroup\$

Python 2 (72 bytes) by Sp3000

There's an unbelievable amount of sequences starting with 1,2,3,6,9,18 from the 1 element. I was fortunate to find one on the 3rd page where these are the only 6 terms: Divisors of 18.

print[1,#((#y
2,3,6,9,#.####c###6#####16#.
18][#)#131963
~-input()#3
]#)
\$\endgroup\$
1
  • \$\begingroup\$ Hmm... I have to say that is the right sequence, but I overlooked the idea that some of the characters could be replaced by newlines (probably got confused due to the rule changes early on). In any case, a crack is a crack. \$\endgroup\$
    – Sp3000
    Apr 11, 2016 at 18:31
0
\$\begingroup\$

Pyth, 4 bytes, FliiFe, A000041

Code:

l./Q

Explanation:

 ./Q  # Calculate the paritions of Q (input)
l     # Take the length, which counts the number of partitions.

Try it here.

\$\endgroup\$
1
  • \$\begingroup\$ Now that I think of it, I could have written l./ with implicit imput. \$\endgroup\$
    – THC
    Apr 16, 2016 at 15:42
0
\$\begingroup\$

JavaScript, 30 bytes, Aplet123, A002061

It's the sequence A002061:

Central polygonal numbers: n^2 - n + 1.

n=>Math.pow(n,!![]+!![])-(n-1)

See it in action on JSFiddle.

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

Python, 123 bytes, ASCIIThenANSI, A089911

Code:

def f(n):
 if n<2:
  return n
 else:
  return f(n-1)+f(n-2)

def g(n):
 if n<2:
  return n
 else:
  return (f(n-1)+f(n-2))%12

The formula for this sequence is g(n) = f(n) % 12, whereas f(n) is the nth Fibonacci number.

This was actually a really nice puzzle! :)

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

Python 3, 58 bytes, Mega Man

import math;x=int(input());print(int(x/math.sqrt(5)*x**x))

The sequence is:

(x/√5)*(x**x)
\$\endgroup\$
0
\$\begingroup\$

Python, 42 bytes, TùxCräftîñg

def f(x):return x if x<2else f(x-1)+f(x-2)

This is the Fibonacci sequence.

\$\endgroup\$
1
2

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.