Skip to main content
Commonmark migration
Source Link

#Python 3, 66 bytes

Python 3, 66 bytes

This formerly took advantage of the new assignment expressions ("walrus operator") introduced in Python 3.8. Thanks to commentors, I've taken that out, so it works on previous versions too!

lambda a,b,c:((a*b*c/(b+c-a)/(a+c-b)/(a+b-c)-1)*a*b*c/(a+b+c))**.5

Try it online!

It's based on the same calculations described in Arnauld's answer, but using the perimeter \$p\$ instead of the semiperimeter \$s\$: $$ \begin{aligned}\\ p&=a+b+c\\ &=2s \end{aligned}\\ \therefore d=\sqrt{R^2-\frac{abc}{p}}\\ \text{and } R^2=\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)} $$

The grand total savings of this rearrangement is... two bytes.

Factoring \$p\$ out and expanding the terms in the denominator means I don't have to store \$p\$, saving another three bytes. I also stored the product \$abc\$ in a variable \$m\$, which saved some bytes at first... but it could later be factored out, turning the brackets-and-walrus into a liability, not a savings! Here's the final formula: \begin{aligned} d&=\sqrt{\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)}-\frac{abc}{p}}\\ &=\sqrt{\left(\frac{abc}{(b+c-a)(a+c-b)(a+b-c)}-1\right)\frac{abc}{p}} \end{aligned}

#Python 3, 66 bytes

This formerly took advantage of the new assignment expressions ("walrus operator") introduced in Python 3.8. Thanks to commentors, I've taken that out, so it works on previous versions too!

lambda a,b,c:((a*b*c/(b+c-a)/(a+c-b)/(a+b-c)-1)*a*b*c/(a+b+c))**.5

Try it online!

It's based on the same calculations described in Arnauld's answer, but using the perimeter \$p\$ instead of the semiperimeter \$s\$: $$ \begin{aligned}\\ p&=a+b+c\\ &=2s \end{aligned}\\ \therefore d=\sqrt{R^2-\frac{abc}{p}}\\ \text{and } R^2=\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)} $$

The grand total savings of this rearrangement is... two bytes.

Factoring \$p\$ out and expanding the terms in the denominator means I don't have to store \$p\$, saving another three bytes. I also stored the product \$abc\$ in a variable \$m\$, which saved some bytes at first... but it could later be factored out, turning the brackets-and-walrus into a liability, not a savings! Here's the final formula: \begin{aligned} d&=\sqrt{\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)}-\frac{abc}{p}}\\ &=\sqrt{\left(\frac{abc}{(b+c-a)(a+c-b)(a+b-c)}-1\right)\frac{abc}{p}} \end{aligned}

Python 3, 66 bytes

This formerly took advantage of the new assignment expressions ("walrus operator") introduced in Python 3.8. Thanks to commentors, I've taken that out, so it works on previous versions too!

lambda a,b,c:((a*b*c/(b+c-a)/(a+c-b)/(a+b-c)-1)*a*b*c/(a+b+c))**.5

Try it online!

It's based on the same calculations described in Arnauld's answer, but using the perimeter \$p\$ instead of the semiperimeter \$s\$: $$ \begin{aligned}\\ p&=a+b+c\\ &=2s \end{aligned}\\ \therefore d=\sqrt{R^2-\frac{abc}{p}}\\ \text{and } R^2=\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)} $$

The grand total savings of this rearrangement is... two bytes.

Factoring \$p\$ out and expanding the terms in the denominator means I don't have to store \$p\$, saving another three bytes. I also stored the product \$abc\$ in a variable \$m\$, which saved some bytes at first... but it could later be factored out, turning the brackets-and-walrus into a liability, not a savings! Here's the final formula: \begin{aligned} d&=\sqrt{\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)}-\frac{abc}{p}}\\ &=\sqrt{\left(\frac{abc}{(b+c-a)(a+c-b)(a+b-c)}-1\right)\frac{abc}{p}} \end{aligned}

When reducing the byte count, one should... reduce the byte count.
Source Link
Tim Pederick
  • 1.7k
  • 13
  • 16

#Python 3, 6766 bytes

This formerly took advantage of the new assignment expressions ("walrus operator") introduced in Python 3.8. Thanks to commentors, I've taken that out, so it works on previous versions too!

lambda a,b,c:((a*b*c/(b+c-a)/(a+c-b)/(a+b-c)-1)*a*b*c/(a+b+c))**.5

Try it online!

It's based on the same calculations described in Arnauld's answer, but using the perimeter \$p\$ instead of the semiperimeter \$s\$: $$ \begin{aligned}\\ p&=a+b+c\\ &=2s \end{aligned}\\ \therefore d=\sqrt{R^2-\frac{abc}{p}}\\ \text{and } R^2=\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)} $$

The grand total savings of this rearrangement is... two bytes.

Factoring \$p\$ out and expanding the terms in the denominator means I don't have to store \$p\$, saving another three bytes. I also stored the product \$abc\$ in a variable \$m\$, which saved some bytes at first... but it could later be factored out, turning the brackets-and-walrus into a liability, not a savings! Here's the final formula: \begin{aligned} d&=\sqrt{\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)}-\frac{abc}{p}}\\ &=\sqrt{\left(\frac{abc}{(b+c-a)(a+c-b)(a+b-c)}-1\right)\frac{abc}{p}} \end{aligned}

#Python 3, 67 bytes

This formerly took advantage of the new assignment expressions ("walrus operator") introduced in Python 3.8. Thanks to commentors, I've taken that out, so it works on previous versions too!

lambda a,b,c:((a*b*c/(b+c-a)/(a+c-b)/(a+b-c)-1)*a*b*c/(a+b+c))**.5

Try it online!

It's based on the same calculations described in Arnauld's answer, but using the perimeter \$p\$ instead of the semiperimeter \$s\$: $$ \begin{aligned}\\ p&=a+b+c\\ &=2s \end{aligned}\\ \therefore d=\sqrt{R^2-\frac{abc}{p}}\\ \text{and } R^2=\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)} $$

The grand total savings of this rearrangement is... two bytes.

Factoring \$p\$ out and expanding the terms in the denominator means I don't have to store \$p\$, saving another three bytes. I also stored the product \$abc\$ in a variable \$m\$, which saved some bytes at first... but it could later be factored out, turning the brackets-and-walrus into a liability, not a savings! Here's the final formula: \begin{aligned} d&=\sqrt{\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)}-\frac{abc}{p}}\\ &=\sqrt{\left(\frac{abc}{(b+c-a)(a+c-b)(a+b-c)}-1\right)\frac{abc}{p}} \end{aligned}

#Python 3, 66 bytes

This formerly took advantage of the new assignment expressions ("walrus operator") introduced in Python 3.8. Thanks to commentors, I've taken that out, so it works on previous versions too!

lambda a,b,c:((a*b*c/(b+c-a)/(a+c-b)/(a+b-c)-1)*a*b*c/(a+b+c))**.5

Try it online!

It's based on the same calculations described in Arnauld's answer, but using the perimeter \$p\$ instead of the semiperimeter \$s\$: $$ \begin{aligned}\\ p&=a+b+c\\ &=2s \end{aligned}\\ \therefore d=\sqrt{R^2-\frac{abc}{p}}\\ \text{and } R^2=\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)} $$

The grand total savings of this rearrangement is... two bytes.

Factoring \$p\$ out and expanding the terms in the denominator means I don't have to store \$p\$, saving another three bytes. I also stored the product \$abc\$ in a variable \$m\$, which saved some bytes at first... but it could later be factored out, turning the brackets-and-walrus into a liability, not a savings! Here's the final formula: \begin{aligned} d&=\sqrt{\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)}-\frac{abc}{p}}\\ &=\sqrt{\left(\frac{abc}{(b+c-a)(a+c-b)(a+b-c)}-1\right)\frac{abc}{p}} \end{aligned}

Another byte off.
Source Link
Tim Pederick
  • 1.7k
  • 13
  • 16

#Python 3.8, 67 bytes

This takesformerly took advantage of the new assignment expressions ("walrus operator") introduced in Python 3.8. Thanks to commentors, I've taken that out, so it works on previous versions too!

lambda a,b,c:(((m:=a*b*c)*ma*b*c/(b+c-a)/(a+c-b)/(a+b-c)-m1)*a*b*c/(a+b+c))**.5

Try it online!Try it online!

It's based on the same calculations described in Arnauld's answer, but using the perimeter \$p\$ instead of the semiperimeter \$s\$: $$ \begin{aligned}\\ p&=a+b+c\\ &=2s \end{aligned}\\ \therefore d=\sqrt{R^2-\frac{abc}{p}}\\ \text{and } R^2=\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)} $$

The grand total savings of this rearrangement is... two bytes. Storing the product \$abc\$ in \$m\$ saves another one two bytes.

Factoring \$p\$ out and expanding the terms in the denominator means I don't have to store \$p\$, saving another three bytes. I also stored the product \$abc\$ in a variable \$m\$, which saved some bytes at first... but it could later be factored out, turning the brackets-and-walrus into a liability, not a savings! Here's the final formula: \begin{aligned} d&=\sqrt{\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)}-\frac{abc}{p}}\\ &=\sqrt{\left(\frac{\left(abc\right)^2}{(b+c-a)(a+c-b)(a+b-c)}-abc\right)\frac{1}{p}} \end{aligned}\begin{aligned} d&=\sqrt{\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)}-\frac{abc}{p}}\\ &=\sqrt{\left(\frac{abc}{(b+c-a)(a+c-b)(a+b-c)}-1\right)\frac{abc}{p}} \end{aligned}

#Python 3.8, 67 bytes

This takes advantage of the new assignment expressions ("walrus operator") introduced in Python 3.8.

lambda a,b,c:(((m:=a*b*c)*m/(b+c-a)/(a+c-b)/(a+b-c)-m)/(a+b+c))**.5

Try it online!

It's based on the same calculations described in Arnauld's answer, but using the perimeter \$p\$ instead of the semiperimeter \$s\$: $$ \begin{aligned}\\ p&=a+b+c\\ &=2s \end{aligned}\\ \therefore d=\sqrt{R^2-\frac{abc}{p}}\\ \text{and } R^2=\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)} $$

The grand total savings of this rearrangement is... two bytes. Storing the product \$abc\$ in \$m\$ saves another one two bytes.

Factoring \$p\$ out and expanding the terms in the denominator means I don't have to store \$p\$, saving another three bytes: \begin{aligned} d&=\sqrt{\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)}-\frac{abc}{p}}\\ &=\sqrt{\left(\frac{\left(abc\right)^2}{(b+c-a)(a+c-b)(a+b-c)}-abc\right)\frac{1}{p}} \end{aligned}

#Python 3, 67 bytes

This formerly took advantage of the new assignment expressions ("walrus operator") introduced in Python 3.8. Thanks to commentors, I've taken that out, so it works on previous versions too!

lambda a,b,c:((a*b*c/(b+c-a)/(a+c-b)/(a+b-c)-1)*a*b*c/(a+b+c))**.5

Try it online!

It's based on the same calculations described in Arnauld's answer, but using the perimeter \$p\$ instead of the semiperimeter \$s\$: $$ \begin{aligned}\\ p&=a+b+c\\ &=2s \end{aligned}\\ \therefore d=\sqrt{R^2-\frac{abc}{p}}\\ \text{and } R^2=\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)} $$

The grand total savings of this rearrangement is... two bytes.

Factoring \$p\$ out and expanding the terms in the denominator means I don't have to store \$p\$, saving another three bytes. I also stored the product \$abc\$ in a variable \$m\$, which saved some bytes at first... but it could later be factored out, turning the brackets-and-walrus into a liability, not a savings! Here's the final formula: \begin{aligned} d&=\sqrt{\frac{\left(abc\right)^2}{p(p-2a)(p-2b)(p-2c)}-\frac{abc}{p}}\\ &=\sqrt{\left(\frac{abc}{(b+c-a)(a+c-b)(a+b-c)}-1\right)\frac{abc}{p}} \end{aligned}

Saved 4 bytes.
Source Link
Tim Pederick
  • 1.7k
  • 13
  • 16
Loading
Source Link
Tim Pederick
  • 1.7k
  • 13
  • 16
Loading