21

Octave, 57 bytes A=input('');V=A'/trace(A*A');for i=1:1e4V=2*V-V*A*V;end V Try it online! This is not particularly well golfed, but I wanted to advertise an approach that could be useful for other non-builtin answers. This uses the Hotelling-Bodewig scheme: $$ V_{i+1} = V_i\left(2I - AV_i\right)$$ Which iteratively computes the inverse of a non singular ...


20

Python 2, 24 bytes Takes two lists \$ a \$ and \$ b \$, where \$ b \$ has the missing number. lambda a,b:sum(a)-sum(b) Try it online! Given that \$ a \$ and \$ b \$ differ by a single number, we can trivially obtain the answer by computing the difference of sums.


18

Python 2, 37 bytes Outputs a flattened \$ n \times n \$ latin square. lambda n:((range(n)*-~n)[1:]*n)[::~n] Try it online!


17

Python 3, 47 bytes f=lambda x,*a:f(*a,x[1:],x[:-1])if sum(x)else x Try it online! It's simple breadth-first search, implemented recursively. The if...else is slightly bothering me; it feels like there is an improvement somewhere...


16

AWK -vn=, 9 a[$1]++<n This is so competitive with the golfing-language answers, I feel like I might have misunderstood the question - did I? The limit n is passed as a variable at the command line with -vn=<value>. The array is read from STDIN. Try it online!


16

Python 2, 23 bytes lambda l:map(l.count,l) Try it online!


16

Jelly, 5 bytes 4ṗ>2Ġ Try it online! Neil saved a byte. Thanks! 4ṗ n-th Cartesian power of [1,2,3,4] >2 Replace 1,2,3,4 with 0,0,1,1 Ġ Group indices by values For n=2, 4ṗ>2 generates a list of 16 pairs: 1: [0, 0] 2: [0, 0] 3: [0, 1] 4: [0, 1] 5: [0, 0] 6: [0, 0] 7: [0, 1] 8: [0, 1] 9: [1, 0] 10: [1, 0] 11: [1, 1] 12: [1, ...


16

Python 3, 33 bytes lambda a:sum(sorted(a)[-2::-2])/2 Try it online! This is my first answer :D


15

R, 5 bytes solve Try it online! Nothing new here... Basically, the code solve(A, B) solves \$AX = B\$, but when \$B\$ is not given, it is treated as identity matrix, thus giving us the inverse as the result.


15

convey, 47 bytes Returns 0 for neither, 1 for one-based, 2 for zero-based and 3 for unknown. {2+~`0 ?;\2:!2[ v^<]` ?;\?+2 v^< v*+} !>>>=?^ 2 Try it online! Run for 1 2 2 3 with index 2 and value 2: On the left we split the input lines with ;\ ^< into the three paths. The first one pushes two zeroes after length of path + index time steps ...


15

Javascript, 106 bytes s=>(s+'!'+s.split``.reverse().join``).match(`(.)((?!\\1).)[^!]{${s.indexOf` `-1}}((?!\\1|\\2).)(\\2|\\3)`) (Returns inverted truthy/falsy.) Focus on the boundaries of the tiling. Suppose the tiling is not checkered. Then there is an odd cycle in the adjacency graph. Draw the odd cycle by connecting adjacent squares' centres, like ...


14

Python 2, 40 bytes f=lambda s,*l:s[3:]and f(s[1:],l,*l)or l Try it online! Doesn't bother telling car from cdr. Instead, makes a big nested tuple where every path ends at the right value, assuming it has the right length and ends in a. For example, f("cdddar", 5) = ((((5,), 5), (5,), 5), ((5,), 5), (5,), 5) is the same as f("caaaar", 5)...


13

Charcoal, 306 246 bytes Eθ⭆ι⎇λ⊟λψ≔ΣEθΣEι∨⁼²№λ¹№λ¹ζFLθFL§θι«Jκι¿›²Σ∨§§θικ²≧⁺⊕LΦKM℅λζ»FLθFL§θι«Jκι¿⁼²ΣKK«≔⌕§§θικ²δ≔δεM✳⁻χ⊗ε¿ΣKK«W∨⁻ⅉι⁻ⅈκ«≧⁻ΣKKεW∨›²§§§θⅉⅈε¬Σ§KVε≦⊕εM✳⁻χ⊗ε»¿¬⁼﹪⁺²ε⁴δ1»»»Wφ«≔⁰φFLθFL§θκ«Jλκ≔ΣKKδ≔§§θκλη≔∧δΦ⌕A粬℅§KVμε¿ε«≔¹φ¿‹Lε䫧≔η⊟ε⁰≔¹δ1»ψ≧⁺δζ»»»≧⁺⊗ΣEKAΣιζ⎚Iζ Try it online! Link is to verbose version of code. Explanation: Eθ⭆ι⎇λ⊟λψ Start by ...


13

APL (Dyalog Extended), 3 bytes ׯ⍸ Try it online! A tacit function. Banning only the exact built-in actually gives APL a massive advantage! How it works ׯ⍸ ⍸ ⍝ Takes a vector v and gives another vector containing v[i] copies of i ⍝ for each index i ¯ ⍝ Inverse of the above, which counts occurrences of i which becomes v[i] × ⍝ Signum of each ...


13

Haskell, 22 bytes (.zip).(.).map.uncurry Try it online! Not particularly interesting, just a reimplementation of zipWith converted to pointfree form: \f x y -> map (uncurry f) (zip x y) \f x -> map (uncurry f) . zip x \f x -> (map (uncurry f) .) zip x \f -> (map (uncurry f) .) . zip \f -> (. zip) (map (uncurry f) .) \f -> (. zip) ((.) (...


13

JavaScript (V8), 48 bytes a=>f=b=>b[2]?b[[x,...r]=f(b.slice(1)),1]<f?x:r:a Try it online! -2 bytes thanks to @Arnauld!


13

Trivial Built-in Answers This is the post for all of the languages where this is a built-in Vyxal, 1 byte ≈ Try it Online! Jelly, 1 byte E Try it online! 05AB1E (legacy), 1 byte Ë Try it online! Wolfram Language (Mathematica), 5 bytes Equal Try it online! SameQ also works. Brachylog, 1 byte = Try it online! Husk, 1 byte E Try it online! Factor, 3 bytes ...


13

Jelly, 8 bytes Ä2œPF_@\ Try it online! Based on the older approach below. Ä generates cumulative sums, and 2œPF (ew) throws away the second one. Then \ scanning by _@ flipped subtraction gives: [a, a+b+c-(a), a+b+c+d-(a+b+c-(a)), a+b+c+d+e-(a+b+c+d-(a+b+c-(a))), ...] = [a, b+c, a+d, b+c+e, ...] I feel like there has to be ...


12

APL (Dyalog Unicode), 1 byteSBCS ⌹ Try it online! The domino primitive is a very interesting APL "built-in". It already featured in another 1-byte answer of my own where it was used to solve a least-squares problem. When applied to a square matrix, ⌹ tries to find the matrix inverse of its argument. Many golfing languages will also have a built-...


12

Brainfuck, 43 bytes ,>,[->,<],<[->->-<<]>[[-]>>++<<]>[[-]>+<]>. Arguments are taken in this order: value_at_index, index, array values. Outputs are: 0-unknown, 1-zero indexed, 2-one indexed, 3-neither. How it works , read value_at_index into first cell >, read index into second ...


12

Jelly, 3 bytes RṙⱮ Try it online! Explanation RṙⱮ Monadic link, takes an argument z R [1, 2, ..., z-1, z] Ɱ For each on right argument (z, defaults to loop over range) ṙ Rotate the left list by the right amount Alternative solution: +þ%. Generates the \$n\times n\$ addition table and then applies modulo to bring the elements into range.


12

Jelly,  9 8  7 bytes (Saved 1 when the assumption of sorted input was allowed, and another realising there was no need to floor the inverses.) İ<Jṣ1ṪL A monadic Link accepting a list of floating-point numbers in \$[0,1]\$ sorted in descending order that yields an integer. Try it online! Or see the test-suite. How? Effectively this evaluates how many ...


12

Python 3, 100 99 88 bytes lambda a:2in[len({i,l}^{k,j})for x,y in zip(a,a[1:])for i,j,k,l in zip(x,x[1:],y,y[1:])] Try it online! Return True if it isn't checkered tiling, False otherwise -1 byte by inversing True/False for return value -11 thanks to @xnor How it works: The pattern is True if any of the following sub-pattern appears in the pattern : AA ...


12

J, 7 bytes -:/:@/: Try it online! Ninja'd by hyper-neutrino :( Takes zero-based input. Applying Grade Up twice to a vector gives a "ranking" of each element, so that 0 is the smallest, 1 is the next smallest, ... up to n-1, breaking ties by giving a smaller number to the one appearing first. A vector is a permutation if and only if the ranking is ...


12

Risky, 7 bytes 7 bytes and a palindrome 1_??!0:0!??_1 Try it online! Explanation 1 sort _ ? input ? filter by ! factorial 0 0 : = 0 range ! length ? input ? find first number such that _ 1 1


12

Haskell (1 indexed), 29 bytes Courtesy of AZTECCO g l=all(`elem`l)[1..length l] Try it online! Haskell (0 indexed), 42 32 31 bytes Lynn saved one byte with the pointfree solution. all.(.fst).flip elem<*>zip[0..] Try it online! I tried a bunch of creative stuff with scans, folds and zips, but the boring solution ended up being the shortest. Both of ...


12

Jelly, 8 bytes ⁵Œ!’³ịⱮQ Times out on TIO, takes about two minutes on my machine: % time python3 -m jelly eu '⁵Œ!’³ịⱮQ' "[1,2,3,1]" [[0, 1, 2, 0], [0, 1, 3, 0], [0, 1, 4, 0], [0, 1, 5, 0], [0, 1, 6, 0], [0, 1, 7, 0], [0, 1, 8, 0], [0, 1, 9, 0], [0, 2, 1, 0], [0, 2, 3, 0], [0, 2, 4, 0], [0, 2, 5, 0], [0, 2, 6, 0], [0, 2, 7, 0], [0, 2, 8, 0], [0, 2, ...


12

Python 3, 53 47 bytes f=lambda a,b,*r:(a,)+(r and f(b+r[0],a,*r[1:])) A variadic function that takes the integers as separate arguments and returns a tuple. Try it online! Explanation f=lambda a,b,*r:(a,)+(r and f(b+r[0],a,*r[1:])) f= # Define f to be lambda a,b,*r: # a function ...


12

Python 3 with numpy, 90 87 86 84 bytes from numpy import* lambda n:2*((4<<(a:=(y:=c_[1-n:n])-y.T)//4)+a%4-2&a-2*y)-1<<a<y%2 Takes \$\left\lceil \frac{n}{2}\right\rceil\$. -3 by removing x. -1 with a shorter expression for \$-x - y\$. -2 with a shorter combining method. How it works Broadcasting is used in several places to produce the ...


11

R, 72 61 bytes function(A,V=t(A/sum(diag(A%*%t(A))))){for(i in 1:1e4)V=2*V-V%*%A%*%V;V} Try it online! Porting Sisyphus' answer is not futile at all...and thanks to Sisyphus for -11 bytes. Observes that \$Tr(AA^T)=\sum\limits_{i,j}a_{ij}^2\$. R, 94 bytes function(M)outer(k<-1:dim(M),k,Vectorize(function(j,i)det(M[-i,-j,drop=F])*(-1)^(i+j)))/det(M) Try ...


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