New answers tagged

0 votes

An Array of Challenges #1: Alternating Arrays

Pip, 8 bytes $&$=*UWg Attempt This Online! Explanation ...
DLosc's user avatar
  • 38.4k
0 votes

An Array of Challenges #1: Alternating Arrays

Brachylog, 6 bytes s₂ᶠoᵐ= Try it online! Explanation Inspired by Luis Mendo's MATL answer: ...
DLosc's user avatar
  • 38.4k
0 votes

Search the deepest depths of an array

APL(NARS), 42 chars {d←≡⍵⋄⌈/∊{0=k←↑⍴⍵:0⋄(k×⍵∊⍨d-≡⍵),∇¨⍵[⍳k]}⍵} test: ...
Rosario's user avatar
  • 301
1 vote

Contract a tensor

Pyth, 38 bytes .N?T:RtTtYN?tY:CN1Y?sIssNs.e@bkN:CMNT2 Try it online! Defines a function : which takes three inputs: a nested ...
CursorCoercer's user avatar
0 votes

Diagonalize a vector

Scala 3, 70 bytes x=>x.zipWithIndex.map((e:Int,i:Int)=>Seq.fill(x.size)(0).updated(i,e)) Attempt This Online!
t9dupuy's user avatar
  • 151
2 votes

Contract a tensor

Charcoal, 103 82 81 bytes ≔LθεW⁺υΣθ«≔ιθ→»≔Eθ⟦⟧δUMEθ﹪÷κXε⮌…·⁰ⅈε∧⁼§ιη§ιζ⊞O§δ↨Φι∧⁻μη⁻μζε§θκUMδΣιFⅈ≔⪪δεδ⭆¹⊟⮌§δ⁰ Attempt This Online! Link is to verbose version of code....
Neil's user avatar
  • 169k
5 votes

Contract a tensor

Python + NumPy, 24 bytes -3 bytes thanks to @Mukundan314. lambda a,i:a.trace(0,*i) Attempt This Online!
alephalpha's user avatar
  • 47.6k
3 votes

Contract a tensor

JavaScript (Node.js), 115 bytes f=(m,x,y,j)=>(r=m.map?.((n,i)=>f(n,x-1,y-1,x?j:i)),y?x?r:r.reduce(a=(u,v)=>u.map?.((w,i)=>a(w,v[i]))??u+v):r[j])??m ...
tsh's user avatar
  • 34.5k
0 votes

Diagonalize a vector

BQN, 6 bytes ⊢×⍋=⌜⍋ Try it at BQN online! Explanation ...
DLosc's user avatar
  • 38.4k
5 votes

Contract a tensor

APL (Dyalog Unicode), 23 bytes +/⊢⍉⍨-⍨⍥≢∘⍴⌊{⍋⍋⍺∊⍨⍳≢⍴⍵} Follows a golf suggested by Marshall and Adam. My original answer that shows the idea better: ...
Kamila Szewczyk's user avatar
4 votes

Search the deepest depths of an array

Jelly, 13 bytes 0LȦ?»ŒḊƇ’߀ṀƲ Try It Online! I'm sure this could be done much better, but I am rusty. Returns 0 for undefined. Explanation ...
hyper-neutrino's user avatar
  • 41.4k
1 vote

Could you please stop shuffling the deck and play already?

Vyxal 3, 7 bytes ϩUJiᶤᵞS Try it Online! ...
pacman256's user avatar
  • 3,410
0 votes

Search the deepest depths of an array

APL (Dyalog APL), 25 bytes {⍬≢⍴⍵:(⌈/∇¨,≢ׯ1∊⊢)⍵-1⋄0} Returns 0 if there is no match. Attempt This Online! ...
Mukundan314's user avatar
  • 8,424
1 vote

Longest Zero Sum Sub-array

Vyxal 3 G, 3 bytes Ṣᶻ∑ Try it Online! filter by falsy my beloved
pacman256's user avatar
  • 3,410
0 votes

Search the deepest depths of an array

Charcoal, 26 bytes ⊞υAFυFΦι⁺⟦⟧κ⊞υ⊖κI⌈EΦυ№ι⁰Lι Try it online! Link is to verbose version of code. Outputs None if no subarray ...
Neil's user avatar
  • 169k
0 votes

Search the deepest depths of an array

05AB1E, 25 24 bytes "Ð0åigˆ}<εD.ïië®.V"©.V¯à As always, ragged-list or recursive challenges aren't really 05AB1E's forte. -1 byte thanks to @Neil. ...
Kevin Cruijssen's user avatar
4 votes

Search the deepest depths of an array

R, 97 93 bytes Edit: -3 bytes thanks to @Giuseppe. f=\(L,d=0,l=0,`[`=sapply,`?`=max)`if`(is.list(L),?L[f,d+1,length(L)*any(L[identical,d])?l],l) Attempt This ...
pajonk's user avatar
  • 15.7k
3 votes

Search the deepest depths of an array

Haskell + hgl 45 bytes t y x=xd 0$[l x|p y?>x]<>(t(y+1)*~|p 0)<x t 0 Attempt This Online! Takes input as a ...
Wheat Wizard's user avatar
  • 97.7k
7 votes

Search the deepest depths of an array

JCram, 13 bytes (SBCS) -1 thanks to @mukundan314 -1 thanks to @tsh A JCrammed version, as suggested by Kamila Szewczyk. νⓅιk⑦③⍋⍁lζ⁷⊗Ⓙ JavaScript (ES13), 60 bytes -...
Arnauld's user avatar
  • 191k
4 votes

Search the deepest depths of an array

Python, 64 63 bytes -1 byte thanks to @LyricLy f=lambda x,d=0:max(0!=i*0and f(i,d+1)or(d==i)*len(x)for i in x) Attempt This Online! Pyth, 23 bytes ...
Mukundan314's user avatar
  • 8,424
0 votes

Remove falsy rows and columns

Nekomata, 9 bytes Z:Ť‼Ť$ᶻ¿‼ Attempt This Online! ...
alephalpha's user avatar
  • 47.6k
1 vote

Swap every two elements in a list

Python 3, 48 bytes f=lambda l:l[::-1][:2]+f(l[2:])if len(l)>1else l Try it online! Very simple. For some reason l[:2:-1] doesn't work.
Alan Breadel's user avatar
  • 4,083
1 vote

Diamondize a Matrix

Perl 5, 67 bytes sub{map{[grep$_,map{shift@{$_[-$_]}}-$_..0]}0..$#_,($#_)x$#{$_[0]}} Try it online!
Xcali's user avatar
  • 14.3k
0 votes

Diamondize a Matrix

Vyxal, 22 bitsv2, 2.75 bytes Þ`R Try it Online! Bitstring: 0010101000111101000010
pacman256's user avatar
  • 3,410
0 votes

Trim elements from the ends of a list

Perl 5 -a, 59 bytes $_=<>;for$i(0,-1){splice@F,$i,1while/(^| )$F[$i]\b/}say"@F" Try it online!
Xcali's user avatar
  • 14.3k
0 votes

Trim elements from the ends of a list

BQN, 16 bytes (⌽(∨`·∧˝≠⌜)/⊢)⍟2 Takes the list as its right argument and the elements to trim as its left argument. Try it at BQN online! Explanation ...
DLosc's user avatar
  • 38.4k
1 vote

What and where is the max?

Ruby, 55 bytes ->a{b=a.flatten [m=b.max,b.index(m).divmod(a[0].size)]} Attempt This Online!
Jordan's user avatar
  • 9,824
0 votes

Trim elements from the ends of a list

Uiua SBCS, 11 bytes ▽¬↥⇌∩\×⇌.∊, Try it!
chunes's user avatar
  • 23.5k
1 vote

Reconstruct Matrix from its diagonals

Vyxal, 2 bytes Þ„ Try it Online! So apparently lyxal forgot there was a built in for this :p
pacman256's user avatar
  • 3,410
1 vote

Remove first encountered elements from a second list

Uiua SBCS, 3 bytes ▽¬◰ Try it!
chunes's user avatar
  • 23.5k
1 vote

The shortest way to find one unique value when all other values are the same

HBL, 13.5 bytes -(+(1(%.))('1(%.)))(1(21(%. Try it! Port of Arnauld's answer.
Fmbalbuena's user avatar
  • 3,831
2 votes

What and where is the max?

Python 3.8 (pre-release), 66 60 bytes Vanilla Python approach, outgolfed by the numpy versions. -6 bytes as lambda expression instead of a function ...
movatica's user avatar
  • 1,074
1 vote

Recursive Z-matrix

flax, 5 bytes G>1ṗ4 Port of @lynn's Jelly answer. Since the lastest version isn't on ATO, here is an image of the program running (in the REPL). Explanation It ...
zoomlogo's user avatar
  • 1,655
1 vote

What and where is the max?

Racket, 114 112 bytes Output in the format (value row_idx col_idx) ...
Matthew Welmers's user avatar
1 vote

Recursive Z-matrix

APL(Dyalog Unicode), 10 9 bytes SBCS ⊢⌸2<,⍳⎕⍴4 Try it on APLgolf! ...
Mukundan314's user avatar
  • 8,424
1 vote

Follow the border

Python3, 307 bytes ...
Ajax1234's user avatar
  • 6,913
1 vote

What and where is the max?

APL+WIN, 32 bytes Prompts for matrix: (⌈/,m),(,(⍳↑⍴m)∘.,⍳1↓⍴m)[↑⍒,m←⎕] Try it online! Thanks to Dyalog Classic
Graham's user avatar
  • 5,886
2 votes

Remove falsy rows and columns

Husk, 8 bytes fm▼¹Tf▼T Try it online! Explanation ...
Leo's user avatar
  • 12.6k
1 vote

Different Way Forward

Vyxal, 2 bytes Try it Online! ( # n times ¯ # take forward differences
emanresu A's user avatar
  • 37.1k
2 votes

Remove falsy rows and columns

R, 32 bytes \(x)x[!rowSums(!x),!colSums(!x)] Attempt This Online! Test suite stolen from pajonk's answer.
Kirill L.'s user avatar
  • 13.9k
0 votes

Remove falsy rows and columns

Perl 5 -MList::Util=product, 88 bytes sub{map{[@$_[grep{//;product(map{$$_[$']}@_)}0..$#$_]]}@_[grep{product@{$_[$_]}}0..$#_]} ...
Xcali's user avatar
  • 14.3k
2 votes

Remove falsy rows and columns

APL (Dyalog Extended), 11 bytes (×∧/⍮∧⌿)⍛/⍨ Try it online!  using the argument as both parameter (list of masks, one per ...
Adám's user avatar
  • 30k
2 votes

Remove falsy rows and columns

05AB1E, 10 bytes øDĀPÏøIĀPÏ Try it online or verify all test cases. Explanation: ...
Kevin Cruijssen's user avatar
0 votes

Cosine similarity of two vectors

APL(NARS), 36 chars {+/¨×/{⍵÷√+/⍵*2}¨(⍺,0⍴⍨≢⍵)(⍵,0⍴⍨≢⍺)} test: ...
Rosario's user avatar
  • 301
2 votes

Remove falsy rows and columns

APL+WIN, 17 bytes Prompts for input of matrix (×/×m)⌿(×⌿×m)/m←⎕ Try it online! Thanks to Dyalog Classic
Graham's user avatar
  • 5,886
3 votes

Remove falsy rows and columns

Google Sheets, 72 bytes =let(a,A1:E6,_,lambda(x,min(x)),filter(filter(a,byrow(a,_)),bycol(a,_))) Put the array in cells A1:E6 ...
doubleunary's user avatar
  • 1,408
1 vote

Remove falsy rows and columns

APL(NARS), 43 chars {(c d)←1⍴⍨¨⍴⍵⋄c[↑¨k]←d[2∘⊃¨k←⍸0=⍵]←0⋄d/c⌿⍵} test: ...
Rosario's user avatar
  • 301
2 votes

Different Way Forward

Uiua SBCS, 8 bytes ⍥(↘1°\+) Try it!
chunes's user avatar
  • 23.5k
6 votes

Remove falsy rows and columns

Python 3, 82 74 65 60 bytes -13 bytes thanks to Mukundan314. -9 bytes thanks to att. lambda m:[q for*q,r in zip(*filter(all,zip(*m)),m)if all(r)] Try it online! I ...
totallyhuman's user avatar
  • 16.7k
4 votes

Remove falsy rows and columns

Matlab, 74 bytes(?) 52 bytes -22 bytes thanks to Luis Mendo because my first attempt was too readable. Try it online! Input for first test case would be ...
Xenox's user avatar
  • 141

Top 50 recent answers are included