Skip to main content
add whitespace
Source Link
S.S. Anne
  • 3.3k
  • 10
  • 31

Go, 79 bytes

func f(a[]float64,i int)float64{s:=0.;for
for _,v:=range a{s+=v};return
return a[i]/s*100}

Try it online!

This has a nice amount of accuracy. It takes a Go slice and uses range to calculate the sum.

Try it online!

Go, 79 bytes

func f(a[]float64,i int)float64{s:=0.;for _,v:=range a{s+=v};return a[i]/s*100}

Try it online!

This has a nice amount of accuracy. It takes a Go slice and uses range to calculate the sum.

Go, 79 bytes

func f(a[]float64,i int)float64{s:=0.
for _,v:=range a{s+=v}
return a[i]/s*100}

This has a nice amount of accuracy. It takes a Go slice and uses range to calculate the sum.

Try it online!

Source Link
S.S. Anne
  • 3.3k
  • 10
  • 31

Go, 79 bytes

func f(a[]float64,i int)float64{s:=0.;for _,v:=range a{s+=v};return a[i]/s*100}

Try it online!

This has a nice amount of accuracy. It takes a Go slice and uses range to calculate the sum.