43
\$\begingroup\$

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:

Python 2, 16 12 bytes, Adnan (+ link to submission)

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
\$\endgroup\$
0

52 Answers 52

1
2
3
\$\begingroup\$

Pip, 24 22 bytes, DLosc

Y5T#y>aY(A_My)JkyA(ya)
\$\endgroup\$
1
  • \$\begingroup\$ 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! \$\endgroup\$
    – DLosc
    Commented Aug 20, 2016 at 2:40
3
\$\begingroup\$

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.

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

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.

\$\endgroup\$
4
  • \$\begingroup\$ Nice job, although you were not able to get it as short as my shortest version. \$\endgroup\$
    – R. Kap
    Commented Aug 6, 2016 at 18:45
  • \$\begingroup\$ @R.Kap I did not attempt to as it provides no benefit in this challenge. \$\endgroup\$
    – feersum
    Commented Aug 6, 2016 at 18:46
  • \$\begingroup\$ Yeah, that's true. \$\endgroup\$
    – R. Kap
    Commented Aug 6, 2016 at 18:46
  • \$\begingroup\$ 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 \$\endgroup\$
    – user74686
    Commented Sep 27, 2017 at 19:26
2
\$\begingroup\$

J, 10 9 bytes, Leaky Nun

-:*1-~3*]

Just shifted the operators around.

\$\endgroup\$
2
  • \$\begingroup\$ Not my intended solution, but nice. \$\endgroup\$
    – Leaky Nun
    Commented Aug 7, 2016 at 4:25
  • 1
    \$\begingroup\$ A numberless version: -:*-.-~+:. \$\endgroup\$
    – randomra
    Commented Aug 7, 2016 at 9:34
2
\$\begingroup\$

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│
└─┴─┴──┴─┴─┴─┴──┴─┘
\$\endgroup\$
6
  • \$\begingroup\$ I think I need it. (2&o.t.) 2 returns _0.5. \$\endgroup\$
    – Dennis
    Commented Aug 7, 2016 at 4:24
  • \$\begingroup\$ This was close to my solution. \$\endgroup\$
    – Leaky Nun
    Commented Aug 7, 2016 at 4:26
  • \$\begingroup\$ Aren't we looking for the sign of the coefficient, so something like *2&o.t.]? \$\endgroup\$ Commented Aug 7, 2016 at 4:33
  • \$\begingroup\$ @GeorgeV.Williams All coefficients of the Taylor series of cos are one of -1, 0 and 1. The coefficient is equal to its sign. \$\endgroup\$
    – Dennis
    Commented Aug 7, 2016 at 4:35
  • \$\begingroup\$ @Dennis, are you sure? On my interpreter, e.g. 2&o.t.]4 gives 0.0416667. \$\endgroup\$ Commented Aug 7, 2016 at 4:41
2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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 \$\endgroup\$
    – JollyJoker
    Commented Aug 8, 2016 at 12:20
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

05AB1E, 13 12 bytes, Adnan

µ•vÉ•DNìÙ{Q½

Try it online

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

Python 3, 77 40 bytes, Joe

g=lambda n,c=1:+(n==0 or n>0<g(n-c,c+1))
\$\endgroup\$
2
\$\begingroup\$

MarioLANG, 87 86 bytes, Business Cat

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

;
)-)+(< >>(
-)===" ""====
>>+([!)( >-(
"====#[(("==+[
!-) - <!!![)<<)
#======###====:
\$\endgroup\$
1
  • \$\begingroup\$ 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 :) \$\endgroup\$ Commented Aug 9, 2016 at 12:38
2
\$\begingroup\$

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/.

\$\endgroup\$
2
  • \$\begingroup\$ 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? \$\endgroup\$
    – clismique
    Commented Aug 9, 2016 at 11:44
  • \$\begingroup\$ Wow, that really is convenient timing... well, I'll keep those tricks in mind. Thanks! \$\endgroup\$
    – clismique
    Commented Aug 9, 2016 at 12:04
2
\$\begingroup\$

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.

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

05AB1E, 7 6 bytes, Adnan

!¹L!/O

or

!žr<*ï

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

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

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ This doesn't work: i.imgur.com/NUDGujV.png \$\endgroup\$
    – user45941
    Commented Aug 21, 2016 at 8:20
  • \$\begingroup\$ Not yet :-) \$\endgroup\$ Commented Aug 21, 2016 at 8:33
  • \$\begingroup\$ Change n*n to 2^n \$\endgroup\$
    – Emigna
    Commented Aug 21, 2016 at 10:01
  • \$\begingroup\$ 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. \$\endgroup\$
    – Dennis
    Commented Aug 21, 2016 at 15:30
  • \$\begingroup\$ @Anastasiya-Romanova秀 Fixed. \$\endgroup\$
    – Dennis
    Commented Aug 21, 2016 at 15:30
2
\$\begingroup\$

M, 18 17 bytes, Dennis

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

Ḥrc
‘Ḥc0r$×Ç:‘+\S
\$\endgroup\$
1
  • \$\begingroup\$ facepalm Well done. \$\endgroup\$
    – Dennis
    Commented Aug 21, 2016 at 16:18
2
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Exactly what I had in mind. \$\endgroup\$
    – miles
    Commented Sep 29, 2016 at 1:11
1
\$\begingroup\$

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.

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

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.
\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
  • \$\begingroup\$ Back to the drawing board! \$\endgroup\$
    – DLosc
    Commented Aug 21, 2016 at 4:24
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.