Tag Info

13

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

11

Jelly, 4 bytes R¡FP Try it online! (Starting from [n],) R Recursively replace each x with [1..x] ¡ n times F Flatten P Product For example R¡ for the input 4 yields [ [[[1]]], [[[1]], [[1], [1, 2]]], [[[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]]], [[[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]], [[1], [1, 2], [1,...

11

Jelly, 6 bytes 3Ḋ*)SI Try it online! -1 byte thanks to Jonathan Allan 1-indexed sequence without leading zeros. Uses the formula $\sum_{k=1}^{n} 3^k - 2^k$. Explanation 3Ḋ*)SI Main monadic link ) For each k in the range [1..n]: 3Ḋ Remove the first element from the range [1..3] * Raise each to the power of k S Sum (producing [sum(2^k)...

11

Python, 20 bytes lambda x,y:x*x>y*y-y Try it online! Checks whether $x^2>y^2-y$. Outputs True/False for whether x comes after y in the listing. Note that we're not asked handle the case x==y. To see that this works, note that each of the x*x value in the table is greater than all the y*y-y values to the left of it, but none to the right of it. ...

9

Haskell, 43 bytes f x=x!x x!0=x x!n=product$map(!(n-1))[1..x] Try it online! +8 bytes due to the problem needing a function that only takes a single argument. Thanks to @Lynn for pointing that out Thanks to OVS for pointing out map is shorter than a list comprehension and taking 1 byte off. My first time ever submitting a haskell answer. I am a beginner so ... 8 Python 3 48 bytes f=lambda x,y:f(x,y-1)*f(x-1,y)if x*y else(y>0)+x TIO 55 bytes if a more conventional input is required. I don't know how to initialize the default 2nd argument to equal the first, so I've rewritten everything as t=x-y without much more thought. f=lambda x,t=0:f(x,t+1)*f(x-1,t-1)if(x-t)*x else(x>t)+x Thanks to Arnauld for saving 3 ... 8 JavaScript, 58 bytes a=>a.some((r,y)=>r.some((c,x)=>(r/(r=c)==a[x][x])/-y--<c)) Try it online! When c==0 r/(r=c) is NaN or Infinity; (r/(r=c)==a[x][x]) is false (r/(r=c)==a[x][x])/-y-- is 0 or NaN (r/(r=c)==a[x][x])/-y--<c is false When y==0 (cells on main diagonal) and c>=1 (r/(r=c)==a[x][x])/-y-- is NaN or Infinity (r/(r=c)==a[x][x])... 8 R, 23 bytes 3^(n=scan()+2)/2-2^n+.5 Try it online! Outputs without the leading zeros, 0-indexed. Uses formula from OEIS page: $$a(n) = 9 \cdot 3^n/2 - 4 \cdot 2^n + 1/2$$ 8 Jelly, 7 bytes cþæ*2FS Try it online! Now that xigoi has outgolfed me, I thought I'd share my answer. This outputs the $n$ term of the sequence without leading zeroes. How it works We generate the matrix $$\left[\begin{matrix} \binom 1 1 & \binom 2 1 & \cdots & \binom n 1 \\ \binom 1 2 & \binom 2 2 & \cdots & \binom n 2 \\ \vdots &... 7 Python 3, 70 bytes f=lambda a,b:b and f(b,a-b*((t:=a/b+.5+.5j).real//1+t.imag//1*1j))or a 7 Jelly, 14 13 bytes ŒDµḢ=Ɲo@ƑḢ>FẠ Try it online! -1 because I actually thought to check if the input can contain negative integers ŒDµ Consider the diagonals of the input matrix. Ḣ Pop the main diagonal; Ɲ for each pair of its adjacent elements = are they equal? (Especially note ... 7 Alchemist, 76 bytes _+0j->2c b+0j->3d 0j+0_+0b->j c+j+x->_+j d+j->x+b+j j+0c+0d->Out_x+Out_" "!b Try it online! Outputs nonzero values infinitely using the formula $S(n, 3) = \sum_{k=1}^{n-2} (3^k - 2^k)$. On TIO, this computes up to the 13th element (2375101) before timing out. 6 JavaScript (Node.js), 43 bytes Expects and returns a BigInt. f=(x,n=x,g=_=>x?f(x--,~-n)*g():1n)=>n?g():x Try it online! This actually simplifies down to ... JavaScript (Node.js), 37 bytes f=(x,n=x)=>n?x?f(x,~-n)*f(~-x,n):1n:x Try it online! ... which is essentially the same as Alwin's answer. 6 Python 2, 24 bytes lambda n:3**n/6-~-2**n/2 Try it online! Formula from OEIS for $n>0$:$$ f(n) = \frac{1}{2}(3^{n-1}-2^n+1)$$6 APL (Dyalog Unicode), 14 bytes Anonymous tacit prefix function using xnor's formula. 1-indexed. 2÷⍨1-2∘*-3*-∘1 Try it online! 6 Jelly, 9 bytes Port of xnor's answer, made/fixed and golfed with hyper-neutrino's and caird coinheringaahing's help. ’3*_2*‘H Try it online! This doesn't handle leading zeroes. ’3*_2*‘H ’ n-1 3* 3^(n-1) _ From that, subtract 2* 2^n ‘ Increment that H Halve it 6 Jelly, 12 bytes 3ẹ@þṗ¥ẠƇṢ€QL Try it online! A monadic link that takes $n$ as its argument and returns $a(n)$. This is longer and less efficient than the answers based on the OEIS formulae, but should work for any value of $k$ by varying the first number in the link from 3. Also, removing the L at the end yields the actual sets. Explanation 3 ¥ ... 6 Jelly, 9 bytes Surely there is an eight or less out there... 1×Ɱ3¡FQS A full program that accepts a non-negative integer from STDIN and prints the result using the 0-indexed, no leading zeros option. Try it online! How? 1×Ɱ3¡FQS - Main Link: no arguments 1 - start with x=1 ¡ - repeat this (read from STDIN) times: - last two ... 6 Desmos, 21 bytes f(x,y)=\{xx-x<yy,0\} (Newline is required) Edit: Just noticed that xnor's answer is very similar to mines, but I found this independently. Function is $f(x,y)$, and it returns $0$ if $x$ has a higher index, otherwise returns $1$. This seems to work, but I just randomly stumbled upon it, so I can't explain how it works. Try It On ... 6 J, 8 bytes >&(-3^|) Try it online! Or verbose: (x - 3 ^ abs(x)) > (y - 3 ^ abs(y)). This maps the inputs to the following sequence to compare them in: 0 1 _1 2 _2 3 _3 4 _4 5 _5 _1 _2 _4 _7 _11 _24 _30 _77 _85 _238 _248 If sorted input as output is allowed, then 7 byte /:*.@%: is another fun way to sort /: the input list: *. ... 5 Community Wiki answer for trivial answers Please add your language to this if the builtin GCD function correctly handles Gaussian integers. J, 2 bytes +. Try it online! Wolfram Language (Mathematica), 3 bytes GCD Try it online! Pari/GP, 3 bytes gcd Try it online! 5 Factor, 53 45 41 bytes [ dup [1,b] [ cum-product ] repeat last ] Try it online! A port of @Bubbler's answers; take the product scan (cumulative product) of 1..x x times and then return the last element. 5 Rattle, 111 bytes |sI^>s[[PgI#1I#s2=#-#1[^0[^1g2[^0=q]][1g2[^0[^1=q]P=#4<s<=#3-sg0>I~<I~s_3P=#4+<s<=#3sg0>I~<I~<[^~=q]]]]g1]]=1 Try it Online! Needless to say, Rattle is not built to handle matrices and this approach is pretty brute-force. However, this code really shows off most of Rattle's features! Explanation | ... 5 Scala, 132 bytes n=>(for{i<-1 to n-1 j<-i+1 to n-1 p<-1.to(n).permutations}yield{Set(p.slice(0,i),p.slice(i,j),p.slice(j,n))map(_.toSet)}).toSet.size Try it online! Is it short? No. Is it efficient? No. Is it clever? No. Why did I make it? I...don't know. I'll try golfing it later, if possible. 5 Husk, 7 bytes F>m€Θİ± Try it online! Returns 1 if the second is larger than the first, 0 otherwise 4 Jelly, 13 bytes Thanks to @ovs for the fix. %Lċ0 *ṗ’ÇƤ€QL Try it online! The first line computes the shadow transform. The second line looks at the shadow transform of all sequences of length n with elements in {1, 2, ..., n^n}. 4 Wolfram Language (Mathematica), 27 bytes 1##&@@#&//@Nest[Range,#,#]& Try it online! Port of Lynn's solution. Wolfram Language (Mathematica), 33 bytes Nest[f1##&@@f~Array~#&,D,#]@#& Try it online! Builds $x!0...x!x$: D x => x!0 f1##&@@f~Array~#& (x => x!n) => (x ... 4 JavaScript (ES6), 46 bytes x=>(g=p=>x>1n?x--**p*g(p*y++/i++):x)(i=1n,y=x) Try it online! Use$$ f\left(n\right) = \prod_{i=1}^n i^{{2n-i-1}\choose{n-1}} $$with exception$$ f\left(0\right) = 0$$4 Haskell, 41 bytes f n=product$iterate(>>= \x->[1..x])[n]!!n Try it online! Same idea as my Jelly answer: starting from [n], repeatedly replace each x by 1..x, n times, then take the product. [4] → [1,2,3,4] → [1,1,2,1,2,3,1,2,3,4] → [1,1,1,2,1,1,2,1,2,3,1,1,2,1,2,3,1,2,3,4] → [1,1,1,1,2,1,1,1,2,1,1,2,1,2,3,1,1,1,2,1,1,2,1,2,3,1,1,2,1,2,3,1,2,3,4]...

4

Jelly, 8 7 bytes Ṭ€+\I’Ȧ Try it online! -1 byte thanks to Jonathan Allan Outputs an empty array (falsey) if it can be the result, and a non-empty array (truthy) if not. How it works Ṭ€+\I’Ȧ - Main link. Takes a list L on the left € - For each integer I in L: Ṭ - Untruth; Generate a list of zeroes of length I, replace the last with 1 \ - ...

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