Skip to main content
added 24 characters in body
Source Link
Mitchell Spector
  • 8.1k
  • 2
  • 18
  • 36

dc, 68 bytes

9k?scsbsa[lad*lblc-d*-lblc*/v]dsFxlalbsasblFxlalcsasclFx++lalblc++*p

Try it online!

Or check out all the test cases.

This is a direct implementation of Surculose Sputum's nice answer (the original iterative one), which is the type of formula that dc ("desk calculator") can be pretty good for!

Explanation:

9k     Set precision to 9 decimal places.
?      Read input line (push a, b, and c on the stack).
scsbsa Save the input numbers in registers a, b, and c.
[      Start a macro.
       This macro takes the values in registers a, b, and c,
       and computes the first square root in the formula,
       leaving that result on the stack, as follows:
  lad*   Push a^2.
  lblc-  Push b-c.
  d*     Replace b-c at the top of the stack with (b-c)^2.
  -      Replace the top 2 items on the stack with a^2-(b-c)^2.
  lblc*  Push b*c.
  /      Divide to compute the formula under the radical sign.
  v      Compute the square root.
]      End of macro.
dsFx       Save macro for later use under the name F, and also run it now.
lalbsasb   Swap registers a and b.
lFx        Call macro F to compute the second square root.
lalcsasc   Swap registers a and c.
lFx        Call macro F to compute the third square root.
++         Add the three square roots.
lalblc++   Compute a+b+c.
*          Multiply a+b+c by the sum of the square roots.
p          Print the result.

dc, 68 bytes

9k?scsbsa[lad*lblc-d*-lblc*/v]dsFxlalbsasblFxlalcsasclFx++lalblc++*p

Try it online!

Or check out all the test cases.

This is a direct implementation of Surculose Sputum's nice answer, which is the type of formula that dc ("desk calculator") can be pretty good for!

Explanation:

9k     Set precision to 9 decimal places.
?      Read input line (push a, b, and c on the stack).
scsbsa Save the input numbers in registers a, b, and c.
[      Start a macro.
       This macro takes the values in registers a, b, and c,
       and computes the first square root in the formula,
       leaving that result on the stack, as follows:
  lad*   Push a^2.
  lblc-  Push b-c.
  d*     Replace b-c at the top of the stack with (b-c)^2.
  -      Replace the top 2 items on the stack with a^2-(b-c)^2.
  lblc*  Push b*c.
  /      Divide to compute the formula under the radical sign.
  v      Compute the square root.
]      End of macro.
dsFx       Save macro for later use under the name F, and also run it now.
lalbsasb   Swap registers a and b.
lFx        Call macro F to compute the second square root.
lalcsasc   Swap registers a and c.
lFx        Call macro F to compute the third square root.
++         Add the three square roots.
lalblc++   Compute a+b+c.
*          Multiply a+b+c by the sum of the square roots.
p          Print the result.

dc, 68 bytes

9k?scsbsa[lad*lblc-d*-lblc*/v]dsFxlalbsasblFxlalcsasclFx++lalblc++*p

Try it online!

Or check out all the test cases.

This is a direct implementation of Surculose Sputum's answer (the original iterative one), which is the type of formula that dc ("desk calculator") can be pretty good for!

Explanation:

9k     Set precision to 9 decimal places.
?      Read input line (push a, b, and c on the stack).
scsbsa Save the input numbers in registers a, b, and c.
[      Start a macro.
       This macro takes the values in registers a, b, and c,
       and computes the first square root in the formula,
       leaving that result on the stack, as follows:
  lad*   Push a^2.
  lblc-  Push b-c.
  d*     Replace b-c at the top of the stack with (b-c)^2.
  -      Replace the top 2 items on the stack with a^2-(b-c)^2.
  lblc*  Push b*c.
  /      Divide to compute the formula under the radical sign.
  v      Compute the square root.
]      End of macro.
dsFx       Save macro for later use under the name F, and also run it now.
lalbsasb   Swap registers a and b.
lFx        Call macro F to compute the second square root.
lalcsasc   Swap registers a and c.
lFx        Call macro F to compute the third square root.
++         Add the three square roots.
lalblc++   Compute a+b+c.
*          Multiply a+b+c by the sum of the square roots.
p          Print the result.
added 58 characters in body
Source Link
Mitchell Spector
  • 8.1k
  • 2
  • 18
  • 36

dc, 68 bytes

9k?scsbsa[lad*lblc-d*-lblc*/v]dsFxlalbsasblFxlalcsasclFx++lalblc++*p

Try it online!

Or check out all the test cases.

This is a direct implementation of Surculose Sputum's nice answer, which is the type of formula that dc ("desk calculator") can be pretty good for!

Explanation:

9k     Set precision to 9 decimal places.
?      Read input line (push a, b, and c on the stack).
scsbsa Save the input numbers in registers a, b, and c.
[      Start a macro.
       This macro takes the values in registers a, b, and c,
       and computes the first square root in the formula,
       leaving that result on the stack, as follows:
  lad*   Push a^2.
  lblc-  Push b-c.
  d*     Replace b-c at the top of the stack with (b-c)^2.
  -      Replace the top 2 items on the stack with a^2-(b-c)^2.
  lblc*  Push b*c.
  /      Divide to compute the formula under the radical sign.
  v      Compute the square root.
]      End of macro.
dsFx       Save macro for later use under the name F, and also run it now.
lalbsasb   Swap registers a and b.
lFx        Call macro F to compute the second square root.
lalcsasc   Swap registers a and c.
lFx        Call macro F to compute the third square root.
++         Add the three square roots.
lalblc++   Compute a+b+c.
*          Multiply a+b+c by the sum of the square roots.
p          Print the result.

dc, 68 bytes

9k?scsbsa[lad*lblc-d*-lblc*/v]dsFxlalbsasblFxlalcsasclFx++lalblc++*p

Try it online!

Or check out all the test cases.

This is a direct implementation of Surculose Sputum's nice answer, which is the type of formula that dc ("desk calculator") can be pretty good for!

Explanation:

9k     Set precision to 9 decimal places.
?      Read input line (push a, b, and c on the stack).
scsbsa Save the input numbers in registers a, b, and c.
[      Start a macro.
       This macro takes the values in registers a, b, and c,
       and computes the first square root in the formula:
  lad*   Push a^2.
  lblc-  Push b-c.
  d*     Replace b-c at the top of the stack with (b-c)^2.
  -      Replace the top 2 items on the stack with a^2-(b-c)^2.
  lblc*  Push b*c.
  /      Divide to compute the formula under the radical sign.
  v      Compute the square root.
]      End of macro.
dsFx       Save macro for later use under the name F, and also run it now.
lalbsasb   Swap registers a and b.
lFx        Call macro F to compute the second square root.
lalcsasc   Swap registers a and c.
lFx        Call macro F to compute the third square root.
++         Add the three square roots.
lalblc++   Compute a+b+c.
*          Multiply a+b+c by the sum of the square roots.
p          Print the result.

dc, 68 bytes

9k?scsbsa[lad*lblc-d*-lblc*/v]dsFxlalbsasblFxlalcsasclFx++lalblc++*p

Try it online!

Or check out all the test cases.

This is a direct implementation of Surculose Sputum's nice answer, which is the type of formula that dc ("desk calculator") can be pretty good for!

Explanation:

9k     Set precision to 9 decimal places.
?      Read input line (push a, b, and c on the stack).
scsbsa Save the input numbers in registers a, b, and c.
[      Start a macro.
       This macro takes the values in registers a, b, and c,
       and computes the first square root in the formula,
       leaving that result on the stack, as follows:
  lad*   Push a^2.
  lblc-  Push b-c.
  d*     Replace b-c at the top of the stack with (b-c)^2.
  -      Replace the top 2 items on the stack with a^2-(b-c)^2.
  lblc*  Push b*c.
  /      Divide to compute the formula under the radical sign.
  v      Compute the square root.
]      End of macro.
dsFx       Save macro for later use under the name F, and also run it now.
lalbsasb   Swap registers a and b.
lFx        Call macro F to compute the second square root.
lalcsasc   Swap registers a and c.
lFx        Call macro F to compute the third square root.
++         Add the three square roots.
lalblc++   Compute a+b+c.
*          Multiply a+b+c by the sum of the square roots.
p          Print the result.
added 296 characters in body
Source Link
Mitchell Spector
  • 8.1k
  • 2
  • 18
  • 36

dc, 68 bytes

9k?scsbsa[lad*lblc-d*-lblc*/v]dsFxlalbsasblFxlalcsasclFx++lalblc++*p

Try it online!

Or check out all the test cases.

This is a direct implementation of Surculose Sputum's nice answer, which is the type of formula that dc ("desk calculator") can be pretty good for!

Explanation:

9k     Set precision to 9 decimal places.
?      Read input line (push a, b, and c on the stack).
scsbsa Save the input numbers in registers a, b, and c.
[      Start a macro.
       This macro takes the values in registers a, b, and c,
       and computes the first square root in the formula:
  lad*   Push a^2.
  lblc-  Push b-c.
  d*     Replace b-c at the top of the stack with (b-c)^2.
  -      Replace the top 2 items on the stack with a^2-(b-c)^2.
  lblc*  Push b*c.
  /      Divide to compute the formula under the radical sign.
  v      Compute the square root.
]      End of macro.
dsFx       Save macro for later use under the name F, and also run it now.
lalbsasb   Swap registers a and b.
lFx        Call macro F to compute the second square root.
lalcsasc   Swap registers a and c.
lFx        Call macro F to compute the third square root.
++         Add the three square roots.
lalblc++   Compute a+b+c.
*          Multiply a+b+c by the sum of the square roots.
p          Print the result.

dc, 68 bytes

9k?scsbsa[lad*lblc-d*-lblc*/v]dsFxlalbsasblFxlalcsasclFx++lalblc++*p

Try it online!

Or check out all the test cases.

This is a direct implementation of Surculose Sputum's nice answer, which is the type of formula that dc ("desk calculator") can be pretty good for!

dc, 68 bytes

9k?scsbsa[lad*lblc-d*-lblc*/v]dsFxlalbsasblFxlalcsasclFx++lalblc++*p

Try it online!

Or check out all the test cases.

This is a direct implementation of Surculose Sputum's nice answer, which is the type of formula that dc ("desk calculator") can be pretty good for!

Explanation:

9k     Set precision to 9 decimal places.
?      Read input line (push a, b, and c on the stack).
scsbsa Save the input numbers in registers a, b, and c.
[      Start a macro.
       This macro takes the values in registers a, b, and c,
       and computes the first square root in the formula:
  lad*   Push a^2.
  lblc-  Push b-c.
  d*     Replace b-c at the top of the stack with (b-c)^2.
  -      Replace the top 2 items on the stack with a^2-(b-c)^2.
  lblc*  Push b*c.
  /      Divide to compute the formula under the radical sign.
  v      Compute the square root.
]      End of macro.
dsFx       Save macro for later use under the name F, and also run it now.
lalbsasb   Swap registers a and b.
lFx        Call macro F to compute the second square root.
lalcsasc   Swap registers a and c.
lFx        Call macro F to compute the third square root.
++         Add the three square roots.
lalblc++   Compute a+b+c.
*          Multiply a+b+c by the sum of the square roots.
p          Print the result.
added 296 characters in body
Source Link
Mitchell Spector
  • 8.1k
  • 2
  • 18
  • 36
Loading
Source Link
Mitchell Spector
  • 8.1k
  • 2
  • 18
  • 36
Loading