4 kyu

Sum by Factors

2,279 of 20,099g964
Description
Loading description...
Arrays
Algorithms
Mathematics
  • Please sign in or sign up to leave a comment.
  • eble@hs-ulm.de Avatar

    For C++, I keep getting the following error that doesn't say anything at all: Time: 3930ms Exit Code: 1 Test Results: sumOfDivided_Tests Fixed_Tests STDERR UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000425a28 bp 0x000000000056 sp 0x7ffda0e40e70 T1) ==1==The signal is caused by a READ memory access. ==1==Hint: address points to the zero page. ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x425a27 (/workspace/test+0x425a27) #1 0x429df1 (/workspace/test+0x429df1) #2 0x427ffe (/workspace/test+0x427ffe) #3 0x427a2d (/workspace/test+0x427a2d) #4 0x42771b (/workspace/test+0x42771b) #5 0x42c6d5 (/workspace/test+0x42c6d5) #6 0x426c2d (/workspace/test+0x426c2d) #7 0x7f28f3969c86 (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) #8 0x404969 (/workspace/test+0x404969)

    UndefinedBehaviorSanitizer can not provide additional info. ==1==ABORTING

    Since they don't show what test is the cause of the crash, I assume that the runtime is broken. I am building a vector of primes, mybe that is causing a memory issue. It is annoying if they have extreme tests that run into numerical and/or timing issues like a test with INT_MAX.

  • Uoao1808 Avatar

    seems like 6 kyu to me... just use basic knowledges and it is solved

  • GreatGonzales92 Avatar

    The random test always times out unless the answer is incorrect. Tested it by swapping the last character from ")" to "(" and it is consistently only wrong on that character, but times out when fixed.

  • lfsegoro Avatar

    Finally yesss I finished it!!, I am beginner less than a month in C# and about 1 year on-off learn coding. For this kata my way of solution maybe like "reverse engineering" methode. I am not cleaning up messy comment in my solutin for remainder to my self.

  • GanmeCc Avatar

    This comment has been hidden.

  • Grecks Avatar

    It seems this kata actually requires finding those prime factors which is a (very) hard problem in general. I'm not sure whether non-sophisticated approaches will work here (that depends on the size of the input numbers), so I will skip this kata for now.

  • Oubadi Avatar

    This comment has been hidden.

  • DimitraK92 Avatar

    Hello! I need some help here! Should the same numbers be part of the result? I'm getting this failure:

    1. Expected: "...126)(11 110)(17 204)(29 116)(41 123)(59 118)(79 158)(107 107)" But was: "...126)(11 110)(17 204)(29 116)(41 123)(59 118)(79 158)"
  • kirzaka8 Avatar

    yeah i've got no clue how to optimize it. right now it's On^2 and I have actually absolutely 0 idea how to make it faster.

  • Saitek  Avatar

    can someone educate me on why i get a kata right but gets a time out error in higher numbers.used python

  • Hunor1024 Avatar

    This comment has been hidden.

  • longinii Avatar

    its not clear what the input was going to be. made me waste time

  • Mebni Avatar

    In Go one of the basic cases is [114 237 421] and wants to get the answer : (2 114)(3 351)(19 114)(79 237)(421 421) which should be wrong, because 421 shouldn't be in the list!?!

  • LunaTMT Avatar

    If you were confused by the problem statement as I was, hopefully this makes it a little clearer what is being asked of:

    The expression [ [p, sum of all ij of I for which p is a prime factor (p positive) of ij] ...] describes a nested array structure where:

    p represents a prime factor found within the elements of the input array I. The inner array [p, sum of all ij of I for which p is a prime factor (p positive) of ij] consists of two elements:

    The first element is the prime factor p.

    The second element is the sum of all elements in the array I for which p is a prime factor. In essence, for each unique prime factor p found in the elements of array I, the resulting structure contains an inner array with p as the first element and the sum of all elements in I for which p is a prime factor as the second element.

    For example: If I = [12, 15], the resulting structure would be [[2, 12], [3, 27], [5, 15]], where:

    • 2 is a prime factor of 12.
    • 3 is a prime factor of both 12 and 15.
    • 5 is a prime factor of 15.

    Hence, the inner arrays [2, 12], [3, 27], and [5, 15] denote the prime factors found in the elements of I along with the sum of those elements for which each prime factor is applicable.

  • puffCoco Avatar

    Can someone provide more context on the problem description? Im am trying to do this problem in Golang and:

    1. the tests are compared to a string "(2 12)(3 27)(5 15)" when from the description it should be an array of arrays?
    2. I get finding the prime numbers but dont quite understand the sum piece. How did we get (3 27) as part of the result for [12,15] specifically where did this 27 come from?
  • trashy_incel Avatar

    C fork

    • initial code no longer crashes
    • input array is shown upon assertion failure
    • it is explained what to return
    • backwards-compatible
  • saudiGuy Avatar
  • akar-0 Avatar

    VB (at least in basic tests): expected and actual are swapped in output logs

    Time: 2287ms Passed: 0Failed: 1Exit Code: 1
    Test Results:
    SumsTests
    BasicTests
    Test Failed
      Expected string length 19 but was 18. Strings differ at index 13.
      Expected: "(2 12)(3 27)(15 15)"
      But was:  "(2 12)(3 27)(5 15)"
      ------------------------^
    Completed in 85.1130ms
    Completed in 97.2160ms
    
  • apampuch Avatar

    Is there some faster way than using a Sieve of Eratosthenes to find all possible primes up to the largest number and checking against all of those?

  • apampuch Avatar

    You should really explain what an "ij" is.

  • ejini战神 Avatar

    Python: sample tests are not using the test framework

  • ejini战神 Avatar

    C#: method name should be PascalCase (Please refer to implementation of backward compatibility here )

  • qlilP Avatar

    help! how can i find the limit of the prime factor, i choose largest number in array and loop through it, but it overflow the limit of the prime factor in the result.

  • M1Miketro Avatar

    Are there input restrictions?

  • tStevens Avatar

    How many test are there? Before I get an Execution Time Out my code goes properly through something about 67 tests. I just wonder how far I am from solution. (I use python)

  • Zak98 Avatar

    This comment has been hidden.

  • MasterYiTheSamurai Avatar

    C# tests are not passing. Could you please look if the random test cases are correct?

  • DeNöff Avatar

    I dont see the point of this kata, because every solution needs to have mathmatical limits. So if the input values are big enough there is no algorithm that works since there is no algorithm that can calculate all the prime numbers.

  • bksdavd Avatar

    Does anybody else has problems with javascript tests?

  • Otrex Avatar

    For me, the problem description is not clear

  • David10092 Avatar

    For me the problem description is not clear enough. In the example [15, 30, -45] all 3 numbers can be divided by 3, but only 5 is shown in the results. At least I cannot find anywhere the requirement that I should output the prime number that divides the most of the array elements. Or am I missing anything there?

  • Cillo-x Avatar

    Error. Expected (2 -61548)(3 -4209)(5 -28265)(23 -4209)(31 -31744)(53 -72769)(61 -4209)(1373 -72769)(5653 -28265)(7451 -29804) but got (2 -61548)

    Could someone tell me something about this test-set? I had tested my code under many situation (all-non-negative, all-negative and both have) and it works well.

    well, i finally found this problem is due to windows. in short, making the space as big as possible, will kept you away from many shitting troubles.

  • PsyTheGuy Avatar

    Awful task description...

  • joexner Avatar

    This comment has been hidden.

  • Def91 Avatar

    This comment has been hidden.

  • jsauceda Avatar

    In R, only a few libraries can be loaded in the soluntions, and non of them contains a function to test prime numbers or factorize numbers. So, I wrote my own code. It works but it runs out of time.

    Any suggestions or tips to beat the clock?

  • Madjosz Avatar

    C++ could need some more edge cases in fixed tests. Currently there is no case which has a 0 in the output and also there could be a case with duplicates in the input.

  • Madjosz Avatar

    JavaScript: By very very very small chance (~1.57e-31) random tests can produce an empty array, also because index is incremented when no value is pushed to array. In contrast to Java no leading zeros occur though, thus this case is not even close to be an actual problem.

  • Madjosz Avatar

    Java: Random tests can produce 0 in the input array. This will put the reference solution into an infinite loop leading to timeout. There is a bug in input creation doEx():

    while (i < k) {
        int rn = randInt(-100, 500);
        if (rn != 0) {res[i] = rn;} // zero is skipped
        i++; // index is increased nevertheless, leading to trailing zeros by chance
    }
    

    Fix is easy, just put the postfix increment into the array assignment.

  • ejini战神 Avatar

    Python new test framework should be used with unnecessary logs removed

  • ejini战神 Avatar
    • Ruby 3.0 should be enabled

    • Function name should use snake_case

  • Hinary Avatar

    Can someone tell me why it sould be ..., [ 11, 187 ], [ 13, 0 ], [ 29, -29 ], but shouldn't be ..., [ 11, 187 ], [ 13, 0 ], [ 23, 0 ], ..., [ 29, -29 ] or ..., [ 11, 187 ], [ 23, 0 ], [ 29, -29 ]?

  • Jessewh Avatar

    This comment has been hidden.

  • wqeewqwqe Avatar

    Test Results: Log [[2, 12], [3, 27], [5, 15]] None should equal [[2, 12], [3, 27], [5, 15]] Log [[2, 54], [3, 135], [5, 90], [7, 21]] None should equal [[2, 54], [3, 135], [5, 90], [7, 21]]

    Why?...........

  • RadiantAscent Avatar

    Test passes, but when I click Attempt it seems to get stuck at sending request. Have tried refreshing browser etc. Am able to submit other problems.

    Could this be an issue with my code (it's not returning timeout or errors), or somehow a server response bug in the problem or similar? I've tested code on 'large' lists of 'large' numbers: seems fine tbh.

    Ta

  • iNeutronn Avatar

    In my C# code, I can pass "Test1", when I click "Test", but when I click ATTEMPT I can not pass test1 whith the same input. So what is wrong?

  • mostaquebillah Avatar

    I need help from someone who already has finished the kata. with python, I have used Sieve method of determining prime numbers. my solution is logically correct but it keeps getting Execution Timed Out. I need better algo but I need help. thanks in advance.

  • Perseus124 Avatar

    Hello. I use C#. As a result of the code, at least a small error, the code compiles very quickly, but with the correct values it always writes that "Execution Timed Out". I optimized the code as best I could, but nothing helped. By the way, I compile no more than 2000 ms. Is this an issue of Kata of it's my mistake?

  • radeenXnoob Avatar

    Great kata. Corner cases add nice touch on this!

  • Anhimov Avatar

    This comment has been hidden.

  • aaronkl Avatar

    This comment has been hidden.

  • profarvin Avatar

    This comment has been hidden.

  • skirhir Avatar

    There is a python Basic Test that has a bug:

    test input [15, 21, 24, 30, -45]
    expected output: [[2, 54], [3, 45], [5, 0], [7, 21]]
    

    [5,0] isn't consitent with other tests outputs.

    Had to handle it as an special case.

  • JakeMiddleton4 Avatar

    This comment has been hidden.

  • shengxia622 Avatar

    Will test add cases like [15, 30, -45], which the min number is the factor of all other numbers. Without prime-checking, some non-rigorous solutions pass this kata by chance

  • GabeOwner Avatar

    The only thing I really don't like about this challenge is the necessity of some boilerplate to obtain a list of prime numbers. I know prime numbers don't pop out of thin air in the real world, but I get a little annoyed every time I have to copy one of these things in. Altogether it seems like a pretty good problem, though.

  • Necytij Avatar

    need a static test with exponent of 2 or other number - to check if in cause of multiple factors program multiple times includes Ij. Also nice example is using in the same test 899 = 29 * 31 - so while simple searching factors in range(2, int(n0.5)) will loose 31, because it is less than n0.5

  • akar-0 Avatar

    This comment has been hidden.

  • SinisterCutlass Avatar

    This comment has been hidden.

  • 1Stas Avatar

    Is this some kind of joke. A lot of time on an empty array. (It's a pity there isn't a smiley face that bangs its head against the wall)

  • geonyoro Avatar

    Something to note.

    As you generate sum_for_list, in python or whatever, take note that the list may have some numbers repeated. ie.

    ssum_for_list([12, 15]) should not be the same output as sum_for_list([12, 15, -15]) and not the same as sum_for_list([12, 15, 15]).

    This mistake was costing me attempt 4 of basic tests.

  • daisy111 Avatar

    This comment has been hidden.

  • jnr07 Avatar

    Is there a way to see the expected results? I'm using PHP and the expected results only show "array(...)" which makes diagnosing the problem with my code difficult. Any tips are appreciated. Thanks!

  • Mezzerine Avatar

    I do this kata in C. I've got a correct solution for as far as I can check, but I get sometimes an invalid memory access violation error (I free all memory that I use, save for bugs). I can pass all the example tests separately, or maybe two at once, but not all three, als sometimes a specific set of two also gives me the error, but not always the same two... I have no idea how to check what is going wrong since if a memory access violation error occurs, there is no output at all. It seems that if it crashes, it is always the second test.

    [edit] I've found the bug via an external debugger. So you get kinda lost when not initializing pointers... [/edit]

  • tatarintsevsv Avatar

    This comment has been hidden.

  • user1430804 Avatar

    This comment has been hidden.

  • tweller Avatar

    I had an interesting issue and would like to know more details.

    All tests passed in my Visual Studio environment, but I didn't pass the acceptance test on CodeWars. I pulled the test data out of the acceptance test - but they passed in Visual Studio as well. I then tried to reproduce the issue in an online IDE and the online IDE complained that I did not #include for std::unique(). I #included in Visual Studio and suddenly the tests in Visual Studio had the same results as on CodeWars.

    Now I am wondering: Where did std::unique() in Visual Studio come from when I did not #include ? What did that version of std::unique() do? Obviously something different. Where did std::unique in CodeWars come from when I didn't #include ? Can we change that so we get a compiler error?

  • steffenkame Avatar

    This comment has been hidden.

  • steffenkame Avatar

    @g964 Hi, could you please have look at the question two days ago. It is not resolved. :(

  • steffenkame Avatar

    Hi, I am using C#. For number 21 the prime number 7 is not listed in the results here. Did I do something wrong? The input numbers are following.

    12, 15, 15, 21, 24, 30, 45, 107, 158, 204, 100, 118, 123, 126, 110, 116, 100, -29804, -4209, -28265, -72769, -31744

    Desired output is: //"(2 -61548)(3 -4209)(5 -28265)(23 -4209)(31 -31744)(53 -72769)..." ---> no (7 ...) occurs!

  • sanaruca Avatar

    I don't understand this kata

  • Yosoku Avatar

    Are duplicate values in array I allowed? Im failing this test even though im sure my code is correct. Expected: equal to "(2 1032)(3 453)(5 310)(7 126)(11 110)(17 204)(29 116)(41 123)(59 118)(79 158)(107 107)" Actual: "(2 932)(3 453)(5 210)(7 126)(11 110)(17 204)(29 116)(41 123)(59 118)(79 158)(107 107)"

    If duplicate values are allowed this would probably make sense tho.So can anyone verify?

  • Ung Sereysopea Avatar

    This comment has been hidden.

  • Ung Sereysopea Avatar

    This comment has been hidden.

  • mirkeau Avatar

    That's just crazy. My Perl solution with an ad-hoc implementation of a prime sieve with Perl's hash type passed the tests without problems. In Haskell the only way - at least for me - seems to be using an optimized prime sieve from the Haskell website, but that's against the rules, right?

  • zLuki Avatar

    Test shouldn't log to console (at least in JS)

  • Davidus_Corvus Avatar

    This comment has been hidden.

  • jeremylloyd Avatar

    This comment has been hidden.

  • SeanAubrey Avatar

    Why do test numbers in Python go up to ~1,000,000 while JS test numbers go up to ~200? This makes the Python solution exceedingly more difficult - I timeout with or without using a global Eratosthenes prime list and applying a number of optimizations that reduce the iterations per lst number. (I also converted the top JS solution to Python and it also times out.)

  • BennyZ3 Avatar

    Is there a way to get past timeouts using js? Already applied a few optimizations for prime checks, but still getting timeouts

  • archmonduu Avatar

    This comment has been hidden.

  • mark_sathoshi Avatar

    This comment has been hidden.

  • PratikshaT Avatar

    This comment has been hidden.

  • ansis m Avatar

    I calculated and stored primes up to 200,000 in a static array. I used sieve of Eratosthenes to do this.

    I passed the kata however, I was quite surprised when I realized that my solution is slower than most other solutions in C that check for primes in each function call. My effort of making static array of primes was acctually detrimental :(

    Perhaps my approach would fare better if there were more test cases with large numbers.

  • hbgardner Avatar

    This comment has been hidden.

  • brdknn Avatar

    This comment has been hidden.

  • Philippians413 Avatar

    This comment has been hidden.

  • Mir Abir Hossain Avatar

    Can somebody give me a hint for a python solution? I have optimized the prime number searching function using sieve of Eratosthenes algorithm but the main function is taking very long time.

  • knighht Avatar

    This comment has been hidden.

  • dawnli Avatar

    OK, I need more carefully.

  • dawnli Avatar

    UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000426c6d bp 0x000000000000 sp 0x7ffc59ac8aa0 T1) ==1==The signal is caused by a READ memory access. ==1==Hint: address points to the zero page. ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x426c6c (/workspace/test+0x426c6c) #1 0x42a848 (/workspace/test+0x42a848) #2 0x428a6e (/workspace/test+0x428a6e) #3 0x42849d (/workspace/test+0x42849d) #4 0x42818b (/workspace/test+0x42818b) #5 0x42d165 (/workspace/test+0x42d165) #6 0x4268cd (/workspace/test+0x4268cd) #7 0x7f5849ea1bf6 (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6) #8 0x404af9 (/workspace/test+0x404af9)

    UndefinedBehaviorSanitizer can not provide additional info. ==1==ABORTING

    I had check my ansers, and I don't know what wrong about my code.

  • dfhwze Avatar

    C: I get the following error ..

    free(): invalid size
    

    .. eventhough the verification process does not free the empty edge case:

    // from verification code ..
    if (l != 0) {
        free(slst); slst = NULL;
    }
    

    If I comment out the "free" part, it works.

    I added the following test case to verify:

    {
        int d1[2] = {12, 15};
        char* sol1 = "";
        dotest(d1, 0, sol1);
    }
    

    Is this a kata issue?

  • Snabbaspirit Avatar

    I = [12, 15]; //result = [[2, 12], [3, 27], [5, 15]] Why result doesn't include [6, 12] ?? Thats also a valid value

  • nicholasbulka Avatar

    Any advice for getting past System Timeouts with the naive prime checking solution? I've invested a lot of time into a correct, slow solution in Haskell but I can't get past the timeouts. A hint would be most appreciated.

  • manu0192 Avatar

    This comment has been hidden.

  • msr94 Avatar

    This comment has been hidden.

  • RenuzitV Avatar

    in C++, the final pre-random answer is crashing the checker. I've tried returning the whole string answer and it crashes everytime. removed 1 character (last bracket) and it runs fine again saying wrong answer. other big random tests works fine on my solution.

    the test {100,100,107,110,116,118,123,126,158,204} gives "(2 1032)(3 453)(5 310)(7 126)(11 110)(17 204)(29 116)(41 123)(59 118)(79 158)(107 107)" as the correct answer (this is from the checker), and anytime i try to return this string the checker crashes.

    this question is asked in all disscussions and haven't been resolved for 3 days. Please fix.

  • jagil Avatar

    This kata with python, doesn't matter what kind of solution you use, all of them gives a timeout error

  • RenuzitV Avatar

    final pre-random answer is crashing the checker. I've tried returning the whole string answer and it crashes everytime. removed 1 character (last bracket) and it runs fine again saying wrong answer. other big random tests work fine on my solution

  • Sethys Avatar

    [ [p, sum of all i_j of I for which p is a prime factor (p positive) of i_j] ...]

    [[p, sum of all numbers from the list that are divisible with p]]

    p = prime number

  • osamakawish Avatar

    It says:

    [ [p, sum of all i_j of I for which p is a prime factor (p positive) of i_j] ...]

    However, should it not be:

    [ [p, sum of all i_j of I for which p is a prime factor (p positive) of the sum] ...]

  • Sycrys Avatar

    This comment has been hidden.

  • Mohrezakhorasany Avatar

    Thanks, it was fun kata :)

  • zshyman Avatar

    I keep timing out on the 7th test. Is there a trick to finding all the primes? Right now finding them takes O(n^2) where n is the highest number that we were given in the array.

  • Yuunooooooo Avatar

    Get TimeOut everytime, very frustrated:(

  • deivleon 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

  • pa-m Avatar

    Expected (2 12)(3 27)(5 15) got (2 12)(3 27)(5 15)

    same test pass in "sample tests" but fails in "attempt".

  • clinzy25 Avatar

    Has anyone run into an issue where the first test always works but every test after returns "NaN"? Its like its storing a value from the previous test run somewhere in my function.

  • clair Avatar

    This comment has been hidden.

  • olgucan Avatar

    nice kata

  • rohitaroramsa Avatar

    This comment has been hidden.

  • vhsconnect Avatar

    This comment has been hidden.

  • cybersinger Avatar

    This comment has been hidden.

  • cybersinger Avatar

    This comment has been hidden.

  • bennyBoy_ Avatar

    Dear Creator, I enjoy working with prime numbers and I found this Kata fascinating. Thank you!

  • MarkMozh Avatar

    When I attempt I run into a problem:

    Expected: equal to (2 1032)(3 453)(5 310)(7 126)(11 110)(17 204)(29 116)(41 123)(59 118)(79 158)(107 107)

    Actual: (2 1032)(3 453)(5 310)(7 126)(11 110)(17 204)(29 116)(41 123)(59 118)(79 158)

    where only the last result isn't shown and I don't understand why.

    The Random test has the same issue:

    Expected: equal to (2 108402)(3 108633)(5 36245)(7 67291)(11 69377)(13 60476)(17 29393)(19 51509)(31 36983)(59 22302)(97 22116)(251 33132)(557 15596)(659 36245)(797 31083)(1193 36983)(1907 15256)(25931 25931)

    Actual: (2 108402)(3 108633)(5 36245)(7 67291)(11 69377)(13 60476)(17 29393)(19 51509)(31 36983)(59 22302)(97 22116)(251 33132)(557 15596)(659 36245)(797 31083)(1193 36983)(1907 15256)

  • codeMogambo Avatar

    have question on this Testing [107, 158, 204, 100, 118, 123, 126, 110, 116, 100] There should be only one unique prime factor for 1262 found [] Actual (2 932)(3 453)(5 210)(7 126)(11 110)(17 204)(29 116)(41 123)(59 118)(79 158)(107 107) Expect (2 1032)(3 453)(5 310)(7 126)(11 110)(17 204)(29 116)(41 123)(59 118)(79 158)(107 107)

    I am not understanding the above of how (2 932) is not correct.

    2 is a factor of 100, 116, 118, 204, 158, 126, 110 that should make it (2 932) how is it (2 1032) what am i missing here ?

  • codeMogambo Avatar

    This kata is not explained well, I have two queries if some one can help

    It can happen that a sum is 0 if some numbers are negative! Example: I = [15, 30, -45] 5 divides 15, 30 and (-45) so 5 appears in the result, the sum of the numbers for which 5 is a factor is 0 so we have [5, 0] in the result amongst others. I dont get how the kata get 5,0 even 3 divides 15, 30 and 45

  • Sygone Avatar

    How is the first example [ [2, 12], [3, 27], [5, 15] ] ?

    For input [12, 15, 18] shouldn't it be [ [2, 30], [3, 45], [5, 15] ]? Since 2 is prime and a factor of both 12 and 18 etc?

  • Davisino Avatar

    This comment has been hidden.

  • user1430804 Avatar

    Somebody help me please..

    UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x0000004266d7 bp 0x7ffd28fe90b0 sp 0x7ffd28fe8d40 T1) ==1==The signal is caused by a READ memory access. ==1==Hint: address points to the zero page. ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x4266d6 (/workspace/test+0x4266d6) #1 0x429e38 (/workspace/test+0x429e38) #2 0x42805e (/workspace/test+0x42805e) #3 0x427ac7 (/workspace/test+0x427ac7) #4 0x42778b (/workspace/test+0x42778b) #5 0x42c7a5 (/workspace/test+0x42c7a5) #6 0x42650d (/workspace/test+0x42650d) #7 0x7f9d3c34db96 (/lib/x86_64-linux-gnu/libc.so.6+0x21b96) #8 0x4046d9 (/workspace/test+0x4046d9)

    UndefinedBehaviorSanitizer can not provide additional info.

  • jamesnottidge Avatar

    My code works to an extent, but it tends to not give any output for large negative numbers. It wouldn't output the factor, and it also woouldn't output the sum. It just skips it entirely and moves on to the next. Please what could be the issue? Javascript by the way.

  • calvos6165 Avatar

    I've been trying for an hour now and I can't manage to pass this Kata although I have all the results OK but the corrector says that are wrong.

    ex: expected-> [[2, 6], [3, 3]] got-> [[2, 6], [3, 3]]

    and continues saying it's wrong.

    Can someone help?

    Thank you.

  • mwk48 Avatar

    This comment has been hidden.

  • user6720290 Avatar

    I have read this multiple times and I still don't get it. Can someone please explain what we're supposed to do?

  • uykusuZzZz Avatar

    in R randomised tests I am getting a mean delta of less than 1 which is throwing off as an error. I printed the res and the lst and manually checked, it seems fine to me, looks like a rounding problem on testing side. Would you mind having a look? Cheers

  • dmrrhalil@gmail.com Avatar

    I couldn't understand the question. Can someone explain and give me another sample test case pls? what exactly should method do?

  • Rigel_Fomalhaut Avatar

    My code uses sympy which doesn't seem to be recognised? Is there a glitch or does the python package not include sympy anymore?

  • JeremiasHeel Avatar

    This comment has been hidden.

  • vaibhav0211 Avatar

    My code is passing all the test cases but when i try attempt, it shows error.

    STDERR

    UndefinedBehaviorSanitizer:DEADLYSIGNAL

    ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x00000042698b bp 0x000000000000 sp 0x7ffcb05a9c30 T1)

    ==1==The signal is caused by a READ memory access.

    ==1==Hint: address points to the zero page.

    ==1==WARNING: invalid path to external symbolizer!

    ==1==WARNING: Failed to use and restart external symbolizer!

    #0 0x42698a  (/workspace/test+0x42698a)
    #1 0x42a3f8  (/workspace/test+0x42a3f8)
    #2 0x42861e  (/workspace/test+0x42861e)
    #3 0x428087  (/workspace/test+0x428087)
    #4 0x427d4b  (/workspace/test+0x427d4b)
    #5 0x42cd65  (/workspace/test+0x42cd65)
    #6 0x42667d  (/workspace/test+0x42667d)
    #7 0x7fd8f02e8b96  (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #8 0x404879  (/workspace/test+0x404879)
    

    UndefinedBehaviorSanitizer can not provide additional info. ==1==ABORTING

    Please help me.

  • sIldefonso Avatar

    I guess the explanation is a little tricky. I guess the challenge here is on the code and the algorythm and not on the English.

    My idea is:

    • For a set of (positive or negative) given numbers, for each prime number in the universe, to show each prime number and the sum of all of the given numbers that can be divided by the prime number.

    I am sorry if I am spoiling anyone. I try not to.

  • scolespa Avatar

    typescript version - my solution passes all the tests locally, but when I submit the solution, all tests fail, including the basic ones that passed locally. The output of the remote tests isn't helpful in figuring out what the issue is, I get output like: expected [ Array(10) ] to deeply equal [ Array(11) ]

    any suggestion?

  • FlorinM Avatar

    I think it is a problem with managing test cases. For the same input on my machine outputs the correct answer but on this site don't. Look three of them. Usually passes more than 100 tests but one or two. Again, on my machine the output is the same as "Expected" on your site. [ -29804, -4209, -28265, -72769, -31744 ]; [ 107, 158, 204, 100, 118, 123, 126, 110, 116, 100 ]; [ 151, 182, 124, 49, 4, 90, 74, -64, 191, 158, 144, 104, -35, -93 ];

  • FlorinM Avatar

    There is a problem with this kata beyond me. For the same input, on my machine passes the test. Exactly same code. On your machine the output array lacks one element. Please repair this kata! I worked hard for it, I want to pass it.

  • MalcolmAG Avatar

    I have a question, should we be trying to create our own "find_primes_up_to_n" function?

  • perottilds Avatar

    Typescript attempt-base-test-case is incorrect whilst every other case passes. Verified out manually and my output is correct.

  • paul2 Avatar

    Broke my mind before understand what do you want, but it's not the problem of this Kata. Much more likely it's my English🤗 Thanks for this Kata😉

  • EricPicot Avatar

    testing [15, 21, 24, 30, -45] Actual [[2, 54], [3, 45], [7, 21]] Expect [[2, 54], [3, 45], [5, 0], [7, 21]] [[2, 54], [3, 45], [7, 21]] should equal [[2, 54], [3, 45], [5, 0], [7, 21]]

    I believe there is an issue. In the expected output, we can find sublist [5, 0], while it should be removed. Isn't it ?

  • Quico666 Avatar

    This comment has been hidden.

  • afdoner Avatar

    The description was hard to follow until it clicked. Great exercise

  • RobertsMaxwell Avatar

    In C# my code manages to get the correct answer within three seconds, I know this because instead of returning the string I print it and return a random string. For some reason when I return the string with the correct answer the compiler times out, I have no idea why this is but I know for certain that it isnt my code. Does anyone know why this is?

  • coding_pad Avatar

    This comment has been hidden.

  • tommyhermansson Avatar

    I only pass the first test case and then my output increases for each test, by almost doubling my output. See the firs two tests below. Then it gets even worse after that.

    This issue does not arise when I run the code on my own computer. Is there something wrong with the testing?

    Basic tests Log testing [12, 15] Actual [[2, 12], [3, 27], [5, 15]] Expect [[2, 12], [3, 27], [5, 15]] Test Passed Log # testing [15, 21, 24, 30, 45] Actual [[2, 54], [3, 135], [5, 90], [7, 21], [3, 135], [5, 90], [7, 21]] Expect [[2, 54], [3, 135], [5, 90], [7, 21]] [[2, 54], [3, 135], [5, 90], [7, 21], [3, 135], [5, 90], [7, 21]] should equal [[2, 54], [3, 135], [5, 90], [7, 21]]

  • pyatsysh Avatar

    Very artificial exercise. Completely useless test cases. Waste of time

  • fibonaccios Avatar

    Awesome kata! I have learned so much through your prime katas...

  • panurag904 Avatar

    This comment has been hidden.

  • yellowBirdy Avatar

    JS Random tests throw an error. It happens before first line of sultions gets executed (it is console.log(lst)) All other tests pass.

    The error is as follows:

    Random tests**** TypeError: Assignment to constant variable. at divs.sort.filter.filter.map.x at Array.map at sumOfDividedPLO at tests_code at /home/codewarrior/index.js:125:5 at /runner/frameworks/javascript/cw-2.js:152:11 at Promise._execute at Promise._resolveFromExecutor at new Promise at Object.describe at /home/codewarrior/index.js:83:6 at /home/codewarrior/index.js:127:5 at Object.handleError

  • counter2015 Avatar

    In the kata instructions, it says

    [ [p, sum of all ij of I for which p is a prime factor (p positive) of ij] ...]

    But it generate random test contains 1 as prime factor(Small probability)

    Testing: 161 116 289 1 343 99 185 397 431
    Actual: (1 2022)(2 116)(3 99)(5 185)(7 504)(11 99)(17 289)(23 161)(29 116)(37 185)(397 397)(431 431)
    Expect: (2 116)(3 99)(5 185)(7 504)(11 99)(17 289)(23 161)(29 116)(37 185)(397 397)(431 431)
    

    I would recommend modifying the test data generator.

  • liushuailong Avatar

    This comment has been hidden.

  • Zheoni Avatar

    I can't access the c++ input vector, I get exit code 139 even when I only print the values of the vector. This happens in c++ int the 4th test of the attempt.

  • kp3393 Avatar

    This comment has been hidden.

  • G_kuldeep Avatar

    This comment has been hidden.

  • no4kar Avatar

    Hi "Exit code : 139", what does it mean???

  • m4ch4do Avatar

    These two clarifications were helpful for me:

    1. For negative numbers you should find positive divisors.
    2. Kata considers every number is its own divisor (ie. 107 is a divisor of 107)

    It will be nice if those two notes could be added to description.

    Happy Coding!!!

  • tanertopac Avatar

    I have an issue for javascript where an empty array is sent as input. Instructions do not specify what the result should be in this case and I get an error for whatever I try to handle this issue. Error says invalid length for array even though I return with [], [[]],[[null,null]], [[null,0]] e.g. no matter whatever I try, right after entering the function.

  • Tinwe Avatar

    For PHP

    [3, 45] should be [3,0] beacuse prime factor for 45 is 3 and 5. $this->revTest(sumOfDivided([15,21,24,30,-45]), [ [2, 54], [3, 45], [5, 0], [7, 21] ]);

  • Deanna1 Avatar

    For C# (and possibly the tests for other languages), your code needs to be able to handle prime numbers up to 1 million. I think it would have been helpful to have this information included in the question, as I kept timing out and without seeing the test input I couldn't work out why.

  • nickchandler Avatar

    For JavaScript:

    Hi there. Running into an issue where I pass all of the prescribed tests, and then fail the random test due to an error being thrown. The error reads "TypeError: 181 is not a function", where 181 can be one of any of the elements passed in the input array.

    My code runs fine in VSCode, even for the input arrays generated by the random test. Anybody having similar issues?

  • fablakeson Avatar

    Nice Kata! But it would be even better if the instructions were showing the limits of the integer values. It is a bit annoying to have submissions failing because of not knowing the maximum value.

  • latiif Avatar

    Trying to solve the problem with Haskell. What are the constraints on the input numbers? Biggest/smallest number possible AND how many numbers should we deal with as input?

  • Katerls3 Avatar

    I'm solving this kata in C. What's the largest prime the solution has to support?

  • AndreyTiko Avatar

    How to return the buttons for testing?

  • AndreyTiko Avatar

    I try to test, but I do not see the button

  • hksong Avatar

    For JavaScript

    #
    [ 107, 158, 204, 100, 118, 123, 126, 110, 116, 100 ]
    Actual:  [ [ 2, 1032 ],
      [ 3, 453 ],
      [ 5, 310 ],
      [ 7, 126 ],
      [ 11, 110 ],
      [ 17, 204 ],
      [ 29, 116 ],
      [ 41, 123 ],
      [ 59, 118 ],
      [ 79, 158 ] ]
    Expect:  [ [ 2, 1032 ],
      [ 3, 453 ],
      [ 5, 310 ],
      [ 7, 126 ],
      [ 11, 110 ],
      [ 17, 204 ],
      [ 29, 116 ],
      [ 41, 123 ],
      [ 59, 118 ],
      [ 79, 158 ],
      [ 107, 107 ] ]
    

    What numbers have 107 as a factor? It feels like the test case might be suggesting 107 is its own factor since the sum is exactly 107?

    I might have just misunderstood the description?

  • VictorCervantes Avatar

    Add the following test, to verify if it works with bigger numbers:

    a = [1200000000, 150000000000,313456445] b = [[2, 151200000000], [3, 151200000000], [5, 151513456445], [62691289, 313456445]] test.assert_equals(sum_for_list(a),b)

  • lynxlynxlynx Avatar

    Shell has no sample tests, so one has to submit to see the input and expected format (likely both string, one can't pass arrays around).

  • Simon Cheung Avatar

    What does it mean by "Can not find symbol"? I have my solution tested in my own code editor and it worked soundly and smoothly.But it repeatly showed me "can not find symbol" when it comes to submitting my solution.Help

  • THayden Avatar

    I seem to be getting the same errors as @wwlwwl and @Immaterial using c++. I can pass the sample tests fine but on "Attempt", I fail with :

    Time: 1936ms
    Test Results:
     sumOfDivided_Tests
     
    

    with a red border and a green arrow next to "SumOfDivided_Tests." If I change my code to return output + "Thing"; Then the output on "Attempt" becomes:

    Time: 1743ms Passed: 0 Failed: 2
    Test Results:
     sumOfDivided_Tests
     Fixed_Tests
    Expected: equal to (2 12)(3 27)(5 15)
    Actual: (2 12)(3 27)(5 15)Thing
     Random_Tests
     Log
     ****************** 
    Expected: equal to (2 166606)(3 131373)(5 62940)(7 88627)(11 37455)(13 55523)(17 19669)(19 34181)(41 34973)(43 215)(61 31903)(83 18592)(89 19669)(103 20600)(107 11663)(109 11663)(151 12231)(197 35854)(227 37455)(257 48059)(383 10341)(467 4670)(523 31903)(853 34973)(4337 13011)(4373 8746)(4507 9014)(4561 9122)(4691 28146)(4733 18932)(4967 -39736)(5437 16311)(9697 38788)(37547 37547)
    Actual: (2 166606)(3 131373)(5 62940)(7 88627)(11 37455)(13 55523)(17 19669)(19 34181)(41 34973)(43 215)(61 31903)(83 18592)(89 19669)(103 20600)(107 11663)(109 11663)(151 12231)(197 35854)(227 37455)(257 48059)(383 10341)(467 4670)(523 31903)(853 34973)(4337 13011)(4373 8746)(4507 9014)(4561 9122)(4691 28146)(4733 18932)(4967 -39736)(5437 16311)(9697 38788)(37547 37547)Thing
    

    Which is apparently the correct output with "Thing" appended. Others have suggested that these issues are usually caused by segfaults but I am not sure that that is the case here. Clearly it is possible to pass this kata in c++ but I am not sure why I am failing.

  • navigator Avatar

    testBasics passed on RUN SAMPLE TEST

    testBasics fail on Attempt in PHP

    Is it me or code?, please take a look!! How can I dump out expected result to hand check?

  • Voile Avatar

    There are no random tests, at least in Haskell. (I haven't checked the other languages yet.)

  • Firefly2002 Avatar

    Crystal has no sample tests

  • Michael Hamhoev Avatar

    System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. Parameter name: count

    What is it??

    C#

  • stealth10k Avatar

    The bash shell version needs more time to calculate. The algorithm i am using passed when written in other languages but in the bash tests it seems like the numbers in the test are too big or something. The code is very short. The first 8 basic tests pass then it times out.

  • timbirms Avatar

    This comment has been hidden.

  • Jomopipi Avatar

    love it thanks

  • pierovera Avatar

    Reopening a previous issue, with some clarification.

    The kata's description is imcorrectly worded for C. It implies you need to return an array of arrays, however it asks for a string in the test cases.

    The function returns a string, and the tests expect a string. There is no conversion whatsoever in the tests. There is also no such thing as a Data * type in the C version of the kata. The test can be passed in C, however the description is incorrect and it could mislead users into returning the wrong thing.

    Either the description should be corrected, or the test cases should be changed. The former makes more sense, in my opinion.

  • pierovera Avatar

    The kata's description is imcorrectly worded for C. It implies you need to return an array of arrays, however it asks for a string in the test cases.

  • anter69 Avatar

    No random tests in python -- however, as it was completed more than 500 times, it cannot be updated anymore...

  • ice1000 Avatar

    Kotlin translation, waiting for moderator to approve.

    Random tests are included

  • ice1000 Avatar

    The Java test case is broken (4th and 5th test didn't run (no @Test annotation) and 5th test is broken).

    Created a fork that removed the broken test and make the 4th test run.

  • CubEd Avatar

    Who can explain me what this means, when i run my code on Visual Studio all works fine, but when i run here i receive that "Process exited prematurely with a SIGSEGV signal." ?

  • laqiguy Avatar

    Test is crushing on Swift. And it's not the only kata, that i couldn't finish cause of bugs in tests

  • itchy_eagler>< Avatar

    iam able to pass test cases but while attempting its showing Process exited prematurely with a SIGSEGV signal. "is there any memory limit" and my code is not trying to accesss any invalid memory!!! because i have tested my code in my IDE by those cases were in final test cases i got final test case by removing all of my code and just printing vector passed and by seeing expected result

  • balaji.ambresh Avatar

    This comment has been hidden.

  • xavierdurawa Avatar

    While working on this kata, I kept running into issues because my code would take too long to run on the server (i.e. >12000 ms). I ended up find a inadvisable way around it but I'm still rather confused. Unless I'm missing something, some of the other solutions posted here are significantly less efficient than my original solution (the pre-jerry-rigged version). How can that be?

  • armstrong Avatar

    This comment has been hidden.

  • kaa-the-snake Avatar

    Way too easy for 4 kyu, IMHO.

  • FaaaX Avatar

    This comment has been hidden.

  • jtmunoz Avatar

    That took some time, and it was well worth it.

  • wwlwwl Avatar

    Time: 14ms Passed: 0 Failed: 0 Test Results: sumOfDivided_Tests Fixed_Tests

    What does this mean????

  • user3012216 Avatar

    Suppose p is a prime such that p <= max(I), but p is not a factor of any element i in I. The instructions do not explicitly state that the function should output the tuple (p, v) if and only if p is a factor of at least one i in I (rather, they state to output p and the sum of the elements of a potentially empty set). Consequently, I think this scenario is ambiguous, since the sum of the elements of an empty set is otherwise undefined. Should the output in this case be (p 0) or an empty string?

  • theZaki Avatar

    When running the example I got a reference error, the same error is fired when running the test suit, the log generated is below:

    ../home/codewarrior/spec.ts(1,1): error TS1084: Invalid 'reference' directive syntax.
    ../home/codewarrior/spec.ts(2,1): error TS1084: Invalid 'reference' directive syntax.
    

    I fixed the example by adding those lines to the top

    /// <reference path="/runner/typings/main/ambient/mocha/index.d.ts" />
    /// <reference path="/runner/typings/main/ambient/chai/index.d.ts" />
    

    instead of

    /// <reference path="/runner/typings/main/ambient/mocha/index.d.ts" ></reference>
    /// <reference path="/runner/typings/main/ambient/chai/index.d.ts" ></reference>
    

    Can you please fix the test suite too?

  • lceames Avatar

    Would it be cheating to download a list of prime numbers and incorporate it into the solution?

  • hfun Avatar

    I have the same issue as 'hamburger' I have time ~15ms Passed: 0 Failed: 0 it'd be really nice to be able to actually see what's going on/comming out.

  • hamburger Avatar

    Time: 15ms Passed: 0 Failed: 0 Test Results: sumOfDivided_Tests Fixed_Tests

    and what???

  • maipatana Avatar

    This one has really burnt my brain out. I was a good one though.

  • ultimastorm Avatar

    Colud you update the tests for Elixir, please?

    fixture:53: warning: random:uniform/1: the 'random' module is deprecated; use the 'rand' module instead
    fixture:61: warning: random:uniform/1: the 'random' module is deprecated; use the 'rand' module instead
    fixture:69: warning: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
    
  • Arunothia Avatar

    This comment has been hidden.

  • Arunothia Avatar

    This comment has been hidden.