# Cops section

The robbers section can be found here.

Thanks to FryAmTheEggman, Peter Taylor, Nathan Merrill, xnor, Dennis, Laikoni and Mego for their contributions.

### Challenge

Your task is to write 2 different programs (full programs/functions/etc.) in the same language and the same version (e.g. Python 3.5 ≠ Python 3.4, so that is not allowed), and when given n (using STDIN/function arguments/etc.), compute a(n) where a is an OEIS sequence of your choice. One of those programs is shorter than the other. You only need to submit the longer program of the two. The other one needs to be saved in case of not being cracked after 7 days. Your submission is cracked when your program has been outgolfed (whether it is by 1 byte or more).

For example, if the task you chose was to perform 2 × n, this could be a valid submission (in Python 2):

## Python 2, 16 bytes, score = 15 / 16 = 0.9375

print(2*input())


Computes A005843, (offset = 0).

If your submission has been cracked, then you need to state that in your header like so:

## Python 2, 16 bytes, score = 15 / 16 = 0.9375, [cracked] + link

print(2*input())


Computes A005843, (offset = 0).

### Offset

This can be found on every OEIS page. For example, for A005843, the offset is 0,2. We only need to use the first one, which is 0. This means that the function is defined for all numbers ≥ 0.

In other words, the function OEIS(n) starts with n = 0. Your program needs to work for all cases given by OEIS.

### Scoring

The score you get for your submission is equal to the following formula:

Score = Length (in bytes) of secret code ÷ Length (in bytes) of public code

The example above has the score 15 ÷ 16 = 0.9375.

The submission with the lowest score wins. Only submissions that have posted their solution will be eligible for winning.

### Rules

• The task you need to do is an OEIS sequence of your choice.
• Given n, output OEIS(n). Deviation is not allowed, so you need to produce the exact same sequence (when given n, you need to output OEIS(n)).
• Submissions that are not cracked within a period of 7 days are considered safe after the solution has been posted (submissions older than 7 days that do not have their solution posted are still vulnerable in being cracked).
• In your submission, you need to post the following things: language name, byte count, full code, so no pastebin links etc. (to prevent answers like Unary), OEIS sequence, score with lengths of both programs and additionally, the encoding that is used.
• Note: the same sequence cannot be posted twice in the same language. (For example, if the sequence A005843 has been done in Pyth, you cannot use Pyth again for that same sequence.)
• Input and output are both in decimal (base 10)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><style>table th,table td{padding: 5px;}th{text-align: left;}.score{text-align: right;}table a{display: block;}.main{float: left;margin-right: 30px;}.main h3,.main div{margin: 5px;}.message{font-style: italic;}#api_error{color: red;font-weight: bold;margin: 5px;}</style> <script>QUESTION_ID=88979;var safe_list=[];var uncracked_list=[];var n=0;var bycreation=function(x,y){return (x[0][0]<y[0][0])-(x[0][0]>y[0][0]);};var byscore=function(x,y){return (x[0][1]>y[0][1])-(x[0][1]<y[0][1]);};function u(l,o){jQuery(l[1]).empty();l[0].sort(o);for(var i=0;i<l[0].length;i++) l[0][i][1].appendTo(l[1]);if(l[0].length==0) jQuery('<tr><td colspan="3" class="message">none yet.</td></tr>').appendTo(l[1]);}function m(s){if('error_message' in s) jQuery('#api_error').text('API Error: '+s.error_message);}function g(p){jQuery.getJSON('//api.stackexchange.com/2.2/questions/' + QUESTION_ID + '/answers?page=' + p + '&pagesize=100&order=desc&sort=creation&site=codegolf&filter=!.Fjs-H6J36w0DtV5A_ZMzR7bRqt1e', function(s){m(s);s.items.map(function(a){var he = jQuery('<div/>').html(a.body).children().first();he.find('strike').text('');var h = he.text();if (!/cracked/i.test(h) && (typeof a.comments == 'undefined' || a.comments.filter(function(b){var c = jQuery('<div/>').html(b.body);return /^cracked/i.test(c.text()) || c.find('a').filter(function(){return /cracked/i.test(jQuery(this).text())}).length > 0}).length == 0)){var m = /^\s*((?:[^,;(\s]|\s+[^-,;(\s])+).*(0.\d+)/.exec(h);var e = [[n++, m ? m[2]-0 : null], jQuery('<tr/>').append( jQuery('<td/>').append( jQuery('<a/>').text(m ? m[1] : h).attr('href', a.link)), jQuery('<td class="score"/>').text(m ? m[2] : '?'), jQuery('<td/>').append( jQuery('<a/>').text(a.owner.display_name).attr('href', a.owner.link)) )];if(/safe/i.test(h)) safe_list.push(e);else uncracked_list.push(e);}});if (s.items.length == 100) g(p + 1);else{var s=[[uncracked_list, '#uncracked'], [safe_list, '#safe']];for(var i=0;i<2;i++) u(s[i],byscore);jQuery('#uncracked_by_score').bind('click',function(){u(s[0],byscore);return false});jQuery('#uncracked_by_creation').bind('click',function(){u(s[0],bycreation);return false});}}).error(function(e){m(e.responseJSON);});}g(1);</script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/Sites/codegolf/all.css?v=7509797c03ea"><div id="api_error"></div><div class="main"><h3>Uncracked submissions</h3><table> <tr> <th>Language</th> <th class="score">Score</th> <th>User</th> </tr> <tbody id="uncracked"></tbody></table><div>Sort by: <a href="#" id="uncracked_by_score">score</a> <a href="#" id="uncracked_by_creation">creation</a></div></div><div class="main"><h3>Safe submissions</h3><table> <tr> <th>Language</th> <th class="score">Score</th> <th>User</th> </tr> <tbody id="safe"></tbody></table></div>

Note

This challenge is finished. The final winner is feersum with his Seed answer. Congratulations! :).

You can still submit new cops, but be aware that they are no longer competing.

• @Andan That seems unfortunate. Say I write a golf with multiple clever tricks that improve on the obvious formula. If I post the obvious formula, anyone can find one improvement and win. Or, I have to tip my hand and give away all the improvements but one. Would you consider changing this, if it's not too late? Sorry for not thinking of this in this sandbox, I only noticed when trying the challenge in earnest.
– xnor
Aug 6, 2016 at 11:07
• @xnor Hmm, that would cause a big problem with the scoring mechanism. You can then make an arbitirarily large submission and an almost impossible short one, and win the challenge. Aug 6, 2016 at 11:12
• @Adnan You could solve that by defining score = len(secret code)/min {len(public code), len(shortest code posted by robbers)}. Aug 6, 2016 at 12:22
• @Adnan The context is xnor’s suggestion to make the score count if the robbers beat your public score but do not match your secret score. I’m proposing a way to make that work while avoiding the problem you’re concerned about. Aug 6, 2016 at 12:43
• Yeah, finally another Cooooops and Rooooobbbbbers challenge. Aug 6, 2016 at 20:41

## QBasic (QB64), 30 bytes, score = 28 / 30 = 0.9333 (cracked)

INPUT n:p=n MOD 2:?p*n+(n+p)/2


Computes A014682, a version of the Collatz function (offset 0).

This works on the QB64 emulator with autoformatting turned off. It should work on actual QBasic as well, but I don't have a copy to test it.

My 28-byte version used a bitwise operator and integer division:

INPUT n:?(1AND n)*n+(n+.5)\2

• Cracked Aug 19, 2016 at 20:32
• So "integer division" is floating-point division followed by round to nearest? Funny :) Aug 19, 2016 at 21:04
• @feersum Even curiouser, actually: it appears to be round to nearest followed by integer division. For example, 1.4\2 gives 0, but 1.6\2 gives 1. I can't confirm whether that's how it works in actual QBasic or if it's a QB64 quirk, but it's weird, in any case. ... Which just made me realize that I could have used 1 instead of .5, for 27 bytes. D'oh! Aug 19, 2016 at 21:49

## Acc!!, 526 bytes, score = 0.5627 (296/526) (cracked)

N
Count x while _%60-46 {
(_+_%60*5-288)*10+N
}
_/60
Count i while _/27^i {
_+27^i*(_/27^i*26-18)
}
_*3+93
Count i while _/27^i/27%3 {
_-i%2*2+1
Count j while _/3^(3*j+2-i%2)%3 {
_+3^(1+i%2)
Count k while _/3^(3*k+1+i%2)%3-1 {
_+3^(3*k+1+i%2)*26
}
}
}
Count i while _/27^i/3 {
_-_/27^i/3%27*27^i*3+_/3^(3*i+1+_%3)%3*3
}
_/3
Count i while _/100^i {
_+_/100^i*100^i*9
}
Count i while _/100^i/10 {
_+_/100^i/10%10
Count j while i+1-j {
_+(_%10-_/100^(j+1)%10)*(100^(j+1)-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}


Computes A000204, Lucas numbers with offset 1.

A couple of notes. Due to Acc!!'s input limitations, the program takes input as a decimal number terminated with a period (.); for example:

> python acc.py Program.txt
5.
11


This program has exponential time complexity, so I wouldn't recommend running it with input greater than about 14 (takes 60 seconds on my laptop). However, given enough time, the algorithm will return the correct result for any positive integer n. Thus: a crack attempt that places any size limits on the input value is invalid.

Have fun!

• cracked (barely) Aug 20, 2016 at 17:59

## Python, 46 bytes, score = 0.97826 (45 / 46) [cracked]

f=lambda n,k=1:n and-~f(n-("01"in bin(k)),k+1)


Calculates A101082 (offset = 1), which are:

Numbers n such that binary representation contains bit strings "10" and "01" (possibly overlapping).

@Dennis cracked the submission as intended, which was to replace "01"in bin(k) with some bit twiddling, namely (k&-k)+k&k>0, to check that k's binary representation isn't of the form 111...111000...000.

• cracked Aug 21, 2016 at 7:56

## Acc!!, 512 bytes, score = 0.5625 (288 ÷ 512) (cracked)

Fourth try. Let's see how fast Dennis cracks this one. (Edit: 8 minutes, that's a record!)

N
Count x while _%60-46 {
(_+_%60*5-288)*10+N
}
_/30
Count i while _/27^i {
_+(_/27^i*26-18)*27^i
}
_*3+93
Count i while _/27^i/27%3 {
_-i%2*2+1
Count j while _/3^(3*j+2-i%2)%3 {
_+3+i%2*6
Count k while _/3^(3*k+1+i%2)%3-1 {
_+27^k*3^(i%2)*78
}
}
}
Count i while _/27^i/3 {
_-_/27^i/3%27*27^i*3+_/3^(3*i+1+_%3)%3*3
}
_/3
Count i while _/100^i {
_*10-_%100^i*9
}
Count i while _/100^i/10 {
_+_/100^i/10%10
Count j while i+2-j {
_+(_%10-_/100^j%10)*(100^j-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}


Computes A002878, Lucas(2*n+1), offset = 0.

Due to Acc!!'s input limitations, the program takes input as a decimal number terminated with a period (.); for example:

> python acc.py Program.txt
3.
29


This program has exponential time complexity, so I wouldn't recommend running it with input greater than about 7. However, given enough time, the algorithm will return the correct result for any positive integer n. Thus: a crack attempt that places any size limits on the input value is invalid.

• cracked Aug 26, 2016 at 20:49
• @Dennis Hey, fastest yet! Aug 26, 2016 at 20:52

# J, 12 bytes, score = 0.9167 (11/12) (cracked)

(#++/)@I.@#:


Computes A230877.

• Cracked Sep 9, 2016 at 19:38

# Woefully, (noncompeting, but you still get points for cracking it), 520/776= ~0.67 Cracked by Feersum.

Computes A000042 (would compute repunits, but that one has 0 as first member)

Offset 1, zero indexed (0 outputs 1, 1 outputs 11, 2 outputs 111, etc.)

| |||||||| | |
|| |||||| |
||| |||| |
|||| || |
||||| || |
|||| |||| |
||| |||||| |
|| |||||||| |
| |||||||||| |
|| ||||||||| |
||| |||||||| |
|||||||||||| |
|||||||||||| |
|||||||||||| |
||||||||||| |
|||||||||| |
|||||||||| |
|||||||||| |
|||||||||| |
||||||||||| |
|||||||||||| |
||||||||||||| |
|||||||||||| |
||||||||||| |
|||||||||| |
||||||||| |
|||||||| |
||||||| |
|||||| |
||||| |
|||| |
||| |
|| |
|| |
|| |
| |
| |
| |
| |
| |
|| |
|| |
|| |
||| |
|||| |
||||| |
|||||| |
||||||| |
|||||||| |
||||||| |
|||||||| |
||||||||| |
|||||||||| |
||||||||||| |
|||||||||||| |
||||||||||||| |
|||||||||||| |
||||||||||| |
|||||||||| |
||||||||| |
|||||||| |
||||||| |
|||||| |
||||| |
|||| |
||| |
|| |
|| |
|| |
|| |
||| |
|||| |
||| |
|| |
| |
| |
| |
|| |
|| |
|| |
|| |


Try it online!

I like to think that my shorter solution was a pretty nice one.

| || || |
|| || |
||| || |
|||| || |
||||| || |
|||| |||| |
||| ||||| |
|| |||||| |
| ||||||| |
|| |||||| |
||| ||||| |
||| |||| |
|||| || |
||| ||| |
|| |||| |
| ||||| |
|||||||| |
||||||||| |
|||||||||| |
|||||||||| |
||||||||| |
|||||||| |
||||||| |
|||||| |
||||| |
||||| |
||||| |
|||| |
|||| |
|||| |
|||| |
|||| |
||| |
||| |
||| |
|||| |
|||| |
||||| |
||||| |
|||||| |
||||| |
|||| |
||| |
|| |
| |
| |
| |
| |
|| |
||| |
||| |
|||| |
||| |
|| |
| |
| |
| |
|| |
|| |
|| |
|| |
||| |
||| |
|||| |
||| |
|| |
| |


What I did was remove the push one command from the top, replace it at the bottom and at the end of the first command, which was free because I just had to replace some pipes, which then allowed me to shorten the push nine commands some more, because it didn't need to move that much anymore

• This TIO link is way too long o_o Sep 7, 2016 at 8:17
• Cracked Sep 8, 2016 at 2:08

# J, 18 bytes, score = 0.7222 (13/18) (cracked)

0{]1&(}.],+/)2 1"_


Computes the Lucas numbers, A000032.

• Cracked Sep 29, 2016 at 0:25

# Sesos, 14 bytes, score = 0.6429 (9/14) (cracked)

0000000: aed40b b47bc2 8e01be 8e9ddb b107                  ....{.........


Computes A130909.

Try it online!

• – Lynn
Aug 6, 2016 at 11:57
• You need to include the score in the header of your submission. Aug 6, 2016 at 12:01

# Python 3.5, 38 bytes, Score = 0.86842 (33/38) (Cracked):

G=lambda n:n<1and 1or(2*n-1)**2*G(n-1)


Computes A001818.

Try It Online! (Ideone)

• Cracked Aug 6, 2016 at 18:44

# 05AB1E, 10 bytes, score = 5 ÷ 10 = 0.5, cracked

This one isn't too hard actually :p. Code:

[NNÂÊ½¾¹Q#


Computes the Nth non-palindromic number, which is A029742.

Try it online!

• Cracked.
– Lynn
Aug 7, 2016 at 18:58

# JavaScript (ES6), 77 bytes, score = 0.9481 (73 / 77) [Cracked]

n=>eval("for(i=0;n;a||n--)[...s=a=++i+''].map(d=>a-=Math.pow(d,s.length));i")


Computes A005188, (offset = 1).

Didn't end up being super interesting but I thought I'd try and submit something.

Note: This is in ES6 so there is no ** operator. I just thought this would make it more cross-browser compatible and easier to test.

• Cracked Aug 8, 2016 at 5:52
• @feersum Lol, I should have spent more time golfing it! Evidently this is possible in 72 bytes... Aug 8, 2016 at 6:07

Python (3.4.3), 77 bytes, score = 0.7272 (56/77) cracked

import math;lambda x: 1 if x==0 else (0 if ((math.sqrt(1+8*x)-1)/2)%1 else 1)


Computes A010054, offset = 0

• Cracked Aug 8, 2016 at 18:28

# Coffeescript, 83 bytes, score = 79/83 = 0.952 [cracked!]

r=(n)->return if r<0 then 0 else Array(parseInt(n/9)+2).join ((n-1)%9+1).toString()


Computes A010785.

(Not so) Surprisingly, @DomHastings managed to shave 33 bytes off of my solution.

Wow, I suck at , don't I? Well, here's my other code:

r=(n)->return if r<0 then 0 else ((n-1)%9+1).toString().repeat(parseInt(n/9)+2)


Here's a less messy version of the code:

r=(n)->
if r<0
return 0
else
((n-1)%9+1).toString().repeat(parseInt(n/9)+2)
# ((n-1)%9+1).toString() is the repeating digit (as a string).
# parseInt(n/9)+2 is the times the digit is repeated.

• Aug 9, 2016 at 11:42

# 05AB1E, 13 bytes, score = 0.769 (10 ÷ 13), cracked

This one isn't too hard either. Code:

µN•vÉ•vyK}g_½


Calculates A001742 (offset = 1).

• Cracked. Gonna keep working on that 10 byte solution for a while. Aug 8, 2016 at 14:18

## Actually, 28 bytes, Score = 0.39285714 (11/28) (cracked)

2√;;4*;u@D))u(*,;)@ⁿ)1-*ⁿ@-½


Computes A048696 (offset = 0). Actually uses CP437 for its encoding.

Try it online!

Dennis's solution is actually almost identical to mine:

19,;τ(+nX (Dennis)
19(;)τ+nX (Mine)


A Levenshtein distance of 3 is pretty impressive!

Try it online!

• cracked Aug 14, 2016 at 22:25

# Jelly, 22 bytes, score 0.2727 (6 / 22) [cracked]

‘ðḤ;+;c2\×P:+’×\$¥µÐ€‘S


This calculates sequence A116881. Try it online!

• Cracked Aug 19, 2016 at 18:35

## Pip, 24 bytes, score = 22 / 24 = 0.9166 (cracked)

Y53T++i>ay.:k.A(yi)A(ya)


Computes A109648 (offset = 0). Try it online!

My 22-byte version:

T++v>alPB A(lJk|5v)l@a

• Cracked Aug 19, 2016 at 22:21

# 05AB1E, 7 bytes, score = 0.857 (6 / 7) [cracked]

This one shouldn't be too hard if you think about it :p. Code:

L!zO¹!*


Computes A002627.

• Cracked Aug 20, 2016 at 20:40

## Acc!!, 523 bytes, score = 0.55067 (288/523) (cracked)

Second try, slightly different sequence.

N
Count x while _%60-46 {
(_+_%60*5-288)*10+N
}
_/60
Count i while _/27^i {
_+27^i*(_/27^i*26-18)
}
_*3+93
Count i while _/27^i/27%3 {
_-i%2*2+1
Count j while _/3^(3*j+2-i%2)%3 {
_+3^(1+i%2)
Count k while _/3^(3*k+1+i%2)%3-1 {
_+3^(3*k+1+i%2)*26
}
}
}
Count i while _/27^i/3 {
_-_/27^i/3%27*27^i*3+_/3^(3*i+1+_%3)%3*3
}
_/3
Count i while _/100^i {
_*10-_%100^i*9
}
Count i while _/100^i/10 {
_+_/100^i/10%10
Count j while i+1-j {
_+(_%10-_/100^(j+1)%10)*(100^(j+1)-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}


Computes A000032, Lucas numbers with offset 0.

Due to Acc!!'s input limitations, the program takes input as a decimal number terminated with a period (.); for example:

> python acc.py Program.txt
5.
11


This program has exponential time complexity, so I wouldn't recommend running it with input greater than about 14 (takes 60 seconds on my laptop). However, given enough time, the algorithm will return the correct result for any positive integer n. Thus: a crack attempt that places any size limits on the input value is invalid.

• cracked Aug 21, 2016 at 4:14

## Acc!!, 522 bytes, score = 0.5555 (290 ÷ 522) (cracked)

Third try. Thanks to Dennis for the golfing "help" with the first two. ;^)

N
Count x while _%60-46 {
(_+_%60*5-288)*10+N
}
_/60*2
Count i while _/27^i {
_+(_/27^i*26-18)*27^i
}
_*3+93
Count i while _/27^i/27%3 {
_-i%2*2+1
Count j while _/3^(3*j+2-i%2)%3 {
_+3+i%2*6
Count k while _/3^(3*k+1+i%2)%3-1 {
_+27^k*3^(i%2)*78
}
}
}
Count i while _/27^i/3 {
_-_/27^i/3%27*27^i*3+_/3^(3*i+1+_%3)%3*3
}
_/3
Count i while _/100^i {
_*10-_%100^i*9
}
Count i while _/100^i/10 {
_+_/100^i/10%10
Count j while i+1-j {
_+(_%10-_/100^(j+1)%10)*(100^(j+1)-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}


Computes A005248, Lucas(2*n), offset = 0.

Due to Acc!!'s input limitations, the program takes input as a decimal number terminated with a period (.); for example:

> python acc.py Program.txt
3.
18


This program has exponential time complexity, so I wouldn't recommend running it with input greater than about 7. However, given enough time, the algorithm will return the correct result for any positive integer n. Thus: a crack attempt that places any size limits on the input value is invalid.

• cracked Aug 21, 2016 at 5:38

# Excel, 16 bytes, score = 0.75, [cracked by Dennis♦]

=FACTDOUBLE(2*n)


Computes A000165: double factorial of even numbers, (offset = 0).

• Cracked? Aug 21, 2016 at 8:09
• This answer doesn't have the correct form -- it is not a program or a function. Aug 21, 2016 at 14:22
• @feersum By the definition here, it is a program Aug 21, 2016 at 14:30
• See here. Input by inserting the number into the source code isn't an accepted input method. Aug 21, 2016 at 14:35
• @feersum Name the cell input as n. See this Aug 21, 2016 at 15:00

# INTERCAL, 85 bytes Score: 77/85=0.90588, safe.

Input: up to SIX FIVE FIVE THREE FIVE, although actual calcuatable input is smaller than that.

This calculates A000217.

PLEASEWRITEIN.1PLEASE.2<-#1DO(1000)NEXTDO.2<-.3DO(1030)NEXTDO.3<-.3~#65534DOREADOUT.3


Try it online!

77 bytes.

PLEASEWRITEIN.2PLEASE.1<-.2DO(1020)NEXTDO(1030)NEXTDO.3<-.3~#65534DOREADOUT.3


C-INTERCAL has a subroutine that just increments .1, which is (1020).

Try it online!

• I'm on UTC+9, so would I be safe at 20:48 here?
– user100411
Sep 23, 2021 at 2:07
• Calcuable up to TWO FIVE FIVE
– user100411
Sep 23, 2021 at 2:15

# Python, 39 bytes, 26/39=2/3=0.666 cont. points, cracked

s=lambda x:x+s(x-1)if x==1else x+s(x-1)


won't last long, but lets see just how long. Just doing the robbers a favour I guess (also because I don't know eso golf langs ;_;)

umm, I accidentally bad code but someone cracked my lower score so...

computes A000217

• How does this terminate if the then clause and the end clause are the same? Aug 6, 2016 at 12:02
• Which version of Python is this? Aug 6, 2016 at 12:04
• Aug 6, 2016 at 12:05
• You need to include the score in the header :3. Aug 6, 2016 at 12:07
• also o sh*t I did the wrong code :( Aug 6, 2016 at 12:15

## Python, 69 bytes, score = 0.97 (67÷69), cracked

f=lambda n:reduce(lambda x,y:x*y,range(1,n+1),1)
lambda n:f(n*2)/f(n)


Computes A001813

• cracked Aug 9, 2016 at 19:28

# 05AB1E - 1 byte - A000027

Code: I

# 05AB1E - 0 bytes - A000027

Code:

Explanation:

I means that it pushes the input to the stack.

means that nothing is changed to the stack, but the input was already added to the stack by default, so it prints out the input.

• Please note this challenge has been inactive for 2 years. Oct 14, 2018 at 11:22
• Oh I thought that there was a proposal to revive old challenges Oct 14, 2018 at 13:52