Skip to main content
don't depend on ⎕io
Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87

APL (Dyalog Classic), 16 13 12 bytes

-3 thanks to @Adám

⍳∘≢+.×3⌽⊢+⌊(+/+\)1⌽⌽+⌊/

Try it online!Try it online!

⊢+⌊⌽+⌊/ argreverse(arg) + min(arg)

3⌽1⌽ rotate 3 to the left, i.e. 1 to the rightleft

+.×+\ inner product, i.e. multiply element by element and sumpartial sums

⍳∘≢ the indices of the array: 1 2 3 4 (uses 1-based indexing, ⎕io←1+/) sum

APL (Dyalog Classic), 16 13 12 bytes

-3 thanks to @Adám

⍳∘≢+.×3⌽⊢+⌊/

Try it online!

⊢+⌊/ arg + min(arg)

3⌽ rotate 3 to the left, i.e. 1 to the right

+.× inner product, i.e. multiply element by element and sum

⍳∘≢ the indices of the array: 1 2 3 4 (uses 1-based indexing, ⎕io←1)

APL (Dyalog Classic), 16 13 12 bytes

-3 thanks to @Adám

(+/+\)1⌽⌽+⌊/

Try it online!

⌽+⌊/ reverse(arg) + min(arg)

1⌽ rotate 1 to the left

+\ partial sums

+/ sum

-1
Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87

APL (Dyalog Classic), 16 1313 12 bytes

-3 thanks to @Adám

(1⌽⍳4)+⍳∘≢+.×⊢+⌊×3⌽⊢+⌊/

Try it online!Try it online!

⊢+⌊/ arg + min(arg)

⍳4 1 2 3 4

1⌽⍳43⌽ 2rotate 3 4to the left, i.e. 1 to the right

+.× inner product, i.e. multiply element by element and sum

⍳∘≢ the indices of the array: 1 2 3 4 (uses 1-based indexing, ⎕io←1)

APL (Dyalog Classic), 16 13 bytes

-3 thanks to @Adám

(1⌽⍳4)+.×⊢+⌊/

Try it online!

⊢+⌊/ arg + min(arg)

⍳4 1 2 3 4

1⌽⍳4 2 3 4 1

+.× inner product, i.e. multiply element by element and sum

APL (Dyalog Classic), 16 13 12 bytes

-3 thanks to @Adám

⍳∘≢+.×3⌽⊢+⌊/

Try it online!

⊢+⌊/ arg + min(arg)

3⌽ rotate 3 to the left, i.e. 1 to the right

+.× inner product, i.e. multiply element by element and sum

⍳∘≢ the indices of the array: 1 2 3 4 (uses 1-based indexing, ⎕io←1)

added 20 characters in body
Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87

APL (Dyalog Classic), 16 13 bytes

-3 thanks to @Adám

(1⌽⍳4)+.×⊢+⌊/

Try it online!

⊢+⌊/ arg + min(arg)

⍳4 1 2 3 4

1⌽⍳4 2 3 4 1

+.× inner product, i.e. multiply element by element and sum

APL (Dyalog Classic), 16 13 bytes

(1⌽⍳4)+.×⊢+⌊/

Try it online!

APL (Dyalog Classic), 16 13 bytes

-3 thanks to @Adám

(1⌽⍳4)+.×⊢+⌊/

Try it online!

⊢+⌊/ arg + min(arg)

⍳4 1 2 3 4

1⌽⍳4 2 3 4 1

+.× inner product, i.e. multiply element by element and sum

added 20 characters in body
Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87
Loading
Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87
Loading