Square side pinpointing
Seriously, 11 bytes
A port of my TI-BASIC answer. Calculates mean(X)+i*(X-mean(X))
.
,;Σ½;)±+ï*+
Explanation:
, Read input
; Duplicate
Σ½ Half the sum (the mean) of the top copy
; Copy the mean
) Rotate stack to the left
Now there's a copy of the mean on the bottom
±+ Negate mean and add to input list
ï* Multiply by i
+ Add to mean
Input as a list of two complex numbers: [1-1j,4+2j]
, and output in the same format: [(4-1j), (1+2j)]
.
Seriously, 25 bytes
,i││-++½)+-+½)++-½)±+++½)
Takes input as a list: [x1,y1,x2,y2]
Same strategy as my Python answer, but in Seriously!
Explanation:
, get input
i flatten list
││ duplicate stack twice, so that we have 4 copies of the input total
-++½) calculate the first x-value using the formula (x1-y1+x2+y2)/2, and shove it to the end of the stack
+-+½) calculate the first y-value using (x1+y1-x2+y2)/2, and shove it to the end of the stack
++-½) calculate the second x-value using (x1+y2+x2-y2)/2, and shove it to the end of the stack
±+++½) calculate the second y-value using (-x1+y1+x2+y2)/2, and shove it to the end of the stack
Try it online
TI-BASIC, 16 bytes
For a TI-83+ or 84+ series calculator.
Input X
i∟X+.5sum(∟X-i∟X
Unless I misunderstood, OP said they were fine with taking input and output as complex numbers. The i
here is the imaginary unit, not the statistics variable.
TI-BASIC has a mean(
function, but annoyingly it doesn't work with complex lists, throwing an ERR:DATA TYPE
.
Input in the form {1-i,4+2i}
for [[1,-1],[4,2]]
. Output is in the form {4-i 1+2i}
for [[1,2][4,-1]]
.