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 162 characters in body
Source Link
Gymhgy
  • 8k
  • 12
  • 35

C# (Visual C# Interactive Compiler), 163177 bytes

double f(double[]g)=>g.All(c=>c==g[0]c=>Math.Abs(c-g[0])<1e-9)?g[0]:f(new[]{g.Sum()/(z=g.Length),Math.Pow(g.Aggregate((a,b)=>a*b),1d/z),z/g.Sum(x=>1/x),Math.Sqrt(g.Sum(x=>x*x)/z)});int z;

Last two cases throw StackOverflowExceptionThanks to @KevinCruijjsen for pointing out that using floating point precision was causing problems! Would be 163 bytes if doubles were perfectly precise.

Try it online! Try it online!

C# (Visual C# Interactive Compiler), 163 bytes

double f(double[]g)=>g.All(c=>c==g[0])?g[0]:f(new[]{g.Sum()/(z=g.Length),Math.Pow(g.Aggregate((a,b)=>a*b),1d/z),z/g.Sum(x=>1/x),Math.Sqrt(g.Sum(x=>x*x)/z)});int z;

Last two cases throw StackOverflowException.

Try it online!

C# (Visual C# Interactive Compiler), 177 bytes

double f(double[]g)=>g.All(c=>Math.Abs(c-g[0])<1e-9)?g[0]:f(new[]{g.Sum()/(z=g.Length),Math.Pow(g.Aggregate((a,b)=>a*b),1d/z),z/g.Sum(x=>1/x),Math.Sqrt(g.Sum(x=>x*x)/z)});int z;

Thanks to @KevinCruijjsen for pointing out that using floating point precision was causing problems! Would be 163 bytes if doubles were perfectly precise.

Try it online!

Source Link
Gymhgy
  • 8k
  • 12
  • 35

C# (Visual C# Interactive Compiler), 163 bytes

double f(double[]g)=>g.All(c=>c==g[0])?g[0]:f(new[]{g.Sum()/(z=g.Length),Math.Pow(g.Aggregate((a,b)=>a*b),1d/z),z/g.Sum(x=>1/x),Math.Sqrt(g.Sum(x=>x*x)/z)});int z;

Last two cases throw StackOverflowException.

Try it online!

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