Skip to main content
deleted 27 characters in body
Source Link
pajonk
  • 18.3k
  • 3
  • 26
  • 74

R, 4333 bytes

Or R>=4.1, 3626 bytes by replacing the word function with \.

function(p,n=sum(p|1),k=1:n)(k*rev(n+1n<-kseq(p))*n)%*%p

Try it online!Try it online!

R, 43 bytes

Or R>=4.1, 36 bytes by replacing the word function with \.

function(p,n=sum(p|1),k=1:n)(k*(n+1-k))%*%p

Try it online!

R, 33 bytes

Or R>=4.1, 26 bytes by replacing the word function with \.

function(p)(rev(n<-seq(p))*n)%*%p

Try it online!

Source Link
pajonk
  • 18.3k
  • 3
  • 26
  • 74

R, 43 bytes

Or R>=4.1, 36 bytes by replacing the word function with \.

function(p,n=sum(p|1),k=1:n)(k*(n+1-k))%*%p

Try it online!