Skip to main content
fixed problem
Source Link
Adám
  • 31.8k
  • 4
  • 131
  • 293

APL (Dyalog Unicode), 16 12 bytesSBCS

Anonymous tacit prefix function. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems. 10-indexed.

+/⊢↑∘∊¯1,¨⍨⍳ 

Try it online!Try it online!

+/ the sum of

⊢↑ the first n elements

∘∊ of the ϵnlisted (flattened)

¯1,¨⍨ negative-one-appended-to-each

 first n ɩndices (0 through n–1

APL (Dyalog Unicode), 16 12 bytesSBCS

Anonymous tacit prefix function. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems. 1-indexed.

+/⊢↑∘∊¯1,¨⍨⍳ 

Try it online!

+/ the sum of

⊢↑ the first n elements

∘∊ of the ϵnlisted (flattened)

¯1,¨⍨ negative-one-appended-to-each

 first n ɩndices (0 through n–1

APL (Dyalog Unicode), 16 12 bytesSBCS

Anonymous tacit prefix function. 0-indexed.

+/⊢↑∘∊¯1,¨⍨⍳ 

Try it online!

+/ the sum of

⊢↑ the first n elements

∘∊ of the ϵnlisted (flattened)

¯1,¨⍨ negative-one-appended-to-each

 first n ɩndices (0 through n–1

deleted 1 character in body
Source Link
Adám
  • 31.8k
  • 4
  • 131
  • 293

APL (Dyalog Unicode), 16 12 bytesSBCS

Anonymous tacit prefix function. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems. 1-indexed.

+/⊢↑∘∊¯1,¨⍨⍳ 

Try it online!Try it online!

+/ the sum of

⊢↑ the first n elements

∘∊ of the ϵnlisted (flattened)

¯1,¨⍨ negative-one-appended-to-each

 first n ɩndices (0 through n–1

APL (Dyalog Unicode), 16 12 bytesSBCS

Anonymous tacit prefix function. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems. 1-indexed.

+/⊢↑∘∊¯1,¨⍨⍳ 

Try it online!

+/ the sum of

⊢↑ the first n elements

∘∊ of the ϵnlisted (flattened)

¯1,¨⍨ negative-one-appended-to-each

 first n ɩndices (0 through n–1

APL (Dyalog Unicode), 16 12 bytesSBCS

Anonymous tacit prefix function. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems. 1-indexed.

+/⊢↑∘∊¯1,¨⍨⍳ 

Try it online!

+/ the sum of

⊢↑ the first n elements

∘∊ of the ϵnlisted (flattened)

¯1,¨⍨ negative-one-appended-to-each

 first n ɩndices (0 through n–1

-4
Source Link
Adám
  • 31.8k
  • 4
  • 131
  • 293

APL (Dyalog Unicode), 1616 12 bytesSBCS

Anonymous tacit prefix lambdafunction. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems. 1-indexed n'th.

{⍵⊃+\0,∊¯1+/⊢↑∘∊¯1,¨⍨⍳⍵}¨⍨⍳ 

Try it online! Try it online!

{}+/dfn; is the argument, e.g. 4:the sum of

⍳⍵⊢↑ɩndices (0 through argument–1);the first [0,1,2,3]

¯1,⍨¨ append –1 to each; [[0,-1],[1,-1],[2,-1],[3,-1]]n elements

∘∊of the ϵnlistnlisted (flattenflattened); [0,-1,1,-1,2,-1,3,-1]

0¯1,¨⍨prepend a zero; [0,0,-1,1,-1,2,-1,3,-1]negative-one-appended-to-each

+\cumulative sum;first [1,0,2,1,4,3,7,6]

⍵⊃n pick the argument'th; ɩndices (0 through 1n–1

APL (Dyalog Unicode), 16 bytesSBCS

Anonymous prefix lambda. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems. 1-indexed n'th.

{⍵⊃+\0,∊¯1,¨⍨⍳⍵} 

Try it online!

{}dfn; is the argument, e.g. 4:

⍳⍵ɩndices (0 through argument–1); [0,1,2,3]

¯1,⍨¨ append –1 to each; [[0,-1],[1,-1],[2,-1],[3,-1]]

ϵnlist (flatten); [0,-1,1,-1,2,-1,3,-1]

0,prepend a zero; [0,0,-1,1,-1,2,-1,3,-1]

+\cumulative sum; [1,0,2,1,4,3,7,6]

⍵⊃ pick the argument'th; 1

APL (Dyalog Unicode), 16 12 bytesSBCS

Anonymous tacit prefix function. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems. 1-indexed.

+/⊢↑∘∊¯1,¨⍨⍳ 

Try it online!

+/the sum of

⊢↑the first n elements

∘∊of the ϵnlisted (flattened)

¯1,¨⍨negative-one-appended-to-each

first n ɩndices (0 through n–1

added 591 characters in body
Source Link
Adám
  • 31.8k
  • 4
  • 131
  • 293
Loading
Source Link
Adám
  • 31.8k
  • 4
  • 131
  • 293
Loading