Ad
  • Custom User Avatar

    Approved

  • Default User Avatar
  • Custom User Avatar

    There are no problems with accessing memory in the code

    Try adding checks with dummy returns before accessing collections similar to this:

    vector<double> vec{...};
    int idx = ...;
    if (idx < 0 || idx >= vec.size()) return 1e308;
    

    to explicitly verify that your indexing is not off anywhere. If you can't find anything, post your solution here and I might look into it later.

  • Custom User Avatar

    I've just run 150k tests and got no errors, it'd be good if you managed to provide an input for which your solution is not working again. In the meantime, try adding logs everywhere to see whether your solution successfully passes all steps, like:

    std::cout << "starting parsing" << std::endl;
    // parse the input string
    std::cout << "parsing complete, starting evaluation" << std::endl;
    // evaluate the expression
    std::cout << "evaluation complete" << std::endl;
    // return the result
    

    I'm not sure whether they will show up correctly due to the tests crashing with an error, but maybe it will provide some insight. Also, try running these cases from different batches of random tests to see if your parser handles them correctly:

    evaluate("-68 * 15 * -17 / -55 / 61 - -8 + 3 / 17")  ==  3.0080652231086176
    evaluate("(85) * (-45 - 88 + (37)) + (68 + ((((-73 / 48)))) - -31)")  ==  -8062.520833333333
    evaluate("-42- 46- -64- -66")  ==  42
    
  • Custom User Avatar

    Evaluating this expression in Python gives 8922.901960784315, and my C++ solution produces the same result. Can you check whether your solution passes this test: Assert::That(calc("(64) * (-97 / 51 * -(55)) - (21 * -((((71 - -33)))) - 44)"), Equals(8922.901960784315))? Maybe the error message shows rounded actual/expected values, and you can't actually see the error.

  • Custom User Avatar

    Have you reset the trainer? If yes, can you provide an input for which your solution fails?

  • Custom User Avatar

    Changed the reference solution to remove double-to-string conversions.

  • Custom User Avatar

    I quote myself from my answer to mr360 from 9 months ago:

    The error message in C++ hides the spaces (I don't know why but it does), you can check it returning return "HEY JUDE "; against the sample test. It'll fail and you won't see why. Just add some * before and after your string to see if there is any.

  • Default User Avatar

    You are welcome! I'm glad you figured it out and especially so that it happened just after awakening for a new day.

  • Default User Avatar

    well, since your code isn't actually failing this test, you need to turn your attention to the next test, which you are failing, and figure out why. print out the inputs. consider edge cases.

  • Default User Avatar

    This test does not return true, it returns false. You are confusing the result with the test that comes after this test. Also: I said you had a mistake in one line your posted code. Have you thought about which line it is?

  • Default User Avatar
    • your code has one logical mistake contained within one line
    • next time please use proper markdown
  • Default User Avatar

    @PUTIS aka Zverb . . . NO . . . kata does NOT say to return true. Look at the post before yours, where @ucczs has had the revelation of paying attention to the logs correctly. This test returns false. If you post your code with proper code markdown, (make sure to click the spoiler tag), I will be happy to dissect your code for errors. : )

  • Default User Avatar

    Oh I see, thanks @rowcased, this issue is indeed not the {2,2,3},{4,9,9} test, but the one which follows. Thanks for the hint :)

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Loading more items...