Hi! I'm Arctic Kona, an Icelandic arctic fox (/Vulpes lagopus fuliginosus/). Interested in all things technology and already enjoyed 2 great summers (~ 16 "fox years" old).
constthirdAngle=(angle1,angle2)=>(angle1&&angle2&&(angle3=180-(angle1+angle2))>0)?angle3:'Invalid - Sum of all angles of a triangle should be 180 degrees';
Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
functhirdAngle(a,bint)(int,error){if(a+b)>=180{return0,errors.New("Input angles sum is greater than or equal to 180 degress, this cannot be a triangle")}ifa==0||b==0{return0,errors.New("Input angle cannot be zero, cannot be a triangle")}angle:=360-a-b// sum of angles must be 360 degressreturnangle,nil}
ANSI C
Run with
~$ gcc -lm <file_name> && ./a.outKept it simple
My solution in js
What happens if I enter
thirdAngle(0,0)?Good catch. Edited. But the challenge is to deal with positive integers so didn't take 0 into account as it is neither positive nor negative integer.
True enough. But why code purely for specs when coding for the edge and error cases takes just a few more minutes?
Keeping it simple in bash
Running through the examples on the cmd:
BTW the challenge on Kata only tests for valid triangles,
was sufficient in JS
This oughta do it for Elixir.
In Go!
Go Playground
Elm
Test it online
Here.
Solution in APL
(using Dyalog APL)
Tests:
Try it online!
What happens if I enter
thirdAngle(0,0)?you are right, I just wrote it very fast and I did not think about this case.
TDD will help a lot in these situations.