Create a simple calculator that given a string of operators (), +, -, *, / and numbers separated by spaces returns the value of that expression
I think de description is quite misleading: in C# at least, there is often no spaces between numbers and operators, as in 1+1 or 1* 1. It would also be nice to mention the unary minus operator, as in 1 - -(-(-(-4))) or 12* 123/-(-5 + 2) (again in this test case operators and numbers are not really separated by spaces).
sorry, but 2 + 3 * 4 / 3 - 6 / 3 * 3 + 8 is +8, not -8:
3 * 4 / 3 is 4
6 / 3 * 3 is 6
2 + 4 - 6 + 8 is +8
probably there is a regex in the tests, probably with /g modificator, was changes the calculation order (it founds 2 + 4 and 6 + 8 first and then calcs 6 - 14, what is wrong!)
When I am testing my program, it is saying "You have passed all of the tests! :)!"..
But when I attempt,I get this error.!!!! (In Java)
./src/test/java/CalculatorTest.java:11: error: reference to assertEquals is ambiguous
assertEquals("simple literal", d, Calculator.evaluate(d.toString()));
^
both method assertEquals(String,double,double) in Assert and method assertEquals(String,Object,Object) in Assert match
./src/test/java/CalculatorTest.java:19: error: reference to assertEquals is ambiguous
assertEquals("addition", new Double(a+b), Calculator.evaluate(a.intValue() + " + " + b.intValue()));
^
both method assertEquals(String,double,double) in Assert and method assertEquals(String,Object,Object) in Assert match
./src/test/java/CalculatorTest.java:20: error: reference to assertEquals is ambiguous
assertEquals("subtraction", new Double(a-b-c), Calculator.evaluate(a.intValue() + " - " + b.intValue() + " - " + c.intValue()));
^
both method assertEquals(String,double,double) in Assert and method assertEquals(String,Object,Object) in Assert match
Note: ./src/test/java/CalculatorTest.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors
When I test it I got all right answers and the solution executes within 0.35 seconds, but when I attempt to submit, it just gives a timeout. Is there any way I could debug this? Really annoyed that I can't see which part of the code is causing trouble. Can I log anything?
I cannot crack this I think. My only idea on how to solve this would be creating an automata that reads the strings, but it seems like such an overkill. Is this the right way to go however?
Does anybody have a vague and non spoiler suggestion for another direction to go for cracking this problem?
Create a simple calculator that given a string of operators (), +, -, *, / and numbers separated by spaces returns the value of that expression
I think , there is no test case for () usage in javascript at least.
I think de description is quite misleading: in C# at least, there is often no spaces between numbers and operators, as in
1+1
or1* 1
. It would also be nice to mention the unary minus operator, as in1 - -(-(-(-4)))
or12* 123/-(-5 + 2)
(again in this test case operators and numbers are not really separated by spaces).sorry, JS
What language?
sorry, but
2 + 3 * 4 / 3 - 6 / 3 * 3 + 8
is+8
, not-8
:3 * 4 / 3
is4
6 / 3 * 3
is6
2 + 4 - 6 + 8
is+8
probably there is a regex in the tests, probably with /g modificator, was changes the calculation order (it founds
2 + 4
and6 + 8
first and then calcs6 - 14
, what is wrong!)When I am testing my program, it is saying "You have passed all of the tests! :)!"..
But when I attempt,I get this error.!!!! (In Java)
./src/test/java/CalculatorTest.java:11: error: reference to assertEquals is ambiguous
assertEquals("simple literal", d, Calculator.evaluate(d.toString()));
^
both method assertEquals(String,double,double) in Assert and method assertEquals(String,Object,Object) in Assert match
./src/test/java/CalculatorTest.java:19: error: reference to assertEquals is ambiguous
assertEquals("addition", new Double(a+b), Calculator.evaluate(a.intValue() + " + " + b.intValue()));
^
both method assertEquals(String,double,double) in Assert and method assertEquals(String,Object,Object) in Assert match
./src/test/java/CalculatorTest.java:20: error: reference to assertEquals is ambiguous
assertEquals("subtraction", new Double(a-b-c), Calculator.evaluate(a.intValue() + " - " + b.intValue() + " - " + c.intValue()));
^
both method assertEquals(String,double,double) in Assert and method assertEquals(String,Object,Object) in Assert match
Note: ./src/test/java/CalculatorTest.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors
What is Happening and what should I do?
Yes.
When I test it I got all right answers and the solution executes within 0.35 seconds, but when I attempt to submit, it just gives a timeout. Is there any way I could debug this? Really annoyed that I can't see which part of the code is causing trouble. Can I log anything?
Log
86 / 63 * 1 * 72
Expected actual value 98 to approximately equal expected value 98.28571428571429 (accepted relative error: 1e-9)
Really? Nearly all the division problems turn out this way in javascript.
It's a 3 kyu, it's intended to be difficult.
The task might be easier than you think, and building a parser for arithmetic expressions is not that difficult. But not trivial either :)
I cannot crack this I think. My only idea on how to solve this would be creating an automata that reads the strings, but it seems like such an overkill. Is this the right way to go however?
Does anybody have a vague and non spoiler suggestion for another direction to go for cracking this problem?
I get this as well.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
In javascript I tried to just do
eval(string)
...of course it couldn't be that easy.Loading more items...