Skip to main content
2 of 5
saved 2 bytes and added an explanation
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

#JavaScript (ES7), 55 53 bytes

Based on the direct formula used by xnor.

Takes input as an array.

a=>a.map(n=>1/a?n/2/a:a=((n+Math.hypot(...a))/2)**.5)

Try it online!

###How?

Given an array \$[a,b,c,d]\$, this computes:

$$x=\sqrt{\frac{a+\sqrt{a^2+b^2+c^2+d^2}}{2}}$$

And returns:

$$\left[x,\frac{b}{2x},\frac{c}{2x},\frac{d}{2x}\right]$$

a =>                            // a[] = input array
  a.map(n =>                    // for each value n in a[]:
    1 / a ?                     //   if a is numeric (2nd to 4th iteration):
      n / 2 / a                 //     yield n / 2a
    :                           //   else:
      a = (                     //     compute x (as defined above) and store it in a
        (n + Math.hypot(...a))  //     we use Math.hypot(...a) to compute:
        / 2                     //     (a[0]**2 + a[1]**2 + a[2]**2 + a[3]**2) ** 0.5
      ) ** .5                   //
  )                             // end of map()
Arnauld
  • 197.7k
  • 20
  • 179
  • 650