We changed our privacy policy. Read more.

Hot answers tagged

34

Wolfram Language (Mathematica), 42 bytes Of course there is a built-in for this... And as @Charlie mentioned we can golf "Portuguese" to "Spanish" and save 3 bytes #~IntegerName~"Spanish"~StringTake~1=="d"& Try all test cases -13 bytes from @att


31

Python 2, 16 bytes lambda n:n<<n%-2 Try it online! The expression n%-2 equals 0 for even n and -1 for odd n. Bit-shifting n by 0 positions leaves it unchanged, but for -1 positions it gives an error for "negative shift count".


27

Haskell, 35 bytes x?y|isNaN$x/y=tanh x*tanh y|0<1=x/y Try it online! The relevant function is (?), which takes two Doubles as input and returns a Double as output. How? The hyperbolic tangent is an amazing function (two bytes shorter than signum!). x tanh x 0.0 0.0 -0.0 -0.0 Infinity 1.0 -Infinity -1.0 Haskell, 30 29 bytes x?y|x/y<=1/0=x/y|0<...


26

Scratch 3.0, 13 20 blocks/121 70 bytes As SB Syntax: define(n)(i say(i ((n)+<(i)=(n)>)((1)+((i)*<(i)<(n This says each term in the sequence. A delay can be added so that the numbers don't rapidly fire. I have never seen scratch so abused. You call the empty name function with empty parameters. My goodness. Whatever saves bytes! -51 thanks to @...


25

Jelly, 3 bytes MḂ¡ Try it online! (even) and Try it online! (odd) How it works M is an atom meaning "Given a list, yield the indices of that maximal elements". Now, typically, when given integer arguments to its array functions, Jelly promotes them to either a range, to digits, or just wraps it. Unfortunately, (I'm guessing due to M's age - it was ...


24

APL (Dyalog Unicode), 39 bytes +/⊢{∨/⍺⍵<⍵0:0⋄⍺=0:1⋄+/∊∇¨/⍺(⍵*2)-⊂⍳⍺}¨⍳ Try it online! A tacit function containing an inner dfn to use recursion. Does not use floating point numbers at all. How it works First of all, observe that $$ \displaystyle \sqrt{a_1+\sqrt{a_2 + \cdots + \stackrel{\vdots}{\sqrt{a_t}}}} \le \cdots \le \sqrt{a_1+a_2 + \cdots + a_t} \...


22

Haskell, 320…236 230 bytes length<$>iterate(\h->nub[r$x:y:u|u<-h,t<-u,x<-n t\\u,y<-n x\\u,([x,x,y]\\(u>>=n))/=[x,y]])[[l,0<$l]] r u=minimum[sort$(!!i).p.map(*j).m a<$>u|a<-u,j<-l,i<-[0..5]] n=(<$>p l).m m=zipWith(-) p=permutations l=[-1..1] import Data.List Try it online! An infinite list whose \$n\$-th ...


22

Hexagony, 13 bytes ?#\.@!:.!_@\| Try it online! Expanded: (Made using Hexagony Colorer) This code is built around Hexagony's # operator. Hexagony initializes with 6 IP's, 1 in each corner of the code box, with the 0th one, the one in the top left, being active in the beginning. The # operator takes the value of the current memory cell mod 6, and then sets ...


21

Python 3, 25 bytes lambda n:len(bin(n**n))-3 Try it online! If the answer is \$x\$, then \$x+1 > n\log{n} \ge x\$ holds true, which means \$2^{x+1} > n^n \ge 2^x\$. So we can simply count the number of bits in the binary representation of \$n^n\$.


20

Charcoal, 32 29 27 bytes ≔⁰θFS≔⁺×θX³℅ι℅ιθ‹³﹪θ⁸§1ijkθ Try it online! Link is to verbose version of code. Explanation: The values are encoded to integers equivalent to 0..7 (modulo 8) in the order 1, i, j, k, -1, -i, -j, -k. The multiplications by i, j and k have the following effect on the integer: Multiplying by i is equivalent to tripling the integer and ...


18

Python 3, 68 62 48 bytes -6 bytes thanks to xnor! -14 bytes thanks to Jitse! lambda n:' 11 'in f' {n:b} {n} '.replace('0','') Try it online!


18

Husk, 2 bytes ḣN Try it online! First Husk answer! Also uses the sequence in the question How it works ḣN - Main program N - The infinite list [1, 2, 3, ...] ḣ - Prefixes; [[1], [1, 2], [1, 2, 3], ...]


18

Wolfram Language (Mathematica), 33 bytes 2#2&@@#~BoundingRegion~"MinBall"& Try it online! Nearly exactly the same as the Mathematica answer to the 2D version. Works for input points of any dimension.


17

Python 2, 13 bytes Takes a positive integer \$ n \$ as input and returns the \$ n \$th term of the sequence. lambda n:n&-n Try it online! The largest power of \$ 2 \$ that divides \$ n \$ is also the lowest set bit. The bitwise magic is a bit difficult to explain, but it uses the fact that ~n + 1 in its binary representation produces the same lowest ...


17

Proof of impossibility The only anti-distributive operator when \$S=\mathbb Z\$ is such that \$\forall a, \forall b, a*b=0\$. Indeed, suppose that \$*\$ is anti-distributive. Then \$*\$ has the following property, for all \$ a,b,c\in\mathbb Z\$: (D) \$a*(b+c) = - (a*b+a*c)\$ (In my notation, \$*\$ has precedence over \$+\$.) Take \$a,b \in \mathbb Z\$. By (...


17

J, 213 bytes Computes the lowest solution for each \$n \leq 162\$ on TIO. Also found out that the OEIS lowest values is apparently wrong, as you don't need to put every prime in a partition. Big thanks to @Neil for reminding me about modular arithmetic, otherwise I would have sit at \$n=36\$. :-) 3 :'N-~<./(0{[*|.(]-[*<.@%~)N*0}.@{_2{[:(]\:~@,:[-]*<....


16

05AB1E, 14 bytes ∞v®yÒgm=Ox<.±, Try it online! My first non-trivial 05AB1E answer! Happy for suggestions to improve it. The code prints two interleaved sign sequences, both related to the Pólya conjecture. In 1919, George Pólya conjectured that the majority (no less than half) of positive integers up to any finite limit \$\ge2\$ have an odd number of ...


16

JavaScript (ES7), 19 bytes n=>14/n**n+1^n%12<1 Try it online! We compute: $$\left\lfloor\frac{14}{n^n}+1\right\rfloor$$ which is \$\lfloor 14/1+1\rfloor=15\$ for \$n=1\$, \$\lfloor 14/4+1 \rfloor=4\$ for \$n=2\$, or \$1\$ for \$n>2\$. We then XOR the result with \$1\$ if \$n \bmod 12=0\$.


16

x86 Machine Code, 5 bytes A8 01 74 01 F4 Takes the integer value of your choice in the EAX register, halts the CPU if the number is odd, or continues execution harmlessly if the number is even. Ungolfed assembly language mnemonics: A8 01 test al, 1 74 01 jz IsEven F4 hlt IsEven: The first two instructions (test+jz)...


15

05AB1E, 2 bytes ∞L Try it online! The footer formats the output like the example from the post. ∞ pushes a list of all natural numbers, L takes the range [1 .. n] for each number.


15

Python 2, 638 634 608 603 572 560 508 470 bytes (without brute force as well) Tthanks to @randomdude999 for the golfing down the code by like 100 bytes as well as everyone who has helped point out smaller golfing tricks! from gmpy2 import* R=range r=reduce p=lambda n,i=1:n/i and[l+[i]for l in p(n-i,i)]+p(n,i+1)or[[]][n:] e=lambda f,x:r(lambda y,z:y*x+z,f) ...


15

Python 2, 28 bytes lambda x,n:(10**-~n/9-n)/9*x Try it online! -6 thanks to @Bubbler and @tsh Aha the first answer I have used some math How? Let's call \$n^{th}\$ term as \$y\$ $$ S_n=x+(10x+x)+(100x+10x+x)+.....+y\\= x+(11x)+(111x)+.....+y\\=\frac{x}{9}(9+99+999+.....+y)\\=\frac{x}{9}((10-1)+(100-1)+(1000-1)+.....+y)\\=\frac{x}{9}((10+100+1000+.....+y)-(...


14

Wolfram Language (Mathematica), 20 bytes Perimeter[#~Disk~#]& Try it online! -2 bytes from @Roman (see comments)


14

Python 3, 43 bytes lambda s:([*{*range(7)}-s]*4)[-sum(s):][:3] Try it online!


14

Jelly, 6 bytes R⁵*%i1 Try it online! Basically compute 10**[1..n] % n and get the 1-based index of 1.


14

Python 2, 24 bytes lambda n,k:n*10%k==0<n%k Try it online! Checks that \$10n\$ is a multiple of \$k\$, but \$n\$ itself is not. 24 bytes lambda n,k:n%k>>n*10%k*n Try it online! The *n at the end can't be omitted, say for n=19001, k=10000.


14

J, 23 bytes ~:/I.@,~4|[:-/1#;._1@,] Try it online! Takes a boolean vector where 0 represents r and 1 represents s, and returns the result in the same encoding. How it works Imagine evaluating the chunks of \$r^n s r^m s\$ from the start. If we evaluate \$sr\$ in the middle \$m\$ times, we get \$r^{n+3m}s^2 = r^{n+3m}\$. We can repeat the process to the end. ...


14

Jelly, 15 bytes ¹ÆFṛÇṭ¥Ị?@/€$Ẓ? Try it online! A full program that takes the number and outputs the answer. This isn't a link because I am using "last link" to refer to itself, so it would break as a link on its own. I fix this for my test suite by making the last link a single atom that calls the next link. For whatever reason, "this link&...


14

Jelly, 6 bytes R×\⁸¡Ṫ Try it online! APL (Dyalog Unicode), 10 bytes {⊃⌽×\⍣⍵⍳⍵} Try it online! The main trick is to observe how the computation of x!y progresses as y increases. 1!0=1 2!0=2 3!0=3 4!0=4 ... 1!1=1 2!1=1*2 3!1=1*2*3 4!1=1*2*3*4 ... 1!2=1!1 2!2=1!1*2!1 3!2=1!1*2!1*3!1 4!2=1!1*2!1*3!...


13

Python 3, 53 bytes def f(b):c=[*{*range(7)}-b];del c[-sum(b)%4];return c Try it online! -3 bytes thanks to FryAmTheEggman -4 bytes by zero-indexing -1 byte thanks to xnor


Only top voted, non community-wiki answers of a minimum length are eligible