I suck at math, like really bad. I am working on a problem in PHP where I have some negative numbers and some positive numbers that will be summed together. I need to cube a negative number (by itself I found out…)
ex:
a = -3^-3 (which is -0)
b = 2^2 (is 4)
so that means: -0+4 = 4
but that’s wrong according to my test case, my test case says that should be 0 and not 4.
(note: all my test cases work except a test case with a negative number)
Hello!
Your calculations are wrong:
For the second array ($b), only the first and the last items will be added to $ret, because of this validation: “$a[$i]%2!=0”.
So:
(-3)^(-3) = -0.03703703703
3^3 = 27
Sum of both = 26.962962962963
so basically this is a fail because i suck at maths. I thought cubing meant to do it by the same number, once i changed pow($a[$i], 3); it worked just fine and satisfied all test cases.
Thanks @CGMS, maybe I need to take a tour through some khan academy courses. My math is seriously fucked, like probably middle school (US). However, I can convert huge equations to code, so go figure lol
(uh and not to mention I ace all logic tests ever created)