Hot answers tagged

6 votes

Repeat Values In Array

JavaScript (Node.js), 44 43 bytes −1 thanks to Arnauld. A=>R=>A.flatMap((a,i)=>Array(R[i]).fill(a)) Try it online!
  • 28.4k
6 votes

Repeat Values In Array

Raku, 12 bytes (*Zxx*).flat Try it online! xx is Raku's replication operator. It produces a list of a number of copies of its ...
  • 5,986
5 votes

Repeat Values In Array

J, 1 byte # Try it online! Simple built-in solution: The copy verb.
5 votes

Repeat Values In Array

Python 3, 42 41 bytes lambda*a:sum(map(lambda x,y:[x]*y,*a),[]) Try it online! -1 thanks to Jonathan Allan
  • 11.2k
5 votes

Repeat Values In Array

Factor,  27  25 bytes [ [ <array> ] 2map-flat ] Try it online! Takes input as R A.
  • 11.6k
5 votes

Repeat Values In Array

Jelly, 1 byte x Try it online!
  • 11.2k
4 votes

Repeat Values In Array

APL (Dyalog Unicode), 1 byte / Try it online!
  • 28.4k
4 votes

Repeat Values In Array

Vyxal, 4 bytes ¨£ẋf Try it Online! This two-byte solution should work, but it seems to bork when the length is an array only of zeros: Try it Online!
  • 11.2k
4 votes

Repeat Values In Array

MATL, 2 bytes Y" Try it online! Or verify all test cases.
  • 101k
4 votes

Repeat Values In Array

Haskell, 27 bytes (concat.).zipWith replicate Try it online! These built-ins have long names, but I haven't found anything shorter.
  • 139k
4 votes

Repeat Values In Array

Pyth, 3 bytes r9C Test suite Takes input as R,A.
  • 4,121
4 votes

Repeat Values In Array

Goruby, 25 22 bytes -3 bytes thanks to G B ->a,b{a.fl{[_1]*b.sh}} Attempt This Online! Ruby, 33 31 bytes -2 bytes thanks to G B ...
  • 5,955
4 votes

Repeat Values In Array

Octave, 7 bytes repelem It seem's that TIO's version of Octave doesn't have this built-in.
  • 37.6k
4 votes

Repeat Values In Array

R, 3 bytes rep Try it online! In R many functions are vectorized and so is rep - it happens to work correctly for this ...
  • 12.3k
3 votes

Repeat Values In Array

Desmos, 72 bytes f(A,R)=[A[i<=∑_{n=1}^{[1...R.length]}R[n]][1]fori=[0...R.total][2...]] Might post an explanation if I feel like it. Try It On Desmos! Try It On ...
  • 8,485
3 votes

Repeat Values In Array

Japt, 6 bytes Takes R as the first input.A byte or 2 could be saved if output could be a 2D-array but I'm guessing a flat array is one of the points of the ...
  • 36k
2 votes

Repeat Values In Array

simply, 87 bytes The code defines an anonymous function that returns the expected result. Nothing special here... ...
2 votes

Repeat Values In Array

PowerShell Core, 30 bytes param($a,$r)$r|%{,$a[$i++]*$_} Try it online!
  • 1,868
2 votes

Repeat Values In Array

Charcoal, 9 bytes IΣEθE§ηκι Attempt This Online! Link is to verbose version of code. Explanation: ...
  • 148k
2 votes

Reconstruct Matrix from its diagonals

Charcoal, 18 bytes I⮌E⊘⊕LθE⊘⊕Lθ⊟§θ⁺ιλ Try it online! Link is to verbose version of code. Takes input from bottom left to top right. Explanation: ...
  • 148k
2 votes

Repeat Values In Array

C (clang), 59 bytes f(*a,*b,n){for(;n--;b++,a++)for(;(*b)--;)printf("%d ",*a);} Try it online!
  • 640
2 votes

Repeat Values In Array

K (ngn/k), 4 bytes ,/#' Try it online!
  • 11.2k
2 votes

Repeat Values In Array

05AB1E, 2 bytes ÅΓ Try it online!
  • 11.2k
1 vote

Repeat Values In Array

Red, 51 bytes func[a b][collect[forall a[loop take b[keep a/1]]]] Try it online!
  • 20.6k
1 vote

Repeat Values In Array

Husk, 1 byte Try it online! Built-in solution. Input is arg1=R, arg2=A Husk, 5 bytes Σz(↑∞ Try it online! Roll-your-own ...
1 vote

N-dimensional identity "matrix"

Vyxal, 6 bytes ẋÞm⁽≈€ Try it Online! My first submission, thanks to emanresu for help with the lambda.

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