6 kyu
Special Multiples
413 of 1,329raulbc777
Loading description...
Mathematics
Algorithms
Fundamentals
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.
<3
How can I fix this? Passed tests, but can't submit...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
Read this: https://www.codewars.com/kata/55e785dfcb59864f200000d9/discuss#636dbbc33be460000ecb6af7
A problem with your code is not a kata issue.
Can't finish task. Please help. Language: Go
Test Passed Completed in 0.1059ms Attempt error: STDERR Execution Timed Out (12000 ms)
Your code failing is not a kata issue. An issue is a proved flaw in the kata, with concrete elements (inputs, logs, etc.). This means your code doesn't run in the time it has been conceded. In general the cause is that the algorithm is too slow, or that it gets lost in an infinite loop at some point. You can refer to this documentation for further help: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
Added in Python, tests imitated from the Rust version. Other languages not checked, open specific issue if needed.
time expire is not correct
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
all test passed but i cannot submit
Time: 3892ms Passed: 17Failed: 0Exit Code: 139
No, not all tests passesd. You tried to create array that's too large and tests crashed.
Please review: C++ Translation
Appoved +1
heh, love this kata... is it possible just to cover some edge cases?
a very nice kata indeed
#11b39/3qf:0z:vV
Description should be language-agnostic -> refering to
count_specMult(3, 200)
This comment has been hidden.
Approved. (+1)
Description should be language-agnostic
It is already, what's the point??
No, it isn't, refer top post for clarity
Ruby 3.0 should be enabled
Also, function and parameter name should be
snake_case
Python new test framework should be used
Done
JS NOde 14. should be enabled
Input constraints should be mentioned. How high does
n
go? (1e9) How many consecutive primes can we expect? (up to 10, looking at JS version)These are important pieces of information to tailor your algorithm to.
Approved by author secretly
This comment has been hidden.
Too late to enforce such changes
Interesting but the example is a little bit misleading : I thought I have to find numbers whose prime factors are ALL in the set of the first
N
primes...For example :
count_specMult(3, 210) = 7 as 210 = 2 * 3 * 5 * 7
but 7 is not in the first 3 primes.The real problem is much simpler than I thought.
I should have read this comment first. I waisted 30 minutes on this kata :)
The function name should be in snake_case in Python.
Done
no edge cases to enforce a proper solution (at leas python, ruby); the description says:
thus, add the following to all languages:
count_specMult(2, 12) == 1
solver fails for the above edge case (at least python, maybe others)
no random tests (python)
Performance KATA of the same as a suggestion.. thanks for the KATA BTW!
Not a suggestion...?
Very nice Kata! Interesting how smart and short the best solution is!
Glad you liked it! :)
I'm having the same problem with execution time(Process was terminated. It took longer than 6000ms to complete), althought I have 18 Passed 0 Failed 0 Errors and when simply running tests(not submiting) process takes about 50ms?!
Nevermind, I managed to solve it...
i'm getting this error...
Random Tests******* countSpecMult Tests n: 11 max: 125389642886 Expected: 0 Process was terminated. It took longer than 6000ms to complete 0 Passed 0 Failed 0 Errors
HI, EVEN I'M GETTING PROBLEM AS THIS CODE STOP EXECUTING AS EXECUTION TIME IS >6S.WHAT CAN BE SOLUTION FOR THIS? ALSO FOR GIVEN TEST CASE IT'S RUNNING ABSOLUTELY FINE.PLEASE TELL ME HOW TO OVER COME THIS? IT'S GIVING ERROR ON RANDOM TESTING WHEN N= 8 AND MAXVAL = 11728597661
Also when i'm executing code into VS , this is all running fine and showing result = 1209 for N= 8 AND MAXVAL = 11728597661. but in codewars since execution time > 6s, so not passing the test case due to high execution time , and then not allowing to submit the code.
this is the error i'm getting Random Tests******* countSpecMult Tests n: 11 max: 125389642886 Expected: 0 Process was terminated. It took longer than 6000ms to complete 0 Passed 0 Failed 0 Errors
This comment has been hidden.
My code seems to be running alright and I'm using memoization in order to speed it up. Nonetheless, I'm still not able to submit my solution under 6s seconds ("Run Test" goes pretty quickly though). What other ways should I go through?
You can send your code with spoiler and enclosed with backticks. Let's see!
This comment has been hidden.
HI, EVEN I'M GETTING PROBLEM AS THIS CODE STOP EXECUTING AS EXECUTION TIME IS >6S.WHAT CAN BE SOLUTION FOR THIS? ALSO FOR GIVEN TEST CASE IT'S RUNNING ABSOLUTELY FINE.
Pretty sure it must be mentioned that divisers are not only prime numbers but INCLUDE prime numbers - in that case solution is very simple.
This comment has been hidden.
Thanks for your comment and feedback.
Looking at the hard coded values for primes, which doesn't seem very programming-style to me, perhaps tests should be added for larger numbers as well.
Thanks for your suggestion. Your suggestion implies that a more efficient algorithm should be required. It would be good for a second part of this kata having optimization as a tag and a higher level of difficult, 4 or 5 kyu perhaps. Your suggestions are welcome.
C# version seems to have some issues (apart from no input test cases):
I'll message the author of this version in C#, thanks.
CountMultiples.CountSpecMult(int, long)
is your code. You should havepublic static long CountSpecMult(long n, long mxval)
(See "Your Solution"). I added some "Your Test Cases":-) I just tried the kata and don't see any problem. Three other guys have passed it in C#. Hope all will be fine for you too:-)That was the original solution I had. Indeed, changed it and works fine, thank you!
Maybe it is only me, but from the description it looks like you are looking for numbers that only contain the first n primes as factors. Unfortunately, the provided example also points in this direction (since the first counterexample would be 2x3x5x7=210>200). Granted, the second test case gives it away, but a more clear description could have saved me a lot of headache :)
Maybe I am miss-understanding the exercise as well, if the given results below have to be divisible by all prime numbers within n, then it is not correct! 200 is only divisible by 2 and 5 not 3.
===================================================================================== and the found numbers below 200 are 30 < 60 < 90 < 120 < 150 < 180 < 200 (6 numbers) =====================================================================================
I think this part is fine, because 200 is only there to emphasize the upper boundary. The rest, 30..180 are 6 numbers that qualify.
Typo
Below is spelled "bellow" in the description.
Fixed, thanks
Try to keep it simple. I tried with a neat object based solution at first, but time got me there. After thinking about primesmore it finnaly dawned on me:)
Sup, I think you should mention maximum count of primes in your tests. You can use memoization and sieve of eratosthenes for this type of tasks, but when you have only first 10 primes it's redundant.
Good one, upvoted!
Thanks a lot for your time solving this kata and for approving it, too.
This comment has been hidden.
NaMe613 did that version. I saw that you told to NaMe. I don't code in Ruby yet, but it's understandable.
I want him to have a chance to check it (I think my code is right, but I'm never 100% sure on problems like this). If we don't hear back from him in a couple of days, I think I can go in as a contributor and correct the issue.
Name613 is very active in CW. It would be good to wait to Monday.
I'll be working this night on my next kata.
Apologies for not having replied yet,
The reason you're getting these off-by-one errors is because your code doesn't take into consideration that the numbers must be below
maxVal
, with your current setup ifmaxVal
has the firstn
primes as factors you count it when you shouldn't.Thanks, and my apologies! I've marked the issue as resolved. As a point of information, the reference implementation for the Python version also produces 192588. So, the Python and Ruby versions are expecting different results.
I massively overthought this one and spent hours trying to get my solution fast enough. Then I had an epiphany, and it turned out to be ridiculously easy :)
You made me laugh. Sometimes we need some jokes, too. Good work!!
Ruby translation kumited.
Please see my post above. I think there may be a bug in your reference implementation.
I've replied.
Thanks a lot for your vigilance and message. It's solved. Your suggestions are wellcome.
The function name is not the same for the example tests as for the actual tests.