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 Answer

Added alternate version
Source Link
mabel
  • 1.7k
  • 14
  • 18

Python 3.8 (pre-release), (削除) 70 (削除ここまで) 69 bytes

-1 byte thanks to Kyle Gullion

returns (mean, p_mean, trend)

lambda x:(m:=sum(x)/len(x),[p:=x[0],*[p:=(p+n)/2for n in x]][-1],p-m)

Try it online!

Alternate version with more of a reducer implementation (89 bytes):

lambda x:(m:=sum(x)/(l:=len(x)),[x:=[sum(x[0:2])/2]+x[2:]for n in range(l-1)][-1],x[0]-m)

Although this is longer, I suspect this reducer implementation may be useful for future python 3.8 code golfing.

Try it online!

I know there has to be some more clever tricks to golf this further...

Python 3.8 (pre-release), (削除) 70 (削除ここまで) 69 bytes

-1 byte thanks to Kyle Gullion

returns (mean, p_mean, trend)

lambda x:(m:=sum(x)/len(x),[p:=x[0],*[p:=(p+n)/2for n in x]][-1],p-m)

Try it online!

I know there has to be some more clever tricks to golf this further...

Python 3.8 (pre-release), (削除) 70 (削除ここまで) 69 bytes

-1 byte thanks to Kyle Gullion

returns (mean, p_mean, trend)

lambda x:(m:=sum(x)/len(x),[p:=x[0],*[p:=(p+n)/2for n in x]][-1],p-m)

Try it online!

Alternate version with more of a reducer implementation (89 bytes):

lambda x:(m:=sum(x)/(l:=len(x)),[x:=[sum(x[0:2])/2]+x[2:]for n in range(l-1)][-1],x[0]-m)

Although this is longer, I suspect this reducer implementation may be useful for future python 3.8 code golfing.

Try it online!

I know there has to be some more clever tricks to golf this further...

tio link disappeared
Source Link
mabel
  • 1.7k
  • 14
  • 18

Python 3.8 (pre-release), (削除) 70 (削除ここまで) 69 bytes

-1 byte thanks to Kyle Gullion

returns (mean, p_mean, trend)

lambda x:(m:=sum(x)/len(x),[p:=x[0],*[p:=(p+n)/2for n in x]][-1],p-m)

Try it online!

I know there has to be some more clever tricks to golf this further...

Python 3.8 (pre-release), (削除) 70 (削除ここまで) 69 bytes

-1 byte thanks to Kyle Gullion

returns (mean, p_mean, trend)

lambda x:(m:=sum(x)/len(x),[p:=x[0],*[p:=(p+n)/2for n in x]][-1],p-m)

I know there has to be some more clever tricks to golf this further...

Python 3.8 (pre-release), (削除) 70 (削除ここまで) 69 bytes

-1 byte thanks to Kyle Gullion

returns (mean, p_mean, trend)

lambda x:(m:=sum(x)/len(x),[p:=x[0],*[p:=(p+n)/2for n in x]][-1],p-m)

Try it online!

I know there has to be some more clever tricks to golf this further...

-1 byte
Source Link
mabel
  • 1.7k
  • 14
  • 18

Python 3.8 (pre-release), 70(削除) 70 (削除ここまで) 69 bytes

-1 byte thanks to Kyle Gullion

returns (mean, p_mean, trend)

lambda x:(m:=sum(x)/len(x),([p:=x[0]]+[p=x[0],*[p:=(p+n)/2for n in x])[x]][-1],p-m)

Try it online!

I know there has to be some more clever tricks to golf this further...

Python 3.8 (pre-release), 70 bytes

returns (mean, p_mean, trend)

lambda x:(m:=sum(x)/len(x),([p:=x[0]]+[p:=(p+n)/2for n in x])[-1],p-m)

Try it online!

I know there has to be some more clever tricks to golf this further...

Python 3.8 (pre-release), (削除) 70 (削除ここまで) 69 bytes

-1 byte thanks to Kyle Gullion

returns (mean, p_mean, trend)

lambda x:(m:=sum(x)/len(x),[p:=x[0],*[p:=(p+n)/2for n in x]][-1],p-m)

I know there has to be some more clever tricks to golf this further...

Source Link
mabel
  • 1.7k
  • 14
  • 18
Loading

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