Can you outgolf me? (Robbers section)

44

3

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

Adnan

Posted 2016-08-06T10:29:09.393

Reputation: 41 965

Answers

9

Cheddar, 7 6 bytes, Downgoat

(<<)&1

This seems to work, but it's always possible that I don't understand the language correctly.

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

Alternatively, (**)&2. I tried 2&(**) and failed. :( – Dennis – 2016-08-07T04:19:56.700

@Dennis (**)&2 works just fine for me :/ but this also works. – Downgoat – 2016-08-07T05:12:10.977

14

Jelly, 5 4 bytes, George V. Williams

RÆḊḞ

Try it here.

A hidden feature!

If I remembered correctly, ÆḊ(A) = sqrt(det(AAT)) is n! times the n dimensional Lebesgue measure of a simplex formed by n input point and the origin in m dimensional space. When n=1 it degenerate to the Euclidean distance. Not that weird after all...

jimmy23013

Posted 2016-08-06T10:29:09.393

Reputation: 34 042

1Right, I did something weird with determinants... So well hidden that I couldn't find it myself! – Dennis – 2016-08-08T01:14:46.853

@Dennis I know this because someday I tried to extend determinant too, and that's what you get if you want it to work as cross product. But it took me long because I thought it might be weird too and didn't expect someone come up with the same thing... – jimmy23013 – 2016-08-08T01:21:54.317

Can these really be considered "bytes?" The code points for and are in the UTF-16 range. That'd make this solution 6 bytes assuming heterogeneous encoding, and 8 bytes assuming homogeneous encoding. Asking honestly here. – Jules – 2016-08-09T18:44:18.650

@Jules https://github.com/DennisMitchell/jelly/wiki/Code-page

– jimmy23013 – 2016-08-09T19:14:26.620

12

Hexagony, 91 33 bytes, Blue

1""?{\>{+/</+'+./_'..@'~&/!}'+=($

Unfolded:

    1 " " ?
   { \ > { +
  / < / + ' +
 . / _ ' . . @
  ' ~ & / ! }
   ' + = ( $
    . . . .

Try it online!

Still looks somewhat golfable but I figured I'd post it before FryAmTheEggman beats me to it. ;)

Explanation

Here are some colour-coded execution paths:

enter image description here

However, these are unnecessarily convoluted due to golfing. Here is the exact same code with a saner layout:

enter image description here

That's better. And finally, here is a memory diagram, where the red arrow indicates the initial position and orientation of the memory pointer (MP):

enter image description here

The gist is that I'm iteratively computing Fibonacci numbers on the three edges labelled f(i), f(i+1) and f(i+2) while keeping track of the iterator on the edges A, B and C. While doing so the roles of these edges are swapped out cyclically after each iteration. Let's see how this happens...

The code starts on the grey path which does some initial setup. Note that f(i) already has its correct initial value of 0.

1   Set edge f(i+1) to 1.
""  Move the MP to edge A.
?   Read input n into edge A.
)   Increment n.

Now the green path is the main loop. _ and > are just mirrors.

(     Decrement n.
<     If the result is zero or less, continue on the red path, otherwise
      perform another iteration of the main loop.
{     Move the MP to edge f(i+2).
+     Add edges f(i) and f(i+1) into this edge, computing the next Fibonacci number.
'     Move the MP to the edge opposite A.
~     Multiply by -1 to ensure that it's non-positive (the edge may have a positive
      value after a few iterations).
&     Copy the current value of n from A.
'     Move back and to the right again.
+     Copy n by adding it to zero. Since we know that the other adjacent edge
      is always zero, we no longer need to use ~&.
'+'+  Repeat the process twice, moving n all the way from A to B.
=     Reverse the orientation of the MP so that it points at f(i) which now
      becomes f(i+2) for the next iteration.

This way, the MP moves around the inner triplet of edges, computing successive Fibonacci numbers until n reaches zero. Then finally the red path is executed:

{}    Move the MP to f(i).
!     Print it.
@     Terminate the program.

Diagrams generated with Timwi's HexagonyColorer and EsotericIDE.

Martin Ender

Posted 2016-08-06T10:29:09.393

Reputation: 184 808

Holy cow! I was expecting to be beaten by you but not my that much! 0.o – Blue – 2016-08-07T20:43:12.223

@Blue Are you planning to add an explanation to yours? I'd be interested in how that one works. :) I'll add an explanation to this one as well sooner or later, but I'm not sure I'll find the time today. – Martin Ender – 2016-08-07T20:47:31.140

Yeah, mine uses a more traditional method of calculation. I completely forgot about &, that could have saved some bytes – Blue – 2016-08-07T20:51:23.687

7

Haskell, 5 4 bytes, xnor

(^)1

Simple currying.

Leaky Nun

Posted 2016-08-06T10:29:09.393

Reputation: 45 011

7

Stack Cats, 14 13 bytes, feersum

^]T{_+:}_

with the -nm flags for +4 bytes. Try it online!

Okay, that loop was nuts. I tried several approaches, such as brute forcing over a reduced alphabet and brute forcing 3x+2 or 5x+4 and trying to extend it, but I never expected the solution to actually contain a loop.

The best way to see how this works is to add a D flag for debugging (so run with -nmD) and turn debug on for the above TIO link. A {} loop remembers the top of stack at the beginning of the loop, and exits when the top of stack is that value again. The interior of the loop does some fun subtracting and cycling of the top three elements of the stack, which is how the loop gets to run for so many iterations.

Sp3000

Posted 2016-08-06T10:29:09.393

Reputation: 58 729

6

Sesos, 14 11 bytes, Leaky Nun

Computes n2. Try it here.

Hex dump:

0000000: 16c0f7 959d9b 26e83e ce3d                         ......&.>.=

From assembly:

set numin
set numout
get
jmp
  jmp, sub 1, fwd 1, add 1, fwd 1, add 2, rwd 2, jnz
  fwd 2, sub 1
  rwd 1, sub 1
  jmp, sub 1, rwd 1, add 1, fwd 1, jnz
  rwd 1
jnz
fwd 2
put

Lynn

Posted 2016-08-06T10:29:09.393

Reputation: 55 648

Nice, you're even shorter than my original golfed version. – Leaky Nun – 2016-08-06T11:34:17.047

This computes 1 + 3 + … + (2n–1) instead of n × n :) – Lynn – 2016-08-06T11:35:10.043

I also used your approach – Leaky Nun – 2016-08-06T11:36:31.047

6

Woefully, 776 759 bytes, Destructible Watermelon

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

I tried to read the source code for this language but it was too confusing. For one thing, ip[1] is a line number while ip[0] is the column number, while the cp coordinates are used the other way around. Yet, sometimes the value of cp is assigned to ip. I gave up on trying to understand what the program is doing and found a way to encode the identical sequence of instructions using fewer bars.

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

5

Brachylog, 27 21 bytes, Fatalize

yrb:1a:+a:[1]c*.
:2/.

Try it online!

Leaky Nun

Posted 2016-08-06T10:29:09.393

Reputation: 45 011

Well done! Using integer division is definitely not the solution I had in mind (which is still shorter), didn't even think about it tbh :p – Fatalize – 2016-08-06T18:38:17.410

5

J, 17 12 bytes, miles

+/@(]!2*-)i:

Pretty much the same as the original just more golfed. :)

i: having +1 range compared to i. is useful (and weird). If you use i. here n=0 will be incorrect but luckily i: solves that.

Try it online here.

randomra

Posted 2016-08-06T10:29:09.393

Reputation: 19 909

Neat trick with i: being zeros for negative values. My version was +/@(]!2*-)i.,]. – miles – 2016-08-06T21:03:39.230

5

M, 10 6 bytes, Dennis

R×\³¡Ṫ

Given n, it computes the nth-level factorial of n. This was a fun exercise!

The code is capable of running as Jelly so you can Try it online.

Explanation

R×\³¡Ṫ  Input: n
R       Create the range [1, 2, ..., n]
   ³¡   Repeat n times starting with that range
 ×\       Find the cumulative products
     Ṫ  Get the last value in the list
        Return implicitly

miles

Posted 2016-08-06T10:29:09.393

Reputation: 15 654

5

Snowman, 50 44 bytes, Doorknob

((}#2nMNdE0nR1`wRaC2aGaZ::nM;aF;aM:`nS;aF*))

Try it online!

Lynn

Posted 2016-08-06T10:29:09.393

Reputation: 55 648

Very nice. Even shorter than the original, which was ((}#1nG|#2nMNdE0nR2aGaZ::nM;aF;aM:nS;aF,nM*)). – Doorknob – 2016-08-10T16:00:02.550

5

Haskell, 15 14 bytes, xnor

until odd succ

I spent a fruitless couple of hours learning to decipher "pointless" syntax... until I found this instead.

Or for a less mellifluous 13 bytes, until odd(+1).

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

Nicely done, this is what I had in mind. I like the three words. – xnor – 2016-09-08T02:28:20.513

4

Python 2, 43 40, xsot

g=lambda n:n<2or-~sum(map(g,range(n)))/3

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

Interesting, this is different from what I had originally. – xsot – 2016-08-07T00:23:57.063

4

Pyke, 11 9 bytes, muddyfish

hVoeX*oe+

Try it here!

How it works

          Implicit input: n (accumulator), n (iterations)
h         Increment the number of iterations.
 V        Do the following n + 1 times.
  o         Iterator. Pushes its value (initially 0) and increments it.
   e        Perform integer division by 2.
            This pushes 0 the first time, then 1, then 2, etc.
    X       Square the result.
     *      Multiply the accumulator and the result.
      oe    As before.
        +   Add the result to the accumulator.
            This sets the accumulator to a(0) = 0 in the first iteration and
            applies the recursive formula in all subsequent ones.

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

Using that method you can get 8 with hV~oX*o+. My 5 byte answer was SDmX^ – Blue – 2016-08-08T05:39:41.120

Ah, ~o is neat. I have no idea what SDmX^ does though. – Dennis – 2016-08-08T05:48:38.753

It basically uses mixed base conversation on the 1-indexed range against that squared. Not something on OEIS – Blue – 2016-08-08T05:50:47.050

Oh, does m only affect the X and not the ^? That explains a lot. – Dennis – 2016-08-08T05:53:27.903

Yeah, m and similar only use the next node. Any comments on my docs etc? – Blue – 2016-08-08T05:55:18.033

4

05AB1E, 7 4, Emigna

LnOx

From the formula for the sum of squares of positive integers 1^2 + 2^2 + 3^2 + ... + n^2 = n(n+1)(2*n+1)/6, if we multiply both sides by 2 we get Sum_{k=0..n} 2*k^2 = n(n+1)(2*n+1)/3, which is an alternative formula for this sequence. - Mike Warburton (mikewarb(AT)gmail.com), Sep 08 2007

alephalpha

Posted 2016-08-06T10:29:09.393

Reputation: 23 988

I'm happy you cracked it at 4 since there was a trivial modification of my public one I'd missed. Nice! – Emigna – 2016-08-08T12:59:58.163

4

Jelly, 22 21 bytes, Dennis

_²×c×Ḥc¥@÷⁸÷’{S
‘µR+ç

I spent several hours reading Jelly source code for the last one, so I might as well put this "skill" to use. I hope @Dennis will share with us his mathematical discoveries allowing a shorter formula (assuming there is something and not only weird Jelly tricks!).

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

For comparison, I had: `‘Ḥc_×c@+¥\nr0ç@€:‘+\S

– Sp3000 – 2016-08-19T19:07:50.130

@Sp3000 Oh, well why didn't you post it? – feersum – 2016-08-19T19:40:05.330

More time to think about the 6 before Dennis reposts in M :P – Sp3000 – 2016-08-19T20:10:55.347

4

J, 20 19 bytes, miles

[:+/2^~+/@(!|.)\@i.

This computes the product as a sum of squared Fibonacci numbers, which are calculated as a sum of binomial coefficients.

Thankfully, @miles himself posted the code to generate Fibonacci numbers in this comment.

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

4

Acc!!, 526 525 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^(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
}

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

24c24
< _+_/100^i*100^i*9
---
> _*10-(_%100^i)*9

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

Ah, shoot. I was hoping no one would catch a math golf that I missed. +1 – DLosc – 2016-08-20T22:34:43.057

4

Haskell, 10 bytes, xnor

gcd=<<(2^)

Usage example: map ( gcd=<<(2^) ) [1..17] -> [1,2,1,4,1,2,1,8,1,2,1,4,1,2,1,16,1].

How it works: From the oeis page we see that a(n) = gcd(2^n, n) or written in Haskell syntax: a n = gcd (2^n) n. Functions with the pattern f x = g (h x) x can be turned to point-free via the function =<<: f = g =<< h, hence gcd=<<(2^) which translates back to gcd (2^x) x.

nimi

Posted 2016-08-06T10:29:09.393

Reputation: 34 639

............... How – TuxCrafting – 2016-10-22T23:12:54.137

3

Sesos, 14 9 bytes, Leaky Nun

Computes n mod 16. Try it here.

Hex:

0000000: 17f84a 750e4a 7d9d0f                              ..Ju.J}..

Assembly:

set numin
set numout
set mask
get
jmp, sub 1, fwd 1, add 16, rwd 1, jnz
fwd 1
jmp, sub 16, fwd 1, add 1, rwd 1, jnz
fwd 1
put

Lynn

Posted 2016-08-06T10:29:09.393

Reputation: 55 648

This is precisely my solution :D – Leaky Nun – 2016-08-06T12:03:33.347

3

Leaky Nun

Posted 2016-08-06T10:29:09.393

Reputation: 45 011

actually really good, I'm actually glad at being outgolfed to see this solution – Destructible Lemon – 2016-08-06T12:17:22.583

Why complicate a simple formula with the right shift? – xsot – 2016-08-06T12:29:01.267

@xsot Because I didn't know what version he used. – Leaky Nun – 2016-08-06T12:54:01.073

3

05AB1E, 9 4 bytes, Emigna

>n4÷

Try it online!

Computes this function instead:

formula

Leaky Nun

Posted 2016-08-06T10:29:09.393

Reputation: 45 011

3

Hexagony, 7 6 bytes, Adnan

?!/$(@

Unfolded:

 ? ! 
/ $ (
 @ .

Try it online!

Same idea, slightly different layout.

Martin Ender

Posted 2016-08-06T10:29:09.393

Reputation: 184 808

Ahhh, very nice! That was exactly the same solution :). – Adnan – 2016-08-06T15:28:32.317

3

MATL, 11 10 bytes, Luis Mendo

YftdAwg_p*

Instead of doing -1^length(array) it converts the elements to Boolean values (which are always 1), negates them, and takes the product of the elements.

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

3

Jelly, 11 10, Dennis

Ḥ’_Rc’*@RP

Vectorized version of same approach.

Try it online!

Leaky Nun

Posted 2016-08-06T10:29:09.393

Reputation: 45 011

3

Lynn

Posted 2016-08-06T10:29:09.393

Reputation: 55 648

Yeah, that was pretty dumb of me :p. I forgot that that has been an actual challenge.

– Adnan – 2016-08-07T19:04:01.497

µNÂʽ for 5 bytes. Presumably the secret version. – Emigna – 2016-08-07T21:06:42.693

3

Jelly, 9 8 bytes, Dennis

œċr0$L€Ḅ

Sorry! I wasn't able to find your intended solution.

This relies on the fact that C(n+k-1, k) is the number of ways to choose k values from n with replacement.

Note: This is inefficient since it generates the possible sets in order to count them, so try to avoid using large values of n online.

Try it online or Verify up to n.

I later found another 8 byte version that is efficient enough to compute n = 1000. This computes the values using the binomial coefficient and avoids generating the lists.

Ḷ+c’Ṛ;1Ḅ

Try it online or Verify up to n.

Explanation

œċr0$L€Ḅ  Input: n
  r0$     Create a range [n, n-1, ..., 0]
œċ        Create all combinations with replacement for
          (n, n), (n, n-1), ..., (n, 0)
     L€   Find the length of each
       Ḅ  Convert it from binary to decimal and return

Ḷ+c’Ṛ;1Ḅ  Input: n
Ḷ         Creates the range [0, 1, ..., n-1]
 +        Add n to each in that range
   ’      Get n-1
  c       Compute the binomial coefficients between each
    Ṛ     Reverse the values
     ;1   Append 1 to it
       Ḅ  Convert it from binary to decimal and return

miles

Posted 2016-08-06T10:29:09.393

Reputation: 15 654

3

Brachylog, 11 10 bytes, Fatalize

yb:AcLrLc.

Try it online!

Explanation

Brachylog is a Prolog-derived languages, whose greatest ability is to prove things.

Here, we prove these statements:

yb:AcLrLc.
yb:AcL       Inclusive range from 1 to input, concatenated with A, gives L
     LrL     L reversed is still L
       Lc.   L concatenated is output

Leaky Nun

Posted 2016-08-06T10:29:09.393

Reputation: 45 011

This is exacly the answer I had in mind, well done! – Fatalize – 2016-08-10T07:53:44.720

3

M, 9 8 bytes, Dennis

Ḥrc’ḊḄḤ‘

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

Nice idea with the double + increment – miles – 2016-08-14T08:40:12.770

3

QBasic, 30 29 bytes, DLosc

INPUT n:?(n MOD 2)*(n+.5)+n/2

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

Nice! (Though not quite what I had.) – DLosc – 2016-08-19T20:43:48.810

3

Pip, 24 22 bytes, DLosc

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

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

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 – 2016-08-20T02:40:42.977

3

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.

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

You're on a roll! Clever trick to sum using base 1. My solution was +/@(*#\)@#:. – miles – 2016-09-09T20:02:03.193

2

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.

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

Nice job, although you were not able to get it as short as my shortest version. – R. Kap – 2016-08-06T18:45:57.980

@R.Kap I did not attempt to as it provides no benefit in this challenge. – feersum – 2016-08-06T18:46:28.003

Yeah, that's true. – R. Kap – 2016-08-06T18:46:47.307

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 – None – 2017-09-27T19:26:53.193

2

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│
└─┴─┴──┴─┴─┴─┴──┴─┘

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

I think I need it. (2&o.t.) 2 returns _0.5. – Dennis – 2016-08-07T04:24:57.607

This was close to my solution. – Leaky Nun – 2016-08-07T04:26:54.013

Aren't we looking for the sign of the coefficient, so something like *2&o.t.]? – George V. Williams – 2016-08-07T04:33:01.210

@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 – 2016-08-07T04:35:23.123

@Dennis, are you sure? On my interpreter, e.g. 2&o.t.]4 gives 0.0416667. – George V. Williams – 2016-08-07T04:41:54.117

@GeorgeV.Williams This is meant to be a verb, so you'd have to call it like (2&o.t.]) 4 or by saving it in a variable. I'll add that to the post. – Dennis – 2016-08-07T04:43:47.420

2

J, 10 9 bytes, Leaky Nun

-:*1-~3*]

Just shifted the operators around.

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

Not my intended solution, but nice. – Leaky Nun – 2016-08-07T04:25:30.400

1A numberless version: -:*-.-~+:. – randomra – 2016-08-07T09:34:00.400

2

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.

miles

Posted 2016-08-06T10:29:09.393

Reputation: 15 654

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 – 2016-08-08T12:20:03.500

2

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.

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

2

05AB1E, 13 12 bytes, Adnan

µ•vÉ•DNìÙ{Q½

Try it online

Emigna

Posted 2016-08-06T10:29:09.393

Reputation: 50 798

Okay, that is clever. I didn't think of that :p. – Adnan – 2016-08-08T14:19:43.433

Alternative 12 byte solution µNðì•vÉ•-gi¼ – Emigna – 2016-08-08T15:28:12.293

2

Python 3, 77 40 bytes, Joe

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

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

2

MarioLANG, 87 86 bytes, Business Cat

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

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

Destructible Lemon

Posted 2016-08-06T10:29:09.393

Reputation: 5 908

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 – 2016-08-09T12:38:22.337

2

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

Dom Hastings

Posted 2016-08-06T10:29:09.393

Reputation: 16 415

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 – 2016-08-09T11:44:26.287

Wow, that really is convenient timing... well, I'll keep those tricks in mind. Thanks! – clismique – 2016-08-09T12:04:17.933

2

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.

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

1Not that it matters, but there's 4*n-2. – xnor – 2016-08-09T19:35:02.037

Not sure how I missed that. Thanks! – Dennis – 2016-08-09T19:36:39.580

2

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.

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

2

05AB1E, 7 6 bytes, Adnan

!¹L!/O

or

!žr<*ï

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

Emigna

Posted 2016-08-06T10:29:09.393

Reputation: 50 798

Oh nice! I really thought I had covered the n = 0 case :p. I had Î>GN*>, which does work for n = 0. – Adnan – 2016-08-20T20:44:07.483

@Adnan: Nice one. – Emigna – 2016-08-20T20:48:39.527

2

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.

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

2

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.

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

2

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.

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

This doesn't work: http://i.imgur.com/NUDGujV.png

– Mego – 2016-08-21T08:20:10.813

Not yet :-) – Anastasiya-Romanova 秀 – 2016-08-21T08:33:38.477

Change n*n to 2^n – Emigna – 2016-08-21T10:01:01.820

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 – 2016-08-21T15:30:25.797

@Anastasiya-Romanova秀 Fixed. – Dennis – 2016-08-21T15:30:52.793

@Dennis OK, (+1) – Anastasiya-Romanova 秀 – 2016-08-21T15:32:37.037

2

M, 18 17 bytes, Dennis

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

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

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

facepalm Well done. – Dennis – 2016-08-21T16:18:23.530

2

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

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

2

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.

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

Exactly what I had in mind. – miles – 2016-09-29T01:11:53.093

1

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.

feersum

Posted 2016-08-06T10:29:09.393

Reputation: 29 566

1

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

Dennis

Posted 2016-08-06T10:29:09.393

Reputation: 196 637

Back to the drawing board! – DLosc – 2016-08-21T04:24:24.703