Ad
  • Default User Avatar

    My issue is resolved.

  • Custom User Avatar

    It was weird as my code with global vars works in VS Code but did not pass tests online.

    it's not weird, it's because on VSC you do only one single test, so you don't actually see there is a state that is shared between different calls.

    Best practice: as B1ts said, don't use global vars (unless you know exactly what you do and how to use them).

  • Custom User Avatar

    How about not using global vars at all? That's the easiest fix. An alternative is to reset all global variables at the start of function.

  • Default User Avatar

    It was weird as my code with global vars works in VS Code but did not pass tests online. Can you recommend a good article to read how to use global vars correctly? Thanks.

  • Custom User Avatar

    Nope. Anyone can use global vars, but only if they know how to use them correctly. Problems with global vars aren't under the "responsability" of the kata/author, but under the reponsibility of the users (who do not know how to code properly with global vars, in that case).

  • Default User Avatar

    I don't see "don't use global variables" in the instructions... May the instructions should be updated?

  • Default User Avatar

    i just tried the second solution, in timed out

  • Default User Avatar

    i literally copied a solution and it didnt work, execution timed out.
    i tried my solutions but i was slow for large number like 9999999999. then i upgraded it but random number were bigger (1003427533368395383) and my solution couldnt kepp up, so frustrated i check the solution (i was on the right path but i was missing some detail) and i tried it, and it failed with a even larger number (4802419968590657004)
    just to know the random test isnt even random, it generate the same big number over and over

  • Default User Avatar

    thanks man, didnt think about that

  • Custom User Avatar

    "don't use global variables" ?

  • Default User Avatar

    its happening something strange, my code seems to work, i pass the test but when i submit it, it fails the same layout as the test. it doesnt make sense tho.
    i logged the input field so i know they are equal

  • Custom User Avatar

    My C++ solution compiles and passes tests, so kata setup seems to be OK. I believe that you either did not stick to the requested method signature, modified it, or left it empty and implemented your solution in some other class/method/function.

    Does your solution implement static std::string SumOfDivided::sumOfDivided(std::vector<int>& lst);?

  • Default User Avatar

    main.cpp:44:22: warning: comparison of integers of different signs: 'int' and 'std::vector::size_type' (aka 'unsigned long') [-Wsign-compare]
    for (auto i= 0; i<prime.size(); i++){
    ~^~~~~~~~~~~~~
    main.cpp:45:26: warning: comparison of integers of different signs: 'int' and 'std::vector::size_type' (aka 'unsigned long') [-Wsign-compare]
    for (auto j= i; j<prime.size(); j++){
    ~^~~~~~~~~~~~~
    main.cpp:53:22: warning: comparison of integers of different signs: 'int' and 'std::vector::size_type' (aka 'unsigned long') [-Wsign-compare]
    for (auto i= 0; i<prime.size(); i++){
    ~^~~~~~~~~~~~~
    main.cpp:54:26: warning: comparison of integers of different signs: 'int' and 'std::vector::size_type' (aka 'unsigned long') [-Wsign-compare]
    for (auto j= i; j<prime.size(); j++){
    ~^~~~~~~~~~~~~
    main.cpp:66:20: warning: unused function 'SumOfDivided' [-Wunused-function]
    static std::string SumOfDivided(std::vector &lst){
    ^
    5 warnings generated.
    /tmp/main-1d7c7a.o: In function sumOfDivided_Tests::Fixed_Tests()': main.cpp:(.text._ZN18sumOfDivided_Tests11Fixed_TestsEv[_ZN18sumOfDivided_Tests11Fixed_TestsEv]+0x5c): undefined reference to SumOfDivided::sumOfDivided[abi:cxx11](std::vector<int, std::allocator >&)'
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    can't understand whats wrong, it worked in my editor. i understand the first 4 warning but not the 5th