Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

1 of 3
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

R, 49 bytes

function(l)Reduce(function(x,y)(x+y)/2,l)-mean(l)

Try it online!

Pretty straightforward implementation. Reduce(mean,l)-mean(l) would be nice, but mean is not a binary function. Alas.

R, 51 bytes

function(l,L=sum(l|1))sum(l*2^(c(1,1:(L-1))-L)-l/L)

Try it online!

This approach is perhaps more amenable to an improvement that I have overlooked.

Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

AltStyle によって変換されたページ (->オリジナル) /