Skip to main content
added 56 characters in body
Source Link
plannapus
  • 9k
  • 23
  • 49

R : 4848 43 characters

f=function(a,b,c...){prod(sum(a+b+c...)/2-c(0,a,b,c...))^.5} 

Using Heron's formula as well but taking advantage of R's vectorization.
Thanks to @flodel for the idea of the ellipsis.

Usage:

f(2,3,4) [1] 2.904738 f(3,4,5) [1] 6 

R : 48 characters

f=function(a,b,c){prod((a+b+c)/2-c(0,a,b,c))^.5} 

Using Heron's formula as well but taking advantage of R's vectorization.

Usage:

f(2,3,4) [1] 2.904738 f(3,4,5) [1] 6 

R : 48 43 characters

f=function(...)prod(sum(...)/2-c(0,...))^.5 

Using Heron's formula as well but taking advantage of R's vectorization.
Thanks to @flodel for the idea of the ellipsis.

Usage:

f(2,3,4) [1] 2.904738 f(3,4,5) [1] 6 
Source Link
plannapus
  • 9k
  • 23
  • 49

R : 48 characters

f=function(a,b,c){prod((a+b+c)/2-c(0,a,b,c))^.5} 

Using Heron's formula as well but taking advantage of R's vectorization.

Usage:

f(2,3,4) [1] 2.904738 f(3,4,5) [1] 6