17
votes
10
votes
Multiply numbers by their depth
Wolfram Language (Mathematica), 12 bytes
#0/@#-#&@-#&
Try it online!
...
7
votes
Multiply numbers by their depth
Python, 51 49 44 43 bytes
f=lambda l,d=0:l*d*-1or[f(s,d-1)for s in l]
Attempt This Online!
This is a really fun abuse of the overloading of the ...
5
votes
5
votes
5
votes
4
votes
Multiply numbers by their depth
BQN, 9 bytes
{+⟜𝕊⍟=¨𝕩}
Try it here!
-5 bytes thanks to @att!
Explanation
{...¨𝕩} for each element n over input...
...
4
votes
3
votes
3
votes
Multiply numbers by their depth
PARI/GP, 25 bytes
f(a)=if(#a',a+apply(f,a))
Attempt This Online!
3
votes
Multiply numbers by their depth
Retina 0.8.2, 51 bytes
\d+
$*
1(?=((\[)|(?<-2>])|(])|[^][])+)
$#3$*
1+
$.&
Try it online! Link includes test cases. Explanation:
...
3
votes
Swap every two elements in a list
Desmos, 42 38 bytes
-4 bytes thanks to @aiden's suggestion and wackscope variables
l=[1...L.length]
f(L)=L[l-1+2mod(l,2)]
Try It On Desmos!
3
votes
3
votes
Swap every two elements in a list
APL, 15 bytes
{,⌽⍵⍴⍨(2÷⍨≢⍵)2}
The same idea as in the existing solution, but implemented as a separate function and two bytes less.
3
votes
Multiply numbers by their depth
Racket, 88 63 bytes
(define(m l[d 0])(if(list? l)(map(λ(n)(m n(+ 1 d)))l)(* l d)))
Try it online!
-25 from removing whitespace, ty @emanresu A!
2
votes
2
votes
Get the best of two Arrays
Vyxal, 8 7 bytes
Zƛ≈[∑|G
-1 byte thanks to @emanresu A
Add the ḋ flag if you want to see the numbers in decimal format.
Try it ...
2
votes
Pairs at every distance
Knight, 91 bytes
;=l~1;W E++'=x'=l+1l'P'1;=aT;=wF;W<=w+1w l;=bF;=s~1;W<=s+1s-l w=b|b?E+'x'sE+'x'+s w=a&a bOa
Enter each number in the input list on their ...
2
votes
Flood fill by distance
Vyxal, 32 bytes
k₁w≬ƛ£?ÞT›'¥ε∑ṅ}ÞfU↔‹vÞǔ∑:fGε›*‹
Try it Online!
Port of Jonathan Allan's Jelly answer, byte count can certainly be way less.
2
votes
Swap every two elements in a list
sed -n, 10 bytes
2~2{G;p};h
Try it online!
2~2{G;p} For even numbered lines, append hold ...
2
votes
2
votes
2
votes
Multiply numbers by their depth
lin, 26 bytes
"deps1> (.+ \@ ' + ) e&".'
Try it here! Uses stack as nested list.
For testing purposes (use -i ...
2
votes
Multiply numbers by their depth
05AB1E, 23 16 15 bytes
.γd}DžuS뛒ηO*J
Try it online!
-2 thanks to @Kevin Cruijssen
Takes the input list as a string, using ( ...
2
votes
Multiply numbers by their depth
05AB1E, 16 bytes
_"Ddië®δ.V>"©.V*
Try it online or verify all test cases.
Explanation:
First step of this 05AB1E answer of mine.
...
2
votes
Multiply numbers by their depth
Perl 5 -p, 33 bytes
s/\d+/$&*($`=~y|[||-$`=~y|]||)/ge
Try it online!
For each number, depth is determined by counting the ...
2
votes
Multiply numbers by their depth
Ruby, 38 bytes
f=->a,d=0{a*0==0?a*d:a.map{f[_1,d+1]}}
Attempt This Online!
2
votes
Multiply numbers by their depth
Ruby, 38 bytes
f=->a,i=1{a.map{f[_1,i+1]rescue _1*i}}
Attempt This Online!
An alternative to Razetime's answer for the same byte count.
2
votes
1
vote
Swap every two elements in a list
ECMAScript 2015 with Lodash (Array), 39 bytes
l=>_.chunk(l,2).flatMap(s=>[s[1],s[0]])
Solution below works if array doesn't chunk evenly (...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
array × 746code-golf × 716
number × 82
matrix × 67
math × 65
decision-problem × 61
sorting × 51
string × 46
integer × 45
arithmetic × 38
sequence × 19
permutations × 19
grid × 18
ragged-list × 18
code-challenge × 16
random × 16
subsequence × 15
combinatorics × 13
counting × 11
optimization × 11
binary-matrix × 11
game × 10
geometry × 9
tips × 7
puzzle-solver × 7