4 kyu
Sum by Factors
2,279 of 20,099g964
Loading description...
Arrays
Algorithms
Mathematics
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
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.
This is a very optimistic assumption, especially in languages with uncontrolled and unmanaged and unprotected memory access, like C and C++.
It is also difficult to say what is wrong with your solution without seeing your code, but " SEGV on unknown address 0x000000000000 [...] caused by a READ memory access" suggests that you are trying to read out of bounds of a vector.
Why is it annoying? It is a requirement, your task is to satisfy it.
Your solution crashes for an empty vector. I agree that this could be spelled out better in the description, but it is not the case of "runtime is broken" .
Hi, hobovsky, thanks for your answer. How do you know that the crash is because of an empty vector? My solution works with the samples that were given, without a crash. Also, I disagree that it is a requirement to test with extreme numbers. It is not part of the description. Isn't the exercise about solving an algorithm? Not, "Make leaky C/C++ abstractions about integer safe". Finally, I wonder why you mark the issue as resolved. It is not for me. And last but not least it would be helpful to see the test parameters where it crashes.
Extreme numbers are tested, therefore it is a requirement. Perhaps you could have a suggestion to add that to the kata description, but that is not an issue. An issue is a bug with the kata. Since the problem you described in your initial post was not a bug with the kata, but a bug with your code, it is not an issue - that's why it was marked as resolved. As for printing the test parameters when it crashes... can you not print to the console and flush in that situation?
I tried to print the list of parameters onto the console. It works in my environment and also in the sample tests, but not in the "Attempt".
This comment has been hidden.
Did you take Hob's reply into account? I'm just guessing, but... what's the maximum of an empty vector?
I read the error message you posted and I see that your solution crashes by reading past the end of a vector. I saw your code, and I noticed that you dereference a pointer returned by
max_element
without checking if it's equal tolst.end()
. Ifmax_element
returnslst.end()
, which would happen for an empty vector, your solution would crash. Then I tested your code with an empty vector and it crashed for me, as expected.This is not enough. To pass, your solution has to pass all tests, and not only examples. To be sure that your solution is correct, you have to test it with more inputs than just examples.
While I agree with description not being perfect, I am not sure why you are so fixated on huge numbers. In the C++ version of this challenge, elements of
lst
are max +/-40_000. It is quite reasonable to expect your solution to work for numbers of magnitude of 40k.Algorithm which solves the problem for small numbers, and not for other numbers, is apparently not a good algorithm for this challenge.
I marked the issue as resolved because you raised it on the premise that "runtime is broken", which is not. You need to fix the crash, because it is caused by your solution, and not by the "broken runtime". I agree that having limits of inputs described would be good thing, but then the issue should be "description lacks details about ranges of inpits". I am also confused because I do not understand why you consider numbers like 40_000 huge.
Unfortunately, when a C++ program crashes (as opposed to returning a wrong answer), there is not much what can be done. Current testing framework does not allow for showing inputs of individual test cases, because it would be difficult to do in C++. Yes, there could be an additional, separate test case for empty vector, but not a separate test case for each tested vector, with its content presented to user on failure.
Thanks for the hints with the empty vector, I could solve it now. That was it. Oh my gosh, I commented my program, beginning from returning "shit", and finally it seemd that the ostringstream had a problem. I was so desparate that I used a global std::string to build the output string after all. And all I had to do was to return "" for the empty lst. 40000 is not huge, but I wondered if they relly tested with INT_MAX. But then, some of the solutions would fail as well, because, what is INT_MAX+1?
By the way, here's an example of this kata crashing and still logging the input to stdout (with no relevant solution code):
I've commented out the endl manipulator because endl happens to also cause a flush to happen. So you can either use endl to flush, or just use flush itself.
seems like 6 kyu to me... just use basic knowledges and it is solved
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.
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.
This comment has been hidden.
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.
This comment has been hidden.
Hello! I need some help here! Should the same numbers be part of the result? I'm getting this failure:
Not a kata issue.
This comment has been hidden.
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.
can someone educate me on why i get a kata right but gets a time out error in higher numbers.used python
it's because your code is not efficient enough, i.e. it takes too much time to execute. in Python, "for" loops must be avoided as much as possible: use built-in functions or list comprehensions whenever possible
This comment has been hidden.
its not clear what the input was going to be. made me waste time
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!?!
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:
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.
The irony of this explanation being marked as spoiler...
But I do agree that the description it wasn't very clear, I postponed doing this kata for a few months because I couldn't understand it well at a first read.
sometimes its better to just take the F, learn what you can and return to it
thanks for the explanation dude. but Why in I = [12, 15] we didn't get [2, 12], [3, 27], [4, 12] and [5, 15]
@Manneta because 4 is not a prime number. Therefore, cannot be used as prime factor.
Nice kata!
Can someone provide more context on the problem description? Im am trying to do this problem in Golang and:
The input format varies depending on the language. In Go one must return a format output given for this language in the description, which is a string, like the function's signature indicates. In (3 27), 27 comes from 12 + 15 because both are multiples of 3, this is what the task is all about.
What the puzzle wants is the prime numbers from a list of numbers, for example: (33, 66, 72) and wants you to find all the prime numbers that are factors of those numbers. The primes from my example is: (2, 3, 11). Then it wants the numbers that contain the primes added together next to the primes. Example: (2 66+72)(3 33+66+72)(11 33+66) Output Example: "(2 138)(3 171)(11 99)"
C fork
Appproved, thanks!
python new test frame work
.
VB (at least in basic tests): expected and actual are swapped in output logs
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?
A single online research will give you the answer. There are advanced techniques faster than a sieve of Erastothenes, but you don't need them to solve this kata. Actually you don't even need a sieve. Just think and try to find a method suited for your purpose. What's the purpose of a sieve? Is it actually what you need? If you think it is (it may be, it may not be), do you use it optimally?
This comment has been hidden.
It's a possibility. Now you can see comparing with other solutions that it was not the only one.
I was wondering the same thing...
You should really explain what an "ij" is.
Python: sample tests are not using the test framework
corrected.
C#: method name should be
PascalCase
(Please refer to implementation of backward compatibility here )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.
Read this for more info
Are there input restrictions?
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)
100 random tests.
I counted 105. You can see that using this code:
5 fixed, 100 random tests.
This comment has been hidden.
C# tests are not passing. Could you please look if the random test cases are correct?
1,009 people out of 16,202 passed C# kata (look at the top of the page).
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.
Nevertheless 16,120 people passed the kata...
Does anybody else has problems with javascript tests?
No)
expected [ [ 2, 24 ], [ 3, 27 ], [ 5, 15 ] ] to deeply equal [ [ 2, 12 ], [ 3, 27 ], [ 5, 15 ] ]
For me, the problem description is not clear
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?
[5, 0]
is not the only result for that input. It's in the example to show that the sum can be zero.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.
i my self had an actual result equivalent to "" for this test, moreover, any test that has an output sum of big negative numbers is not encluded in my actual result, can you pass some info pleas?
i my self had an actual result equivalent to "" for this test, moreover, any test that has an output sum of big negative numbers is not encluded in my actual result, can you pass some info pleas?
Awful task description...
Surprised this is rated so highly. Examples are not a good description.
This comment has been hidden.
Doesn't seem so. Why don't you print the input?
I didn't think that would work in the test framework.
Anyway, I was wrong; I wasn't handling the case of repeated inputs correctly.
This comment has been hidden.
Hi I don't use JS so I can't help you specifically, but if you want people to read your code it's recommended you use the Codewars Markdown layout - this will allow your code to be readable.
You can learn how to do this here:
https://docs.codewars.com/references/markdown/
This comment has been hidden.
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?
This comment has been hidden.
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.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.
Modified as in Java.
Like in Java if you want to exclude 1 I would suggest to exclude also -1 because it is also a unit in ℤ.
Right, done.
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 creationdoEx()
:Fix is easy, just put the postfix increment into the array assignment.
Ok, thanks! Modified.
Yes, that will work. If you want to exclude 1 I would suggest to exclude also -1 because it is also a unit in ℤ.
Right, done.
Python new test framework should be used with unnecessary logs removed
Hasn't g964 approved his new translation with new framework and without logs? =/
Reraised above
Ruby 3.0 should be enabled
Function name should use
snake_case
Enabled + added random tests in this Ruby translation
Forked & approved. (Honor points go to @4500zenja1)
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 ]?
It's impossible to answer you without knowing the test case you are refering to.
If no number from the array is divisible by a prime factor, then the sum will be equal to 0, or should there not be this pair at all?
You are right. If no number is divisble by that prime number it should be added to the string at the end.
OP solved it, closing
This comment has been hidden.
I tried troubleshooting your solution - since this is a 4 kyu I don't want to give you the answer directly because it's supposed to require a bit of debugging, but I'll give you a hint with specific examples:
Take the fixed test where you fail and look at the numbers where your code misses/skips some prime factors - for example, run your
get_prime_factors
on justn= -72769
. Why do you only get53
as a factor?.
Thanks @benjaminzwhite ! That is very helpful
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?...........
Because: https://docs.codewars.com/training/troubleshooting/#.print-vs-return
This is my bad. I printed ans, but didn't return it
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
Before posting issues look at the top of tha page: more than 5000 people passed the Python kata -> if there were errors somebody woul have seen them before you.
I did, and I'm not saying there are errors with the kata. I've seen replies similar to this on many posts and was careful to consider the possibility I was making a mistake before posting. I'll continue to work on the assumption that there's an issue with my code somewhere, but a more generous reply could be in order in this case...
EDIT: I am now receiving some sort of time out error whereas it was hanging this morning and last night. Thanks if anyone did something to correct the behaviour :)
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?
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.
Maybe try and implement it another language, just to see whether your algorithm works. I just reimplemented my Python code in JS and validated that the algorithm approach is correct. Now, I need to find the issue with my code.
I also need some help with python,
I pass all the tests, but timeout has appeared soo i need to optimize my code,
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?
Your mistake. Look at the top of the page before posting : 917 people passed with C#.
Great kata. Corner cases add nice touch on this!
This comment has been hidden.
This comment has been hidden.
there are more than 43 random tests. passing 43 means you are timing out on more than half the other random tests
starting from scratch or tweaking it is entirely your choice (and will come with research). either way, all that needs to happen is for the algo to run faster
This comment has been hidden.
This comment has been hidden.
you need to think of a different algo/solution that doesn't use four loops
any more hints and i'll have to give away the answer ;)
This comment has been hidden.
There is a python Basic Test that has a bug:
[5,0]
isn't consitent with other tests outputs.Had to handle it as an special case.
Not a kata issue. Before posting issues look at how many people passed the kata (4932 with Python); if there was a bug someone else would have seen it before you:-)
This comment has been hidden.
This comment has been hidden.
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
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.
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
This comment has been hidden.
Reviewed, approvable.
if you say so... ;)
Approved 2 days ago?
No, I didn't propose it and you did right in not approving it, I wanted to have some reviews :)
Seems it was approved by (?).
Hobovsky did :)
This comment has been hidden.
"trimming down" the code doesn't really help if the algorithm is not efficient in the first place
learning/trying new algorithms is part of the challenge in codewars
Why is my solution inefficient? I just started studying Python a few weeks ago.
It's not a problem with Python, but with the maths.
Read this for more info
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)
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.
This comment has been hidden.
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!
Yes, simply do not use PHP.
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]
This comment has been hidden.
Print the input, the first value in the error message is what your function wrongly returned, the other is the expected value.
this error occured in basic test 3 i think that correct answer is [[2, 56], [3, 54]]
Again, print the input. If you don't know what it is, how can you say "this is the correct answer"?
Read this: https://docs.codewars.com/training/troubleshooting/#print-input
sorry for worrying. and 10x a lot for link. that's was my mistake
This comment has been hidden.
So maybe it's not as easy as you think ;) For some reason it's a 4kyu.
Right. :)
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?
One can't know. If not requested explicitly, it could come into scope by some indirect includes, or in some other way, and it's difficult to find out what it actually is and where from.
Since one cannot tell what exactly it is, it's difficult to tell what it actually does.
See both of above.
Unfortunately, not.
Botom line is, when you want to use
std::unique
(or any other name, for that matter), you need to explicitly include headers which provide its declaration. If you attempt to use it but you do not include it, it's an error on your side and strange things may happen.Question resolved.
Yes, it was difficult. How do you C++ people debug such things?
Sure, it was. Yet, if I do similar mistake in other programming languages, I typically get a compiler error. I think this is a real disadvantage of C++. Code compiles (and for whatever reason even worked), so how should I find out I made a mistake? This time I was lucky, because Codewars uses a different compiler or whatever. If this were production code, it would have gone unnoticed. I want to prepare myself for real-world C++ with Codewars. Any additional hints are welcome.
Simple: we switch to Java or C#.
Switch to Java or C# :trollface:
This comment has been hidden.
I didn't downvote your post... Fixed tests have the following form:
Since you have already passed some of my kata with C# have a look at the tests and you will see how they are built.
Because on linqpad the input you give is wrong as I already said.
@g964 Hi, could you please have look at the question two days ago. It is not resolved. :(
I already answered... When you wrote: "12, 15, ..., -72769, -31744" you wrote your printing of the inputs of several different tests included in "test1()". If you want to have clearly each input of each test you have to print some separator after your lines:
I think you are at CW since long enough to understand that:-) BTW before posting issues have a look at the top of the page: 795 out of 12,246 passed the C# kata; if there were errors somebody would have seen them before you, all the more that the fixed tests are the same in all languages. Moreover there is no need to repeat a wrong issue and to downvote my previous answer... Good luck and cheers!
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!
The input you give is wrong: you are putting 7 tests in only one...
@g964 But some of the test are working. I put seven tests in one? But I use the test cases of Code Wars.
Downvotes without answers are useless. ;)
This issue is not resolved. The test is given by CodeWars, not by me. @g964
Downvotes without answers are useless. ;)
I don't understand this kata
me too
me too
me too
Imagine you do the following (that may not be the thing you must do actually to solve the kata cause it could be too inefficient, but to help you understand):
I didn't do much more than rewording the description. If it's still not clear it may be that it's hard to explain it more easily...
I thought I was the only one.
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?
There is no error in the tests. Notice that 684 people passed the C++ kata.
I passed the kata assuming unique values in array I.But my guy,i asked you a simple question with a simple yes or no answer.I dont care how many people passed or if the tests have errors. Please read : https://www.americanexpress.com/en-us/business/trends-and-insights/articles/think-fast-10-ways-to-be-prepared-for-any-question/
This comment has been hidden.
A lot of part of your code is redundant and can be done in O(logN).
You are checking unnecessary values on whether they are being prime.
You need not to pre-generate prime values beforehand
You need not to sort and remove duplicate entries
Remember that you only need information on the shared prime factor numbers between each numbers in the list.
*
This comment has been hidden.
Sorry your code is wrong somewhere. BTW before posting issues look at the top of the page to see how many people passed the kata (2732 in JS). When this number is high, high are chances that your code has a problem. Cheers.
No, even the number is small it's not checked, my function is not return blank but it regcognise that my function return a blank array. My code is right I wrote an test in VScode. Please check
Oh I see the parameter is an array, and I miss understood that the paraments are numbers. Thanks I found the problem with my code.
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?
Test shouldn't log to console (at least in JS)
I don't understand your post because I am quite sure that I read somewhere from @hobovsky that input and expected must be visible so people who try to pass don't have to print the input and they can know expected answers.
Should be visible, yes, but there are better places to put these: titles of test cases, assertion messages, and other places provided/controlled by tests.
Standard output is not a good place for information related to tests results.
One note though: Some kata have very large inputs and answers (blocks of textx, matrices, large arrays), which look bad when presented in any way other than stdout.
In such cases it's rather fine to have it printed to stdout rather than totally hidden, but usually it's a good idea to make printed output as terse as possible (for example, do not display it at all when test passes, print necessary information only on failure).
In this kata you can see my proposal of handling large inputs with stdout: https://www.codewars.com/kata/54c91b5228ec4c3b5900036e/train/java
Ok sorry then @g964
No problem.
This comment has been hidden.
This comment has been hidden.
Solution for what language is that?
Sometimes it might happen that tests are bad and let some insufficient solutions pass initially, but they get improved later so new bad solutions do not pass anymore, but old ones are still listed as valid. Solutions which do not pass new tests should be automatically invalidated and hidden, but it does not always happen.
If you tell me the language, i will revalidate top solutions so the bad ones will disappear. And you need to think of a better solution. Or check the second one from the list.
Language Python? The tests were modified a few months ago. Bad solutions (including codes with "xrange") were not invalidated maybe because there are lots of solutions (4233); it is not the first time I see that at CW. It is not a problem of the kata itself so I don't think it is an issue (I can be wrong...).
For me it didn't time out since it uses "xrange" and didn't pass. You could have taken mine that regularly passes in about 700 ms...
Maybe @hobovsky is able to make the bad ones disappear and I let him decide if the issue is resolved or not.
Indeed, I was using the python language and replaced the xrange reference with range.
I am going to mark this issue as resolved, because it's not a kata issue. It's related to how mechanism of invalidating of old solutions works (or not).
I have not solved the kata in Python so I cannot see solutions or invalidate them, but I will try to get someone on this.
done
You have to use sieve to calculate the primes
Well, not really. There are many solutions which do not use sieve.
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.)
I've just run full tests in both languages, and I get a max of 173471 for JS and 992753 for Python. There's a difference but not that big. You actually don't need a very sophisticated optimization to solve this kata in Python. Moreover, do you know Python has efficient tools in some library to handle primes (though they are not necessary).... ? Js hasn't. I've just tried them out here and they work wonderfully. That makes a true difference ;)
Thanks for the response - I see the 173471 in JS basic tests, but the second highest is 72769, followed by 2040. So it would be better to talk averages. Looking at the average of random tests for JS, the average is probably 100 with no value exceeding 200. Python's average is probably about 500,000.
I must be missing something obvious about prime principles.. I will keep trying.
Maybe. I've just revised my solution and for me the difficulty here is not in factorizing the different numbers, but rather in the phase of assembling factors. I still could not solve this kata in Go because of that.
Is there a way to get past timeouts using js? Already applied a few optimizations for prime checks, but still getting timeouts
My solution still works, so I'd say yes, there is.
Ended up researching a lot about primes and used Eratosthenes' sieve with just index checks, and sped things up soo much.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Please use the spoiler button when you post code in the discourse.
This comment has been hidden.
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.
It would be better to start with a more naieve approach, and only optimize along the way when required to. I also noticed other translations (the ones I solved thus far) do not require a sieve, so the C translation is no exception.
This comment has been hidden.
This comment has been hidden.
Please use code blocks when pasting code.
This comment has been hidden.
This comment has been hidden.
Uncomment that code, and add a condition that when
lst.length == 0
, return[]
Because:
(And these were causing your code to time out)
Got it?
I think that makes sense. I will try and get back to you. Thank you for responding!
THANK YOU SO MUCH. I'VE BEEN STUCK ON THIS FOR LIKE 2 WEEKS NOW. I can't tell you how grateful I am for your help @ӜЯℱӁℒᚹ
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.
You could try storing primes in a global/static variable. That way you only calculate them once during the first function call.
I did that, but it's still taking too long because of how large the numbers are. I've been stuck with this all day.
You don't need a sieve to calculate prime factors. Its OP. Look at trial division.
This comment has been hidden.
-5 is not a prime number, so it should not be listed as a prime factor.
right, i literally forgot about the answer must be prime numbers.
what if inpputed number contains
-315
factors of
-315
can be[3,3,5,-7] or [-3,3,5,-7] or [3,3,-5,7]
which the prime factors could be :
[3,5], or [3,7] or [3,5,7]
what do you think about that ?
Neither 3 nor -3 is a factor of -35. Factors of -35 are 1,5,7,35 and, if you count negative factrs too, there are -1,-5,-7,-35. Out of all of these, the only prime numbers are 5 and 7.
i've edited the reply, would you mind reanswer my question.
OK, I need more carefully.
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.
Not a kata issue. Notice at the top of the page that 616 people pased the C++ kata.
I'm sorry about that. I want to know how to deal it.
i got the same case. What does it mean?
I sure you should consider more carefully that the input maybe is "NONE".
@kochka, @dawnli, the error you're getting a segfault, a.k.a accessing memory that you shouldn't access, you can google segfault.
edit: i just realized that I'm replying to a thread 2 years ago
still possibly useful to someone else reading this in 2 years
This comment has been hidden.
C: I get the following error ..
.. eventhough the verification process does not free the empty edge case:
If I comment out the "free" part, it works.
I added the following test case to verify:
Is this a kata issue?
I don't think so but I'm not at the best place to answer that... I tried several solutions amongst the 188 C solutions which passed. I had no crash.
Your solution crashes - as far as I have been able to experiment - with or without the "free" part in the verification. It doesn't crash when removing
cr_assert_str_eq(sact, sexpr, "");
. Sorry to be of so little help!Fixed it with an initial larger buffer. I would have expected "strcat" did a reallocate for us. Thanks for investigating.
Good!
I = [12, 15]; //result = [[2, 12], [3, 27], [5, 15]] Why result doesn't include [6, 12] ?? Thats also a valid value
6 is not a prime number.
but 5 and 3 are prime factors of 15 right
Yes, that's why you get [3, 27 = 12 + 15] and [5, 15]
i actually didnt understand the kata. is it like finding the factor of a number which is prime?
@kingcobra_
You need to find the prime factors of all elements of
I
, then produce the sum of all elements ofI
that share that prime factor:[(prime factor p1, sum of all elements of I with prime factor p), (prime factor p2, sum of all elements of I with prime factor p2), ...]
Thanks! :D.
Turns out that only 2,3,5,7 are valid numbers
nope they're not
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.
In a similar situation, I have managed to get to Test 12 with [100000001, 10000000055] but I can't think of a nice way of making my solution more efficient. Though I have only been using Elixir for a few days so I not sure what exactly is expensive just yet.
For Elixir, that's the same test I also fail at the moment. I tried Streams instead of Enums to gain some performance, but it seems to boil down to the point, that the naive prime check relies on counting the divisor up to 100000001 and 10000000055 by one, which breaks the timeout limits.
I wonder, if we could speed this up or do some other kind of prefiltering magic, like implementing a "Sieve of Erasthosthenes" somehow, but that also sounds quite "expensive" towards execution times.
As I am far from being a "maths guy", I am maybe just missing the obvious here :)
Edit: Just after I wrote this, I came up with a working solution. This does not make the algorithm faster, but spares a lot of unnecessary turns with minimal effort, especially when testing big primes.
This comment has been hidden.
It says time out error, can anyone help me?
This comment has been hidden.
Are you certain you are
returning
your answer and not justprinting
it? Because the test result claims it receivedNone
, which is the default return value for a function that doesn't have a return statement.that´s. Thank you very much
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.
Your assertion "...as the correct answer (this is from the checker)" is wrong. Verify your string: it is badly copied.
It is asked only by you, 3 or 4 days ago. I verified several solutions at that time and all worked fine so there was nothing to fix (note that 597 people passed the C++ kata).
I corrected the string you badly "copied" from the checker. This time the corresponding test is passing but here is what I get:
Please fix your code:-) Cheers.
sorry about the "this question is asked in all disscussions and haven't been resolved", I was meaning that Ive asked this question in the "all" disscussion tab. Im new to this platform.
about the paticular test case, did you mean that the answer I'm assuming to be correct, is actually wrong ? Because that is what the checker is expecting me to return, and i triple checked it to make sure im not seeing things. I even tried returning a const string to other answers aswell and it works.
Sorry if i sound furious or something, its just that im frustrated about this one tc and its bothering me alot. A single respond saying that the string im assuming to be correct is wrong is enough.
I already said that you had wrongly copied the answer to that test. Look carefully at what the test outputs when it fails and at what you had copied. When I looked at your solution for my first answer you had at the beginning of your copy an extra white space!
you meant the string ive returned looks like
" (something)"
? Thats because i couldnt return the correct string or else i cant output any debug information. Also, my solution made the checker return in stderr exactly what you said in the first comment (as is has been for the past 3 days, only on that paticular test). Is this normal ? since anything other than the "correct" string i return does not make stderr output that message, and i still fail that test though.This kata with python, doesn't matter what kind of solution you use, all of them gives a timeout error
Python version is alright.
I am stuck with python. I have used very fast method for searching prime_numbers, but still timeout. Don't know where I am messing up.
Same here
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
Please state the language you're talking about.
its C++.
[ [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
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] ...]
No.
This comment has been hidden.
Thanks, it was fun kata :)
Thanks!
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.
Get TimeOut everytime, very frustrated:(
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
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);
?Expected (2 12)(3 27)(5 15) got (2 12)(3 27)(5 15)
same test pass in "sample tests" but fails in "attempt".
It's not that test you fail.
I got it. Ocaml tests mark all tests failed if one test fails.
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.
This comment has been hidden.
I rather think that not having an optimal / elegant solution is the point.
the story of my life
nice kata
This comment has been hidden.
This comment has been hidden.
Not a kata issue, rather a question. Good solutions run in less than 2 seconds.
I mean ya probably my solution isn't the most efficient. My only quandry is that there is no random tests for this kata. And sample size is super small... I think
Running tests with incorrect solution gives this, (that's how I gauge what tests are running)
Am I right in assuming that the server runs all tests and doesn't bail if some of them fail?
The server stops when a test fails.
ok thanks :)
This comment has been hidden.
It's difficult to say exactly witohut seeing the code, but your loops seem to roll too much. To find factors, do a prime factorization, etc. you never have to loop up to the number, required limit is much lower.
.
This comment has been hidden.
You code times out because it is too slow. 2nd question: I don't think it makes it slower but in some cases can cause undefined behavior.
Dear Creator, I enjoy working with prime numbers and I found this Kata fascinating. Thank you!
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)
And what result you get when running your solution locally in your IDE?
How do I see what the random test is?
Print the input.
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#print-input
Ok, i found the error in my code, thanks.
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 ?
How many times do each of those numbers that 2 is a factor of occur?
thanks...yup two times...so thats a bug in my code...will fix it
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
a = [15, 30, -45] 2 is a factor of 30 the sum of numbers divisible by 2 is 30 hence a partial result [2, 30] 3 is a factor of 15, 30, -45 the sum of numbers divisible by 3 is 0 hence a partial result [3, 0] 5 is a factor of 15, 30, -45 the sum of numbers divisible by 5 is 0 hence a partial result [5, 0] So the final result is: [[2, 30], [3, 0], [5, 0]]
ok that makes sense...that is what i was thinking...the way kata is described it never lets that on...i thought it was saying it can only be 5,0
The case 5,0 was only an example...
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?
The input is
[12, 15]
.Yes, but the input in the example is
[12, 15]
.Are you sure you did not mix up some examples? The example you refer to I see as
[12, 15]
and indeed valid answer for it is[ [2, 12], [3, 27], [5, 15] ]
. I do not see any example of[12, 15, 18]
.EDIT: Damn, I was late to the party ;]
The example I see:
class SumOfDividedTestCases extends TestCase { private function revTest($actual, $expected) { $this->assertEquals($expected, $actual); } public function testBasics() {
$this->revTest(sumOfDivided([12, 15, 18]), [ [2, 12], [3, 27], [5, 15] ]); *** // REFERRING TO THIS LINE *** $this->revTest(sumOfDivided([15,21,24,30,45]), [ [2, 54], [3, 135], [5, 90], [7, 21] ]); $this->revTest(sumOfDivided([15,21,24,30,-45]), [ [2, 54], [3, 45], [5, 0], [7, 21] ]); } }
Click reset (before backup your code if you have it), the test should be like this:
@Chrono79: Yes that now fixes it, strange. Thank you so much!
This comment has been hidden.
Yes.
My solution only works for positive values, when it comes to negatives sometimes the result is 0. What do i do in that case? Thanks, Luis
EDIT :already solved thanks
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.
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#c-error-undefinedbehaviorsanitizer-segv-on-unknown-address-0x000000000000
Hi, I have a problem just like you have. Can you help me?
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.
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.
It is a question, not an issue.
Unfortunately you don't have all your results OK. I ran your solution several time and the last one gives: "Time: 8596ms Passed: 90 Failed: 20 Exit Code: 1". A failed example:
This comment has been hidden.
I have read this multiple times and I still don't get it. Can someone please explain what we're supposed to do?
same here. . . description shoulb be more clear. .
same here...
Given an array* of integers find prime factors (divisors) of every single one of them and for every unique prime
p
obtained this way create pair* (p
, sum of all integers in an array* whichp
divides), collect those pairs* in an array* ordered byp
from lowest to highest and return.* how data structure in question is called depends on language you use
Still don't understand what this part means, thanks!
See the example in the description, 2 is only a prime factor of 12, so the first pair is
[2, 12]
, 3 is a pf of both 12 and 15, so the second pair is[3, 27]
where 27 is 12 + 15, and lastly 5 is pf only for 15, so the last pair is[5, 15]
.So here's example if
p = 5
then for[12, 40, 20]
,p
divides40
and20
because40 % p == 0
and20 % p == 0
.Exactly, and the pair for 5 would be
[5, 60]
Thank you Chrono79, that explanation did clarify the challange. I thought at first that I had to combine the elements of the given array.
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
Notice that it is a question, not an issue:-) I tried several solutions and all worked fine. 23 guys passed the R kata; not a lot but I think it is enough to say there is no error in the tests. Moreover you are failing some of the fixed tests that are the same in other languages.
There is no rounding in the tests. They simply compare the actual and expected results but it seems that R tests give an indication of the falsety by indicating a difference of mean which is without interest. You should give an exemple of input with your output for a failed test so I can give you the expected result for this test.
You could have a look at https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution.
Alright here is what I get:
Test Failed
actual
not equal toexpected
. Length mismatch: comparison on first 3 components Component 3: Mean relative difference: 0.8214286Log
the list was 107 158 204 100 118 123 126 110 116 100 the returned res was c(2, 1032) c(3, 453) c(5, 310) c(7, 126) c(11, 110) c(17, 204) c(29, 116) c(41, 123) c(59, 118) c(79, 158) c(107, 107)
What's the problem here?
Read carefully the tests results. You don't fail this test.
This is for the previous one. Your output is above the result of the test. Rather look at the previous one:
testing(c(15,21,24,30,-45)...
and verify your result by hand. Hope this help.My bad. Now I see which case was failing and why. Thanks for bearing with me.
I couldn't understand the question. Can someone explain and give me another sample test case pls? what exactly should method do?
Basically, you have to find the unique prime factors of each number in the given list, group them by prime factors and sum numbers which share the same prime factor.
[16, 27, 33]
Prime factorization of 16 is 2 * 2 * 2 * 2, but we only consider unique prime factors, so 2
Prime factorization of 27 is 3 * 3 * 3, , so 3
Prime factorization of 33 is 3 * 11, so 3 and 11
Now, we have prime factors as keys with the corresponding number with those prime factors as values
So, the output should be the summation of those numbers in string format with their corresponding key.
My code uses sympy which doesn't seem to be recognised? Is there a glitch or does the python package not include sympy anymore?
The python package does not include sympy.
This comment has been hidden.
Tests are not broken since 567 people passed the C# kata. Sorry but I don't understand your problem: the description says:
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!
UndefinedBehaviorSanitizer can not provide additional info. ==1==ABORTING
Please help me.
It's difficult to tell exactly what's wrong without seeing your code, but error message suggests that you dereference NULL pointer at some point. Or you return NULL and test suite dereferences it because it expects some valid pointer.
I found at least one flaw in your code. Have you thought to all kinds of vectors you can get?
This comment has been hidden.
@g964 you there??
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:
I am sorry if I am spoiling anyone. I try not to.
You only show the prime number if it is a factor of at least one element of the set. Your comment is not a spoiler - spoilers tend to be code ;)
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?
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 ];
I tried several solutions and they worked fine. There is sommething wrong in your code. It seems that the missing element is the last.
That last element is missing only on your site. I tried that input on my system and the last element is there. Because tle last element on my system is in the output I can't "debug". But, without changing the code, I tried again and again the "Attempt" button and my solution was accepted. Because I did not changed anything in code, I still think the problem is with tests or site. But not a problem of me anymore. Anyway, good kata. Thanks.
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.
I have a question, should we be trying to create our own "find_primes_up_to_n" function?
Typescript attempt-base-test-case is incorrect whilst every other case passes. Verified out manually and my output is correct.
Sorry the "attempt-base-test-case" you fail is not incorrect, it has no error.
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😉
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 ?
Why should it be removed? Read the description again.
This comment has been hidden.
Not an issue. A proper solution can pass the tests in ~20 milliseconds.
The description was hard to follow until it clicked. Great exercise
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?
I don't understand what happened since (see the top of the page) 535 guys passed the C# kata without complaining. Nevertheless I slightly modified the tests. The reference solution and the solutions I tried from other people take between 1600 ms and 2000 ms.
This comment has been hidden.
Timeout is not a kata issue.Cheers.
Cheers but not cheers, it's been 2 days I try to send this code it doesn't work. It is related to the code somehow but it don't understand at all what is wrong in it or what is wrong with the server taking care of it (it takes 1 second on my my computer to calculate this for range(1000)). I sent different versions that didn't trigger timeout but this one does, and I try to understand why
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]]
You should state which language this is, also there are over 7k completions, more likely it's a problem with your solution. You should double check your code and if the issue still persists then you can post your code as a question with spoiler flag.
It's Python. But ok, I'll have a look at it again.
Alright it helped to take a break from it.
I had defined a global array, which kept growing between the tests. Didn't know that it was not allowed.
Very artificial exercise. Completely useless test cases. Waste of time
Awesome kata! I have learned so much through your prime katas...
Thanks!
This comment has been hidden.
don't use a list for your primes if you use containment check, and remove (those are slow operations). Moreover, dont generate ALL the numbers up to n, you're ruining the use of what's in your condition for the while loop. Btw, archive the result of that function so that you don't compute if each time.
All in all, you have to totally garbage your first for loop and the while one just after: merge them together, replacing the while with a more appropriate for loop (you'll still need the inner loop), and find a way to avoid the remove/in operations, somehow.
Alternative: look up for prime generation algorithms.
final note: don't forget the spoiler flag when you post code (even if wrong)
.
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
There was a name conflict with your
const sum ...
. Should be fixed now, please tell me.Works like a breez. Thanks.
Great kata also.
In the kata instructions, it says
But it generate random test contains 1 as prime factor(Small probability)
I would recommend modifying the test data generator.
The description says:
I
must be composed of positive or negative integers and1
is a positive integer so there is no problem in the input. The problem is in your "Actual" since you considered1
as a prime factor of all elements of the input which is false since1
is not a prime number (not being a prime number it can't be in this kata considered as a factor). Hence your "actual" is false and the correct answer is "Expect". Cheers.Thank you for your reply. I didn't understand the meaning of the question correctly before.
This comment has been hidden.
don't post code without using the spoiler tag, thanks
I test the test one by one. try 3.4, 3.6 (version) python.
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.
Sorry but it's not a kata problem. Look at the top of the page and you will see that 337 people passed the C++ kata. Maybe try to get the vector length before printing it. Cheers.
This comment has been hidden.
kata hint != kata suggestion
This comment has been hidden.
This comment has been hidden.
Hi "Exit code : 139", what does it mean???
These two clarifications were helpful for me:
It will be nice if those two notes could be added to description.
Happy Coding!!!
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.
Sorry! The description says:
I thought it was clear that when there are no
i
inI
there are no[p, sum of all ij of I for which p is a prime factor (p positive) of ij]
in the returned array so you have to return[]
. I am surprised it doesn't work when you are returning the empty array (1377 people passed the JS kata). In fact your test of an empty array is not the good one. Sorry again for the inconvenience but at least you will learn something about empty arrays. Cheers and good luck!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] ]);
Read the instructions again, 3 divides all of those numbers: 15 + 21 + 24 + 30 - 45 = 45.
Thank you friend. I see now my think mistake!
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.
You could have printed it.
I couldn't get console.write to work when it was timing out.
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?
Not an issue of the kata. I tried several solutions without problem. Look at the top of the page to see how many guys passed the JS kata.
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.
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?
I'm solving this kata in C. What's the largest prime the solution has to support?
I don't remember the exact number but it's around 5.5k I think
How to return the buttons for testing?
I try to test, but I do not see the button
For JavaScript
What numbers have
107
as a factor? It feels like the test case might be suggesting107
is its own factor since the sum is exactly107
?I might have just misunderstood the description?
Yes,
107
is a primary factor of107
, what a surprise!It feels like you're suggesting that 1165 people completed this kata in JS, and nobody noticed an issue. Your solution is wrong.
Based on the condescending replies, I guess I need to explicitly define some terms that I had assumed were well understood on a site such as this.
*Note the bolded terms below
From the description:
In number theory, integer factorization is the decomposition of a composite number into a product of smaller integers. If these integers are further restricted to prime numbers, the process is called prime factorization.
A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers.
I am assuming we can agree that prime factorization is the process for finding prime factors?
Note that there are two issues with calling
107
a prime factor of107
.107
is not smaller than107
1
which is not a prime numberTo be explicit,
107
is already invalid as a factor based on the fact that it is not less than107
. This means it cannot be an integer factor, much less a prime factor. The fact that the other smaller integer of1
is not prime is unnecessary.Maybe I am still wrong, but I am just not able to see it on my own. Instead of another condescending response, maybe provide some helpful information this time around? Also, I have no idea how my original comment warranted such condescension, but that is separate issue.
PS: On second thought, to avoid further condescension, I am just going to include a link that explicitly states the relationship between prime factor and prime factorization.
Writing a number as a product of prime numbers is called a prime factorization of the number... The terms in the product are called prime factors.
In that case, you should explain your problem explicitly, and not say "I think the tests are wrong".
Issue
should be raised when something is definitely wrong with the kata. If you assume that your answer is correct but you still can't pass the tests, post aquestion
- in this case, asking why107
is included in the output, despite not following the exact mathematical rules on integer factorization.So is there something wrong with the tests or the description? Your reply does not seem to address the actual issue.
It seems like you are just trying to defend your previous comment?
I actually said:
I even included "I might have just misunderstood the description?" because of how many people had completed the kata already. I thought this statement conveyed an earnest and polite tone, but for some reason, it was only met with condescension.
Just to be explicit and explain the same thing again. I assumed the terms factor and prime factor are very well understood concepts on here. I am still under the impression that these are fundamental concepts that all but true novices would struggle with. This is a 4 kyu kata, so I believe it is safe to assume it is not meant for true novices. Also, you literally need to understand how to implement integer factorization to even complete this kata.
Read my original comment with the assumption that the audience actually understands all of this. If that is the case, the reasoning should be self evident.
Again. Is there something
definitely wrong with the kata
? It seems apparent to me, but for some reason, you and another high ranking user stated otherwise. I would like to know the "some reason" if I am wrong, or at least have my suspicions confirmed.From my second comment:
Seriously though, was my assumption that these terms should be well understood by people who have completed this kata unreasonable? Feel free to point out where my thought process is wrong. I would honestly welcome it at this point because this entire interaction has confused me.
"...of a composite number..."
For composite numbers.
At the same time "factor" seems to be a synonym of "divisor" in the context of number multiplication: https://en.wikipedia.org/wiki/Divisor
In any case, Wikipedia articles can sometimes be reworded without much thought, losing subtle details.
Another source: http://mathworld.wolfram.com/PrimeFactorization.html
Thanks for the explanation. Turns out I was completely wrong. I'm glad someone finally explained it to me.
Found a Wikipedia article that almost mirrors the wolfram article, but it left out the 1 which is probably another subtle detail lost...
https://en.wikipedia.org/wiki/Table_of_prime_factors#1_to_100
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)
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).
Fixed, thanks!
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
Not a kata issue.
Did you import all classes/features/whatever you're using in your code?
Debug the issue. If an unexpected input is causing your code to throw an exception, use whatever the language stdout is (in python: print) followed by return 0 (or None, etc.) and figure out what input is causing the issue. Then get your code to handle it.
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 :
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: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.
I have exactly the same problem.
Look in java I've done it pretty easy, doubt it's any segfault. But u might be doing something that causes the issue , try to get my solution in c++. It's pretty straight forward and I'm not trying to be clever on it , who knows what format or other might be causing it.
Even I,m facing the same issue.
testBasics
passed onRUN SAMPLE TEST
testBasics
fail onAttempt
inPHP
Is it me or code?, please take a look!! How can I dump out
expected
result to hand check?It is a question, not an issue. You could have had a look at the top of the page to see how many guys passed the PHP kata. Print the input to see what is expected.
Hand checking the input gives correct answer (at least for the couple of inputs i've checked). Can you please give me one input and expected result pair for
testRandom
input so I can test it on my local machine to test?input
[27, 27, 26, 48, 41, 44, 32, 35, 31, 42, 45, 37, 48, -53, 34, 40, 45, 21, 38, 33]
output:
array(8) { array(2) { [0]=> int(2) [1]=> int(352) } [1]=> array(2) { [0]=> int(3) [1]=> int(336) } [2]=> array(2) { [0]=> int(5) [1]=> int(165) } [3]=> array(2) { [0]=> int(7) [1]=> int(98) } [4]=> array(2) { [0]=> int(11) [1]=> int(77) } [5]=> array(2) { [0]=> int(13) [1]=> int(26) } [6]=> array(2) { [0]=> int(17) [1]=> int(34) } [7]=> array(2) { [0]=> int(19) [1]=> int(38) } }
There are no random tests, at least in Haskell. (I haven't checked the other languages yet.)
Crystal has no sample tests
Done, thanks!
:)
System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. Parameter name: count
What is it??
C#
That's an error in your code. Look for an index out of range or rather, an int value that's overflowing or something like that (Note: I don't do C#, so I don't know exactly what this exception is. Though, I'd bet on the second one).
Note: don't raise issues for that kind of things, issues are used when the kata is dysfunctionning. But since already 300 users completed it in C#, the problem is more likely laying on your side. When you have troubles with a kata, ask rather for a "Question".
Cheers
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.
The algorithm you're using (at least for JavaScript), is incredibly slow. If you're using an analogous solution for bash, it's thoroughly unsurprising that it's not completing in time, given it's bash. Even the 'top' solution in JS is about 15x faster than what you've got, and it's quite a slow solution. I don't think it's really reasonable to force the kata maker to have set the bar so low that literally any solution will finish in time.
This comment has been hidden.
love it thanks
Thanks!
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.
Maybe I didn't understand well your first post and I answered wrongly but you could have seen in the description for C this line:
and in initial solution:
which shows that the return is a
char *
. In the description I will replace the line:by "The final result has to be given as a string in Java, C#, C, C++ and as an array of arrays in other languages".
since in that line I forgot "C". I am sorry and thanks for your post.
Don't worry! I agree that it can be inferred from the code, it really is just a small issue, not really kata-breaking or anything. But hey, it's a pretty trivial fix and no reason not to have it correct. I'd change it myself if I had permissions/knew how. Thanks!
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.
I am afraid you didn't understand well the tests. You have to return a
Data *
but to ease the testing your return is transformed by the tests in a string. This transformation has not to be done by yourself, it is made by the kata. Note at the top of the age that 47 guys passed the C kata.What you're telling me is completely incongruent with what the actual kata and the tests say. The function returns a string, and the tests do expect a string. There is no conversion whatsoever in the tests. The test can be passed, indeed I have completed it. I am flagging the poorly worded description that describes the kata incorrectly.
The kata is doable, sure, but the description is incorrect. Also, in the C solutions, you can see that everyone returns a string. It cannot be completed otherwise.
I'm reopening the issue.
No random tests in python -- however, as it was completed more than 500 times, it cannot be updated anymore...
This kata was written long ago when random tests were most often absent and was approved by jhoffner. No need to put an issue, I can't do anything about that now, sorry!
I know, I know... I shouldn't have marked it as an issue :-)
I believe there's at least talk of potentially opening old kata with > 500 completions per language to editing, though :)
The flood gate is already open:
https://github.com/Codewars/codewars.com/issues/1301
Just need to wait for the next deploy to the main site which should happen soon (it will also bring upon many other things).
Is it possible to add random tests now?
There are random tests now in python, someone added them in the meantime
I added them in Python and Ruby in August 2018.
Kotlin translation, waiting for moderator to approve.
Random tests are included
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.
Yes but when I saw that, more than 500 guys (586) had passed the kata so it was and it is not possible to modify something in Java translation. Sorry, it was one of my first kata. I approved your Kotlin translation.
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." ?
This almost certainly means your code is running too slowly.
Test is crushing on Swift. And it's not the only kata, that i couldn't finish cause of bugs in tests
If you want to post an issue about bugs in the tests you have to tell where the tests are wrong.
Test fails with error "fatal error: Index out of range", but in xcode all works perfectly well with test data. So the only reason i see here is bug in tests
Unfortunately for you there are no errors in the tests. Have you thought of possible edge cases? Have you look at the top of the page how many guys passed the kata? Don't you mutate the input?
I'm pretty sure, that my code is working right. Sample tests are working right, but when i send attempt tests fails with error
See if your program works on this input: [-12, -15]
I've been having plenty of Swift 4 vs. Swift 3.1.1 issues. Great practice in both versions of Swift and building my own tests. Keep on swimming.
Swift 3: myString.characters.count Swift 4: myString.count
Remember that Swift 4 String is collection of Characters, but Swift 3 is not. (see "string".characters) These plus other testing issues may block success.
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
This comment has been hidden.
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?
Odds are fairly excellent you were in an infinite loop.
This comment has been hidden.
Way too easy for 4 kyu, IMHO.
This comment has been hidden.
2 divides only 24 and 30 hence [2, 54], 3 divides 15, 21, 24, 30, 45 hence 135. Read again the description.
Got it. Thanks!
That took some time, and it was well worth it.
Thanks!
Time: 14ms Passed: 0 Failed: 0 Test Results: sumOfDivided_Tests Fixed_Tests
What does this mean????
It happens with C++... I think there is certainly an error in your code not trapped by CW Unit tests. Maybe the only way is to report the bug at: https://github.com/Codewars/codewars.com/issues
Fine. It's so wired that if I add 1 on each output item on purpose, it runs perfectly except all items 1 larger than expected. But once I deduct 1 from each item, which is supposed to show the correct one, it breaks down.
I think the testcase is really important, especially for the question for practcing algorithm, because it will cost a large amount of time debugging the code, which turns out to be a non-sense error.
Do you pass the example test?
I'm not the original poster, but I seem to have the same issue. My code does pass the example, and if on the actual solution I return something like str+" " (adding an extra space to make it wrong) it will say I failed 2 tests and will show me the results (for which my output seems to match expected result, with the exception of the space).
If the solution should be correct though, it says 0 failed, 0 passed, has a red border, but green arrows for fixed test, but doesn't show expected vs actual results nor random test header. Also the ms time is quite low vs when it's incorrect from adding a space. This seems to suggest (at a guess) if it passes the fixed test, it stops without trying the random test for some reason.
No output nearly always means your code compiled but segfaulted in execution.
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?
When running the example I got a reference error, the same error is fired when running the test suit, the log generated is below:
I fixed the example by adding those lines to the top
instead of
Can you please fix the test suite too?
This error has already been told to CW a lot of times. I fixed it again. Could you tell me if it works? Thanks for your post.
Yes solved, thank you!
Would it be cheating to download a list of prime numbers and incorporate it into the solution?
It's easy to write a function "isPrime" and enough to solve the kata...
Nope it's not called cheating, it's called preprocessing, it's definitely allowed in competitive programming.
It also does not solve the problem, merely makes the tests pass.
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.
Maybe the only way is to report the bug: https://github.com/Codewars/codewars.com/issues
Time: 15ms Passed: 0 Failed: 0 Test Results: sumOfDivided_Tests Fixed_Tests
and what???
I just tried a few solutions and all worked fine. Seems nevertheless that CW has problems since some time. Try again and if it doesn't work report it as a bug at CW (See Forum -> bugs).
ok, thanks)
This indicates your code produced a segfault (Runtime error for Windows people).
This one has really burnt my brain out. I was a good one though.
Burning brain can be good if not too often:-)
Haha, True. Thank you for the Kata :D
Colud you update the tests for Elixir, please?
There were Elixir or OTP changes at CW. Everything was fine when I publish this kata. I have just replaced
random
byrand
but now I getbut that doesn't harm the tests so you could give it a new try. I have reported the INFO REPORT as a "bug" on github; https://github.com/Codewars/codewars.com/issues/428.
I know. I think that the report has nothing to do with random/rand replace. I think is due to the changes they made. Wohever, in order to submit a solution, the changes has to be made for all the katas.
Again... thanks for the update.
If CW comes back to the older version (OTP 18?), the changes will have to be made again... in the other way. I suppose that the "random/rand replace" comes from the change OTP 18 --> OTP 19.
This comment has been hidden.
This comment has been hidden.