Skip to main content
Commonmark migration
Source Link

#Java 8, 104 bytes

Java 8, 104 bytes

(a,b,c)->{double r=0,t,n=3;for(;n-->0;t=a,a=b,b=c,c=t)r+=(a+b+c)*Math.sqrt(c*c/a/b-a/b-b/a+2);return r;}

Iterative port of @SurculoseSputum's Python answer, so make sure to upvote him!

Try it online.

Explanation:

(a,b,c)->{                  // Method with double as all three parameters and return-type
  double r=0,               // Result-sum, starting at 0
         t,                 // Temp-double
  n=3;for(;n-->0            // Loop 3 times:
          ;                 //   After every iteration:
           t=a,a=b,b=c,c=t) //    Rotate `a,b,c` to `b,c,a` respectively
    r+=                     //  Increase the result-sum by:
      (a+b+c)               //   The sum of `a,b,c`
      *Math.sqrt(           //   Multiplied by the square-root of:
         c*c                //    `c` squared
            /a/b            //    Divided by both `a` and `b`
         -a/b               //    Minus `a` divided by `b`
         -b/a               //    as well as `b` divided by `a`
         +2);               //    Plus 2
  return r;}                //  After the loop, return the result-sum

Or as a single formula:

$$p = (a+b+c)\sqrt{c^2\div a\div b-\frac{a}{b}-\frac{b}{a}+2}$$ $$+(a+b+c)\sqrt{a^2\div b\div c-\frac{b}{c}-\frac{c}{b}+2}$$ $$+(a+b+c)\sqrt{b^2\div c\div a-\frac{c}{a}-\frac{a}{c}+2}$$

#Java 8, 104 bytes

(a,b,c)->{double r=0,t,n=3;for(;n-->0;t=a,a=b,b=c,c=t)r+=(a+b+c)*Math.sqrt(c*c/a/b-a/b-b/a+2);return r;}

Iterative port of @SurculoseSputum's Python answer, so make sure to upvote him!

Try it online.

Explanation:

(a,b,c)->{                  // Method with double as all three parameters and return-type
  double r=0,               // Result-sum, starting at 0
         t,                 // Temp-double
  n=3;for(;n-->0            // Loop 3 times:
          ;                 //   After every iteration:
           t=a,a=b,b=c,c=t) //    Rotate `a,b,c` to `b,c,a` respectively
    r+=                     //  Increase the result-sum by:
      (a+b+c)               //   The sum of `a,b,c`
      *Math.sqrt(           //   Multiplied by the square-root of:
         c*c                //    `c` squared
            /a/b            //    Divided by both `a` and `b`
         -a/b               //    Minus `a` divided by `b`
         -b/a               //    as well as `b` divided by `a`
         +2);               //    Plus 2
  return r;}                //  After the loop, return the result-sum

Or as a single formula:

$$p = (a+b+c)\sqrt{c^2\div a\div b-\frac{a}{b}-\frac{b}{a}+2}$$ $$+(a+b+c)\sqrt{a^2\div b\div c-\frac{b}{c}-\frac{c}{b}+2}$$ $$+(a+b+c)\sqrt{b^2\div c\div a-\frac{c}{a}-\frac{a}{c}+2}$$

Java 8, 104 bytes

(a,b,c)->{double r=0,t,n=3;for(;n-->0;t=a,a=b,b=c,c=t)r+=(a+b+c)*Math.sqrt(c*c/a/b-a/b-b/a+2);return r;}

Iterative port of @SurculoseSputum's Python answer, so make sure to upvote him!

Try it online.

Explanation:

(a,b,c)->{                  // Method with double as all three parameters and return-type
  double r=0,               // Result-sum, starting at 0
         t,                 // Temp-double
  n=3;for(;n-->0            // Loop 3 times:
          ;                 //   After every iteration:
           t=a,a=b,b=c,c=t) //    Rotate `a,b,c` to `b,c,a` respectively
    r+=                     //  Increase the result-sum by:
      (a+b+c)               //   The sum of `a,b,c`
      *Math.sqrt(           //   Multiplied by the square-root of:
         c*c                //    `c` squared
            /a/b            //    Divided by both `a` and `b`
         -a/b               //    Minus `a` divided by `b`
         -b/a               //    as well as `b` divided by `a`
         +2);               //    Plus 2
  return r;}                //  After the loop, return the result-sum

Or as a single formula:

$$p = (a+b+c)\sqrt{c^2\div a\div b-\frac{a}{b}-\frac{b}{a}+2}$$ $$+(a+b+c)\sqrt{a^2\div b\div c-\frac{b}{c}-\frac{c}{b}+2}$$ $$+(a+b+c)\sqrt{b^2\div c\div a-\frac{c}{a}-\frac{a}{c}+2}$$

Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 8, 104 bytes

(a,b,c)->{double r=0,t,n=3;for(;n-->0;t=a,a=b,b=c,c=t)r+=(a+b+c)*Math.sqrt(c*c/a/b-a/b-b/a+2);return r;}

Iterative port of @SurculoseSputum's Python answer, so make sure to upvote him!

Try it online.

Explanation:

(a,b,c)->{                  // Method with double as all three parameters and return-type
  double r=0,               // Result-sum, starting at 0
         t,                 // Temp-double
  n=3;for(;n-->0            // Loop 3 times:
          ;                 //   After every iteration:
           t=a,a=b,b=c,c=t) //    Rotate `a,b,c` to `b,c,a` respectively
    r+=                     //  Increase the result-sum by:
      (a+b+c)               //   The sum of `a,b,c`
      *Math.sqrt(           //   Multiplied by the square-root of:
         c*c                //    `c` squared
            /a/b            //    Divided by both `a` and `b`
         -a/b               //    Minus `a` divided by `b`
         -b/a               //    as well as `b` divided by `a`
         +2);               //    Plus 2
  return r;}                //  After the loop, return the result-sum

Or as a single formula:

$$p = (a+b+c)\sqrt{c^2\div a\div b-\frac{a}{b}-\frac{b}{a}+2}$$ $$+(a+b+c)\sqrt{a^2\div b\div c-\frac{b}{c}-\frac{c}{b}+2}$$ $$+(a+b+c)\sqrt{b^2\div c\div a-\frac{c}{a}-\frac{a}{c}+2}$$