Challenge 2 - Work out the Angle

https://learninghub.kx.com/forums/topic/challenge-2-work-out-the-angle

Thank you to everyone who interacted with my last challenge! The replies were greatly appreciated.

My next challenge is for the math lovers. The triangle below, ABC is a right-angled triangle.

M is the mid-point of the hypotenuse AC.

You are given the lengths AB and BC (which are integers).

The task is to work out the angle MBC.

 

This is my solution:

// reading in 2 sides 
ab: "I"$read0 0 
bc: "I"$read0 0 

// finding the distance 
ac: sqrt((ab*ab)+(bc*bc)) 
bm: ac % 2.0 
mc: bm 

// equalizing the sides 
b: mc 
c: bm 
a: bc 

// where b=c 
// finding the angle in radian 
angle_b_radian: acos(a % (2*b)) 

// converting the radian to degree 
round:{"F"$.Q.f[y]x} 
angle_b_degree: round[((180 * angle_b_radian) % 3.141593);2] 
answer: "i"$angle_b_degree 
show angle_b_degree

I would love to see other approaches to this so if anyone has any comments or suggestions please let me know

You don’t need any of the midpoint calculation, the answer in radians is atan ab%bc

 

Along with 's help on how to convert to degrees, thanks for showing me a quicker way of solving it!

q)ab: 10 
q)bc: 10 
q)atan ab%bc 
0.7853982 
q)atan[ab%bc]*180%acos -1 
45f

 

thanks so much for all the advice ! Now looking back at my own solution and your examples, I should have took advantage of using a function. I can see how using a lamba is more effective than reading in the values. I will most definitely take this on board in the future as I understand the fewer the lines of code the better debugged.