# Tag Info

30

MATL, 21 bytes 3XytPJ*-X*Xj~4&1ZIunq The input is a matrix with 1 for \ and j (imaginary unit) for /. Try it online! Or verify all test cases. With some extra code, you can see the different pieces in random colours. Or increase the resolution for a better looking result. Explanation Consider input [1,j; 1,1; j,1; j,j] as an example. This ...

29

MATL, 4 bytes BSXB Try it at MATL Online Explanation % Implicitly grab input as an array % STACK: [10, 17, 19, 23] B % Convert each element to binary where each decimal number results in a row % STACK: [0 1 0 1 0; % 1 0 0 0 1; % 1 0 0 1 1; % 1 0 1 1 1] S % Sort each column, placing all of the 1'...

28

Python 3, 124 bytes def f(n): while n&4369<n/n:n>>=1 while n&15<1:n>>=4 return'TJLZSIO'["rēȣc63ıGtĲȱᄑ@'̢̑@@@@Ȳq".index(chr(n))%7] Try it online! Expects an integer n representing a 4 × 4 binary matrix. Throws if no tetromino is found. Line 2 slides the shape to the right until a 1 is in the rightmost column. (4369 ...

26

MATL, 2 bytes Xy A translation of my Octave answer. Try it online. A 4 byte version with no built-ins (thanks to Luis Mendo): :t!= : take input n and a generate row array [1,2,...n] t duplicate ! zip = thread compare over the result

20

Wolfram Language (Mathematica), 26 25 bytes Tr[#//.x_:>#.#.Clip@x]<1& Try it online! How it works Given an adjacency matrix A, we find the fixed point of starting with B=A and then replacing B by A2B, occasionally clipping values larger than 1 to 1. The kth step of this process is equivalent up to the Clip to finding powers A2k+1, in which the (...

19

TI-BASIC, 2 bytes identity(Ans Fun fact: The shortest way to get a list {N,N} is dim(identity(N. Here's the shortest way without the builtin, in 8 bytes: randM(Ans,Ans)^0 randM( creates a random matrix with entries all integers between -9 and 9 inclusive (that sounds oddly specific because it is). We then take this matrix to the 0th power.

18

Julia, 9 3 bytes eye This is just a built-in function that accepts an integer n and returns an nxn Array{Float64,2} (i.e. a 2D array). Call it like eye(n). Note that submissions of this form are acceptable per this policy.

17

J, 57 bytes ,&([:(0#@-.~~.@,)](*@[*[:>./((,-)#:i.3)|.!.0])^:_ i.@$)-. Try it online! This is one of those where the idea is incredibly simple (and I think fun), but executing it had some mechanical lengthiness which masks the simplicity... eg, shifting the original matrix in all directions with 0 fill is the verbose ((,-)#:i.3) |.!.0. It's ... 16 APL, 5 bytes ∘.=⍨⍳ This is a monadic function train that accepts an integer on the right and returns the identity matrix. Try it here 16 APL (Dyalog Unicode), 29 28 bytesSBCS -1 thanks to @Adám {≢∪∨.∧⍨⍣≡2>+/↑|∘.-⍨⍸⍵}¨⊂,~∘⊂ Try it online! ⊂,~∘⊂ the matrix and its negation { }¨ for each of them do ⍸⍵ list of pairs of coords of 1s +/↑|∘.-⍨ matrix of manhattan distances 2> neighbour matrix ∨.∧⍨⍣≡ transitive closure ≢∪ number of unique rows 16 APL (Dyalog Unicode), 20 12 bytesSBCS -6 bytes through dzaima Full program. Prompts stdin for: texture as a list of strings number of rows in shape matrix number of columns in shape matrix indices of falsies (to be blanks) in the shape matrix All the ⎕s are supposed to be rectangles (they're not tofu). They symbolise a computer console which here means ... 14 Octave, 10 4 bytes @eye Returns an anonymous function that takes a number n and returns the identity matrix. 14 Python 3, 181 179 171 167 161 159 bytes Input by UTF-16 little-endian bytes without BOM. First decompose into columns using bit shifts, split by empty column, then hash them into a lookup table. -2 bytes thanks to ngn. -5 bytes thanks to Mr. Xcoder. lambda h,j=''.join:j(' ZAQV;JWP;MBOS;YRKCGXDF;ILHUENT'[int('0'+i,27)%544%135%32]for i in j(chr(64|i&7|... 14 Python 2, 105 bytes lambda b:sum(b[i+d::d][:(8,7-i%8,i%8)[d%8%5]].find('1')*int(c)>0for i,c in enumerate(b)for d in[1,7,8,9]) Try it online! Explanation We take the input as a string of 64 characters '0' or '1'. Using step slices, we cast four "lines of sight" from every queen we encounter. For example, when i = 10 and d = 7, marking the ... 13 Python 2, 275 271 264 249 bytes Saved four bytes by replacing -1 with H and removing one slicing operation ([:]). Saved seven bytes thanks to Halvard Hummel; removing yet another slicing operation ([:]), using multiple-target assignment to give a visited entry a value v not in "01" (S=S[1:];M[y][x]=H; -> S=M[y][x]=S[1:];) and switching from a ternary if/... 12 R, 4 bytes diag When given a matrix, diag returns the diagonal of the matrix. However, when given an integer n, diag(n) returns the identity matrix. Try it online 12 Python 2, 42 bytes lambda n:zip(*[iter((+*n)*n)]*n)[:n] An anonymous function, produces output like [(1, 0, 0), (0, 1, 0), (0, 0, 1)], First, creates the list (+*n)*n, which for n=3 looks like [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0] Using the zip/iter trick zip(*[iter(_)]*n to make groups of n gives [(1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, 0)] ... 12 Since this is basically talking about a cellular automaton I give you.. Golly Quicklife rule, 10 bytes 01234/234V Input the rule, paste the grid into Golly, run pattern. The resulting pattern is the output. Explanation: 01234 Survive on any number of neighbors /234 Born on >2 neighbors V Only directly adjacent neighbors count Or if you ... 11 16/9 20/11 22/12 28/15 30/16 32/17 34/18 36/19 (Java) This uses a number of ideas to reduce the search space and cost. View the revision history for more details on earlier versions of the code. It's clear that wlog we can consider only circulant matrices in which the first row is a Lyndon word: if the word is non-prime then it must have property X, and ... 11 JavaScript (ES6), 148 146 143 bytes Saved 1 byte thanks to @ngn s=>[...s].map(c=>g((k=c.charCodeAt()/8)&8|k*8&7)&g(k&7|k/2&8),o=x='',g=n=>x=n?x*27+n:(o+=' DZQGYWXNHJ.CSTIO.AFB.LPVE..KUMR'[x%854%89%35],n))&&o Test cases let f = s=>[...s].map(c=>g((k=c.charCodeAt()/8)&8|k*8&7)&g(k&7|k/2&... 11 Wolfram Language (Mathematica), 16+83=99 bytes Library import statement (16 bytes): <<Combinatorica` Actual function body (83 bytes): Length@HamiltonianCycle[MakeGraph[#~Position~1~Join~{1>0},##||Norm[#-#2]==1&],All]& Try it online! Note that the question just ask for the number of Hamiltonian path in the graph. However, (for some ... 11 MATL, 5 bytes JYaZy Try it online! Or verify all test cases. Explanation JYa % Implicit input. Unpad matrix. This removes outer zeros Zy % Size. Implicit display 10 Jelly, 4 bytes R=€R Doesn't use a built-in. Try it online! How it works R=€R Main link. Input: n R Range; yield [1, ..., n]. R Range; yield [1, ..., n]. =€ Compare each. This compares each element of the left list with the right list, so it yields [1 = [1, ..., n], ..., n = [1, ..., n]], where comparison is ... 10 J, 4 bytes =@i. This is a function that takes an integer and returns the matrix. 10 Jelly, 31 30 bytes sz0Z ç€2ZF€ç€8Zœ?@€€-36Ḅ+⁽$ṁỌY Try it online! How? sz0Z - Link 1, split & right-pad with zeros: list, items; number, chunkSize s - split items into chunks of length chunkSize z0 - transpose with filler zero Z - transpose ç€2ZF€ç€8Zœ?@€€-36Ḅ+⁽$ṁỌY - Main link: list of lists of numbers (1s & 0s), M ç€2 ... 10 Husk, 15 14 bytes zȯḋm←CtNCİ□ṁḋN Try it online! Continually prints the results as an infinite list. Explanation I wonder whether there's a better way to get every nth element from a list than splitting the list into chunks of length n and retrieving the head of each chunk. tN Get a list of all natural numbers except 1. (A) ... 10 JavaScript (ES7), 86 bytes Takes input as an array of 64 integers with 254 for a queen and 0 for an empty square. a=>[s=0,6,7,8].map(d=>a.map(g=(n,p)=>(p%8-(p+=~d)%8)**2<n%4?a[p]?s+=n&1:g(n/2,p):0))|s Try it online! This version abuses arithmetic underflow to get a stop condition in the recursive part. JavaScript (ES7), 89 bytes Takes ... 10 Jelly, 12 11 bytes ŒṪŒ!ạƝ€§ÐṂL Try it online! Explanation. ŒṪ Positions of snake blocks. Œ! All permutations. For each permutation: ạƝ€ Calculate the absolute difference for each neighbor pair § Vectorized sum. Now we have a list of Manhattan distance between ... 10 JavaScript (ES6), 154 134 bytes m=>m.map((r,Y)=>r.map(g=(_,x,y,r=m[y=1/y?y:Y])=>r&&r[x]&&[-1,0,1,2].map(d=>r[r[x]=0,/1/.test(m)?g(_,x+d%2,y+~-d%2):++n,x]=1)),n=0)|n/4 Try it online! How? Method Starting from each possible cell, we flood-fill the matrix, clearing all cells on our way. Whenever the matrix contains no more 1's, we ... 10 Clean (with Snappy), 800 785 670 644 bytes 460 402 bytes of code + 360 242-byte string literal (escaped here and on TIO because it isn't valid UTF-8) You can verify the length of the literal here. import StdEnv,Data.List,Data.Maybe,Codec.Compression.Snappy,Text @a b|b<'~'=b=a$m x y d=map(@' ')(foldl(\a b=[@u v\\u<-a&v<-b])['~~'..][join[' ']k\...

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