# Robbers section

The cops section can be found here.

### Challenge

Your task is to outgolf the submissions of the cops in the same language and the same version (for example, Python 3.5Python 3.4, so that is not allowed). A submission is outgolfed when the length in bytes is shorter than the original submission. You only need to golf off at least 1 byte in order to crack a submission. E.g. if the task was to perform 2 × n, and the submission was the following:

print(2*input())


You could outgolf the cop by doing the following:

print 2*input()


Or even this (since lambda's are allowed):

lambda x:2*x


Post this with the following header:

##{language name}, <s>{prev byte count}</s> {byte count}, {cop's submission + link}


For example:

lambda x:2*x


Computes A005843, (offset = 0).

In that case, you have cracked the submission.

### Scoring

The person with who cracked the most submissions is the winner.

### Rules

• The crack submission must be in the same language as the cop submission.
• The same input should result into the same output (so a(2) = 4 should remain 4).
• For languages such as Python, you can import libraries that are standard included within the language. (So, no numpy/sympy etc.)
• Input and output are both in decimal (base 10).

Note

This challenge is finished. The winner of the Robbers section is feersum. The final scores for the CnR are shown below:

• feersum: 16 cracks
• Dennis: 12 cracks
• Leaky Nun: 6 cracks
• Lynn: 4 cracks
• miles: 3 cracks
• Martin Ender: 2 cracks
• Emigna: 2 cracks
• jimmy23013: 1 crack
• Sp3000: 1 crack
• randomra: 1 crack
• alephalpha: 1 crack
• nimi: 1 crack
• Destructible Watermelon: 1 crack
• Dom Hastings: 1 crack

## Pip, 24 22 bytes, DLosc

Y5T#y>aY(A_My)JkyA(ya)

• You know, the approach of regenerating the string each time never occurred to me. Now let me golf your golf: Y5T#y>aY A*yJkA(ya) for 19 bytes. Very nice! – DLosc Aug 20 '16 at 2:40

## J, 12 11 bytes, miles

##.>:@I.@#:


+/ for summing an array behaves poorly with regards to vectorization, so I tried to use base 1 instead. # happened to work for a 1-byte verb that results in 1 when called on a scalar.

• You're on a roll! Clever trick to sum using base 1. My solution was +/@(*#\)@#:. – miles Sep 9 '16 at 20:02

## Python 3.5, 38 36 bytes, R. Kap

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


Even if you don't accept True as 1, this is good enough.

• Nice job, although you were not able to get it as short as my shortest version. – R. Kap Aug 6 '16 at 18:45
• @R.Kap I did not attempt to as it provides no benefit in this challenge. – feersum Aug 6 '16 at 18:46
• Yeah, that's true. – R. Kap Aug 6 '16 at 18:46
• Slightly shorter: G=lambda n:0**n or(2*n-1)**2*G(n-1) (35 bytes) - I am over a year too late though :P – user74686 Sep 27 '17 at 19:26

# J, 10 9 bytes, Leaky Nun

-:*1-~3*]


Just shifted the operators around.

• Not my intended solution, but nice. – Leaky Nun Aug 7 '16 at 4:25
• A numberless version: -:*-.-~+:. – randomra Aug 7 '16 at 9:34

# J, 9 7 bytes, Leaky Nun

2&o.t.]


This is a monadic verb; it computes the yth term of the Taylor series of the cosine function (2&o.).

### Example run

   f =: 2&o.t.]
f each 0 1 2 3 4 5 6 7
┌─┬─┬──┬─┬─┬─┬──┬─┐
│1│0│_1│0│1│0│_1│0│
└─┴─┴──┴─┴─┴─┴──┴─┘

• I think I need it. (2&o.t.) 2 returns _0.5. – Dennis Aug 7 '16 at 4:24
• This was close to my solution. – Leaky Nun Aug 7 '16 at 4:26
• Aren't we looking for the sign of the coefficient, so something like *2&o.t.]? – George V. Williams Aug 7 '16 at 4:33
• @GeorgeV.Williams All coefficients of the Taylor series of cos are one of -1, 0 and 1. The coefficient is equal to its sign. – Dennis Aug 7 '16 at 4:35
• @Dennis, are you sure? On my interpreter, e.g. 2&o.t.]4 gives 0.0416667. – George V. Williams Aug 7 '16 at 4:41

# Java, 53 51 bytes, JollyJoker

int f(int n){return n<2?3-3*n:n<3?2:f(n-2)+f(n-3);}


Combines the first two if statements into 3-3*n for n less than 2.

• Ah, finally got commenting privileges. I didn't come up with the '3-' trick myself; that makes it a lot easier! Updated the original with some comments and a 47-byte version combining both 3- and % to get 0,1,2 to 3,0,2 in seven bytes, 3-3*n%5 – JollyJoker Aug 8 '16 at 12:20

## Retina, 28 27 bytes, Martin Ender

.+
$* ((^.?|\3)(^|\1)){99}$


Where it says {99} I wanted to use +, but that mysteriously causes the match to fail.

The regex matches strings which have a length that is a sum of a prefix of the Fibonacci numbers. The main group matches lengths starting with 1, 2, 3, ..., which skips one of the initial 1s, so I tried to improve it by getting it to match length 1 twice at the beginning, so that it was not necessary to have a special case.

## 05AB1E, 13 12 bytes, Adnan

µ•vÉ•DNìÙ{Q½


Try it online

• Okay, that is clever. I didn't think of that :p. – Adnan Aug 8 '16 at 14:19
• Alternative 12 byte solution µNðì•vÉ•-gi¼ – Emigna Aug 8 '16 at 15:28

## Python 3, 77 40 bytes, Joe

g=lambda n,c=1:+(n==0 or n>0<g(n-c,c+1))


# MarioLANG, 87 86 bytes, Business Cat

Don't know how I did it, but here it is I think

;
)-)+(< >>(
-)===" ""====
>>+([!)( >-(
"====#[(("==+[
!-) - <!!![)<<)
#======###====:

• Oh damn, didn't see that it was possible to get only one byte off... I'll post my 73-byte solution in my submission for interest's sake :) – Business Cat Aug 9 '16 at 12:38

## CoffeeScript, 83 50 bytes, DerpfacePython

s=(n)->0|r<0||Array(0|(n/9)+2).join ((n-1)%9+1)+''


Tested via http://coffeescript.org/.

• Whoa. That was... 10 minutes? Yikes, I suck at code golf. So, can you explain what the code does? Or is that just a naïve fix of what I did? – clismique Aug 9 '16 at 11:44
• Wow, that really is convenient timing... well, I'll keep those tricks in mind. Thanks! – clismique Aug 9 '16 at 12:04

# Python, 69 32 bytes, HiggsBot

f=lambda n:0**n or(4*n-2)*f(n-1)


Test it on Ideone.

Two bytes saved by @xnor. Thanks! Two more could be saved by returning True instead of 1.

• Not that it matters, but there's 4*n-2. – xnor Aug 9 '16 at 19:35
• Not sure how I missed that. Thanks! – Dennis Aug 9 '16 at 19:36

# Actually, 28 11 bytes, Mego

19,;τ(+nX


Try it online!

### How it works

This uses the recursive definition from A048696: a(0) = 1, a(1) = 9, a(n) = 2a(n-1) + a(n-2).

19           Push 1 and 9 on the stack.
,          Read n from STDIN and push it on the stack.
    n   Do the following n times:
;          Push a copy of the topmost integer.
τ         Multiply it by 2.
(        Rotate the bottom-most integer on top of the stack.
+       Add the two topmost integers.
Each iteration turns the stack [a(k-2) a(k-1)] into [a(k-1) a(k)].
After n iterations, we are left with [a(n) a(n+1)].
X  Discard a(n+1) from the stack.


## 05AB1E, 7 6 bytes, Adnan

!¹L!/O


or

!žr<*ï


Note that both of these return 1 for 0, but so did the cop program.

• Oh nice! I really thought I had covered the n = 0 case :p. I had Î>GN*>, which does work for n = 0. – Adnan Aug 20 '16 at 20:44
• @Adnan: Nice one. – Emigna Aug 20 '16 at 20:48

# Acc!!, 522 514 bytes, DLosc

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+2-j {
_+(_%10-_/100^j%10)*(100^j-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}


Not so tiny improvement this time, but I still have no idea what I'm doing.

28,29c28,29
< Count j while i+1-j {
< _+(_%10-_/100^(j+1)%10)*(100^(j+1)-1)
---
> Count j while i+2-j {
> _+(_%10-_/100^j%10)*(100^j-1)


Since (100^j-1) is zero when j = 0, we can loop over the range [0, ..., i + 2) instead of looping over [0, ..., i + 1) and incrementing j. This saves eight bytes.

# Python, 46 45 bytes, Sp3000

f=lambda n,k=1:n and-~f(n-(k+(k&-k)&k>0),k+1)


Test it on Ideone.

# Excel, 16 12 bytes, Anastasiya-Romanova 秀

=FACT(n)*2^n


I don't actually have Excel, but from what I read online, this should work.

• This doesn't work: i.imgur.com/NUDGujV.png – Mego Aug 21 '16 at 8:20
• Not yet :-) – Anastasiya-Romanova 秀 Aug 21 '16 at 8:33
• Change n*n to 2^n – Emigna Aug 21 '16 at 10:01
• Eh, mixed up n^2 and 2^n, and I wasn't sure if Excel had ^. That's what happens when you try to do math at 4 AM... Thanks, @Emigna. – Dennis Aug 21 '16 at 15:30
• @Anastasiya-Romanova秀 Fixed. – Dennis Aug 21 '16 at 15:30

## M, 18 17 bytes, Dennis

Tragically, Dennis has missed a trivial modification this time. Only the first line is different.

Ḥrc
‘Ḥc0r\$×Ç:‘+\S

• facepalm Well done. – Dennis Aug 21 '16 at 16:18

# Acc!!, 512 511 bytes, DLosc

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 {
_+3^(3*k+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
}


This is the improvement.

15c15
< _+27^k*3^(i%2)*78
---
> _+3^(3*k+i%2)*78


## J, 18 13 bytes, miles

(2&-%-.-*:)t.


I checked the shortest most popular J answer for Fibonacci numbers: a generating function. Unsurprisingly, the same approach is also good for Lucas numbers.

• Exactly what I had in mind. – miles Sep 29 '16 at 1:11

## JavaScript(ES6), 77 76, user81655

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


Just a 1-byte peephole golf.

# Acc!!, 523 521 bytes, DLosc

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+i%2*6
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
}


I have no idea how this works, but I was able to spot a tiny improvement.

13c13
< _+3^(1+i%2)
---
> _+3+i%2*6

• Back to the drawing board! – DLosc Aug 21 '16 at 4:24