Skip to main content
57 votes

N-dimensional N^N array filled with N

Python, 32 bytes lambda n:eval('['*n+'n'+']*n'*n) Try it online! Makes a string like "[[[n]*n]*n]*n" with ...
xnor's user avatar
  • 147k
44 votes
Accepted

Should we be friends?

SWI-Prolog, 62 47 41 bytes X*Y:-X+Y;Y+X;X==Y. X?Y:-not(X*Y),X*Z,Y*Z. Prolog isn't too often useful, but when it is it's just beautiful. We'll use ...
orlp's user avatar
  • 39.2k
34 votes

N-dimensional N^N array filled with N

J, 4 bytes $~#~ Try it online! Explanation ...
miles's user avatar
  • 17k
19 votes

Implementing a stack

MATL, 6 bytes "@?@}x Input is a row vector of numbers. The final stack is shown upside down, with the most recent element below. Try it online! Or verify all ...
Luis Mendo's user avatar
  • 105k
17 votes

Neutralize data

JavaScript (ES6), 53 47 bytes f=o=>o.big?o.replace(/./g,' '):o.map?o.map(f):0 Test cases ...
Arnauld's user avatar
  • 198k
17 votes

Follow a linked list

convey, 36 29 bytes v<<<<,{ \~./." >"`=>! >!0<"} Try it online! { gets the input, that ...
xash's user avatar
  • 11.3k
16 votes

Follow a linked list

Haskell, 17 bytes f x=iterate(x!!)0 0-indexed Try it online!
MennoK's user avatar
  • 271
15 votes

Should we be friends?

PHP, 138 133 129 bytes PHP beats Mathematica - a rare occurence. ...
Titus's user avatar
  • 14.8k
13 votes

N-dimensional N^N array filled with N

APL (Dyalog APL), 4 bytes ⍴⍨⍴⊢ Try it online!
Dennis's user avatar
  • 211k
13 votes

N-dimensional N^N array filled with N

Mathematica, 22 20 bytes (t=Table)@@t[#,#+1]& (* or *) Table@@Table[#,#+1]&
JungHwan Min's user avatar
  • 13.9k
13 votes

Implementing a stack

Java (JDK 10), 42 bytes Since "[the] output is flexible [...], the only thing that matters is the order", this changes the input array into a 0-terminated array. ...
Olivier Grégoire's user avatar
12 votes

Should we be friends?

CMD (Batch), 50 + 20 + 135 = 205 bytes FRIEND.CMD @for %%f in (%1.%1 %1.%2 %2.%2 %2.%1)do @set %%f=1 KNOW.CMD ...
Neil's user avatar
  • 177k
12 votes

Implementing a stack

PowerShell, 46 41 40 bytes $args|%{$x,$a=&({1,$_+$a},{$a})[!$_]};$a Try it online! Takes input via splatting, e.g., ...
AdmBorkBork's user avatar
  • 43.5k
12 votes

Implementing a stack

Sed, 17 Bytes :;s/[0-9]\+,0//;t -3 bytes thanks to @OMᗺ, -1 thanks to @eggyal Because you're guaranteed to never pop an empty list, you don't need anything more ...
Tacroy's user avatar
  • 221
12 votes

Drawing a tree from an array

Python 3, 400 393 390 bytes ...
Beefster's user avatar
  • 9,971
11 votes

Implementing a stack

C (gcc), 62 60 56 55 bytes -2 -6 bytes thanks to l4m2 -1 byte thanks to ceilingcat. Uses the permitted notion of -1 terminated arrays. f() calls itself ...
gastropner's user avatar
  • 4,413
11 votes

CGAC2022 Day 7: Fen The Wicked

Python 3.8, 45 bytes lambda l,i=0:[sum(l[i&(i:=i+1):i])for _ in l] Try it online! The start index for the sum at one-indexed position ...
xnor's user avatar
  • 147k
11 votes

Sorting with a deque

K (ngn/k), 17 bytes {&/(x=|\x)|x=&\x} Every element must be the minimal (or the maximal) element of its prefix. Try it online! APL(Dyalog Unicode), 13 10 ...
akamayu's user avatar
  • 1,145
10 votes

N-dimensional N^N array filled with N

JavaScript (ES6),  44  40 bytes f=(n,k=i=n)=>i--?f(n,Array(n).fill(k)):k Demo ...
Arnauld's user avatar
  • 198k
10 votes

N-dimensional N^N array filled with N

Octave, 35 33 25 23 20 bytes @(N)ones(N+!(1:N))*N Try it online! @(N)ones(N*ones(1,N))*N @(N)repmat(N,N*ones(1,N)) Thanks to @...
rahnema1's user avatar
  • 5,675
10 votes

N-dimensional N^N array filled with N

R, 26 This is the obvious answer but perhaps there is something cleverer? n=scan();array(n,rep(n,n))
Flounderer's user avatar
10 votes

Implementing a stack

R, 45 bytes o={};for(e in scan())o="if"(e,c(e,o),o[-1]);o Try it online! -4 byte thanks to @Giuseppe
digEmAll's user avatar
  • 5,029
10 votes

Implementing a stack

Haskell, 28 bytes foldl(#)[] (_:s)#0=s s#n=n:s Try it online!
nimi's user avatar
  • 35.9k
10 votes

Implementing a stack

Jelly, 6 bytes ṣ0Ṗ;¥/ Try it online! How it works ...
Dennis's user avatar
  • 211k
10 votes

Follow a linked list

Husk, 4 bytes ¡!¹← Try it online! 1-indexed, returns an infinite list. Explanation ...
Razetime's user avatar
  • 27.4k
10 votes

Keep elements in sequence that have a letter repeated at least 3 times

Python 3, 51 50 bytes lambda l:{s for s in l for c in s if s.count(c)>2} Try it online!
The Thonnu's user avatar
  • 18.3k
10 votes

Implement a bag without replacement

Vyxal, 5 bytes Inspired by Kevin Cruijssen's 05AB1E answer 6 bytes without the bonus: {7Þ℅⟑, Try it Online! Explanation ...
math scat's user avatar
  • 9,468
10 votes

Implement a bag without replacement

JavaScript (ES6), 50 bytes A function that draws one piece at a time. m=f=_=>m^(m|=1<<(i=Math.random()*7))?-~i:f(m%=127) Try it online! Commented ...
Arnauld's user avatar
  • 198k
9 votes

N-dimensional N^N array filled with N

05AB1E (legacy), 6 5 bytes -1 thanks to Kevin Cruijssen F¹.D) Try it online! ...
Riley's user avatar
  • 11.7k
9 votes

N-dimensional N^N array filled with N

Haskell, 52 bytes f n=iterate(filter(>'"').show.(<$[1..n]))(show n)!!n Try it online! Inspired by @nimi's answer, but using more predefined functions. ...
Ørjan Johansen's user avatar

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