8 kyu
Find numbers which are divisible by given number
20,071 of 43,797XxxX88
Loading description...
Arrays
Algorithms
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.
This comment has been hidden.
Not a kata suggestion. See https://docs.codewars.com/training/troubleshooting#post-discourse.
h
This comment has been hidden.
The test cases are not comprehensive, and some wrong code can also pass:
function divisibleBy(numbers, divisor){ return numbers.filter(i => numbers.includes(i / divisor)) }
This comment has been hidden.
This comment has been hidden.
the definition of the word indicates there's no remainder
Description should be language-agnostic
^^
Typescript translation (author inactive)
Forked && approved, thanks!
Julia translation
Crystal translation
Java Please help! Can't understand how can I return List or ArrayList? Cause I tried lots of variants and result is always like "incompatible types: Object cannot be converted to int" or you can't convert anything to int...
Or did I misunderstood the concept? All the ways are somehow to use objects... Or maybe I have to use somehow dinamic array?
See the function declaration:
Your function should return an array of integers, if your code uses a List, convert that to an array before returning.
All the variants I tried had the same result - "can't convert Integer to int", "Object cannot be converted to int" and so on... I understand that I have to convert but I have no idea how can I do it now/
Does this help: https://stackoverflow.com/questions/960431/how-to-convert-listinteger-to-int-in-java ?
yep ->Object[] cannot be converted to Integer[], the same was when I tried to convert to int in a few ways...
Well ok, but how do you guess (or know) that the top line of this code needs to be
import java.util.Arrays;????
apart from methods .filter(), .toArray(). A bit strong case for a 7kyu noobs, imho...
That's Java's problem :P You should know about these imports if you read some basic java tutorials.
In some other languages it's a lot easier of a task and on average it should be 8kyu.
You could also do it without it, click in view Solution from me to see how, but it is easier with the import.
Java need long to test but int when attempt :/
Just a note, the test cases did not catch when the divisor was zero (Python 3.6), I included a check for it, but when I ran it without one no error came up.
Fails testRandom No. 1 what is the problem?
Fixed.
Prolog translation kumited. (author is inactive)
Crystal translation Dart translation Factor translation Julia translation R translation
I want to ask whether the function should check for the duplicate dividends or not. E.g., if the numbers array is [2, 4, 4, 5] and the divisor is 2, then should the function return [2, 4] or [2, 4, 4] ? Can anyone clarify this doubt?
This comment has been hidden.
[2, 4, 4]
. OP solved it, closingRacket translation
PHP translation kumited 🙂
I don't see any test cases for JavaScript, i believe somthing is broken here.
No, you had to write you own tests, I've added some now.
Test cases have errors. Also, if the given list contains a zero that zero shouldn't be passed through to the returned list
Why not? Zero divided any number (except zero) is zero. Give examples of what you think is wrong, but I can't find anything wrong in the tests.
Not a kata issue then.
Come on!!! Something is broken here. I have submitted the same answer but received that Arrays class is missing error. Than I've tried different solution but List and other collections also not found!!!! When I opened answer and didn't earn any points: error: cannot find symbol return Arrays.stream(numbers) ^ symbol: variable Arrays
not an issue, a question :p (issue= problem in the kata / question=problem with your code. Considering the number of completions, the latter is way more than probable... ;) )
I bet you forgot the imports...
o_O I didn't know this. I thought that it is added by default.
This comment has been hidden.
In C++ the random tests are comparing what the user's function return against itself.
Fixed.
This comment has been hidden.
You're pushing the index, not the value. The sample tests are ok, I'm intrigued why your code passed the random tests.
Thank you. That explains the confusion I was having.
As for it passing the random test I have no idea. Not sure if it will now since I read your post above.
No, now that code won't pass anymore.
This comment has been hidden.
thank you guys, but by the moment i've received the answers, i've already done the kata.
Haskell translation
Bump.
i have written the code, but i don't know where to take the values from and how to print them out, or whatever to do, cause i'm a newbee. Please help..
You could test with some values like in the example [1, 2, 3, 4, 5, 6] for numbers and 2 for divisor.
I succeeded by removing all the code in the Test Driven Development, apparently here the Solution can work without that...
Yeah, that won't ever work. Because you can't remove the
Submit
Tests.Define a function in the
Solution
box.Run Sample Tests
will run the tests in theTDD
box on your code, supplying your function with arguments.Attempt
will run hidden tests ( which you can view after youSubmit
) on your code. If you pass,Attempt
will change intoSubmit
.Submit
and you get to see everybody's solutions ( and the tests, and - if you fork a solution -Preloaded
).( It helps if you mention which language you're using. Hopefully the above is generic enough. )
Happy coding! ^^
I think ValentinLevalet meant there are no sample tests for javascript, only the TDD skeleton (that should be completed to be useful). AFAIK AhtyTheCoder only used Python and has already solved this kata.
Fixed Elixir translation kumited -- please check and approve
for everyone having issues in java, change the return type of the method from 'long'[] to 'int'[] also change type of the input array to int too.
Fixed
java version is undoable
Fixed
Java translation has issues please fix.
Document it. What's the problem? Closing.
Feel free to raise a new documented issue.
There is a problem with method's return type.
Had to change the initial method from
to
for tests to pass.
10 months after newsh's post - same story. I noticed that the tests are like this:
assertTrue(Arrays.equals(new int[] {2,4,6}, EvenNumbers.divisibleBy(new int[] {1,2,3,4,5,6},2)));
Method input:
(int[], int)
Method output:int[];
There was no way to make it work with long values so I did the same as newsh did - I changed all "long" types to "int", to match my method with those tests.
However... Is it supposed to be a tricky one or is it a mistake? If it is supposed to be this way - maybe the description should mention that it contains an additional problem to solve?
Fixed
the type may be wrong
Solved but cannot submit. Testcases have errors!
given method return long[] but in testcase using int[], so it can not pass the testcase
Translated to c++
Approved
See the issue above, already resolved tho.
I think, the java version of this Kata has errors: Kata accept and return long[] arguments but in tests passed and expected int :(
Fehler !!!
In Kata we accept and return long[] arguments but in tests passed and expected int[] In java long a == long b accepted BUT long[] a != int[] b
The Java version should use Collections instead of Array which is the way current Java programs are written.
In Kata we accept and return long[] arguments but in tests passed and expected int[] In java long a == long b accepted BUT long[] a != int[] b
I has this problem too.
Fixed
The java version of this Kata needs to be fixed, it has errors.
C translation kumited!
Solution should test for something Expected: [3,6,9], instead got: [3,6,9] 0 Passed 1 Failed 0 Errors Process took 283ms to complete
What do you want here ?
CoffeeScript Translation Kumited! Plase acceptd :D
In Java header for the method takes long[] array and returns long[] array while all test cases are set for int[] input and output. Bit confusing, unless its part of the riddle.
Fixed
Could have more test cases in general but good to see that there is at least 1 random test :)
I don't get why my solutions is not working. As others pointed, test cases has int[] but the solution expects long[]. Pls help to resolve.
unKnown test Failer , seriously i can't find mistake in my code which make me question the test
this is not cool 0 error 1 failer , i seems like test sample has error some where.
It looks to be broke. No matter what your method returns, it's just returning: Test didn't pass: Unknown error
I have tried the function in plunker though and it appears to be working fine.
There are no default test cases. Thats the error you get when no tests are run. It will work when you submit. Or you can write your own tests
In method on entry is long, but in teston entry is int. Is it right?
Yeah that was funny , i don't know if it was a mistake or part of the task to figure that out @_@
For Java
In task used long[] numbers and long divisor, but in tests used int numbers. Is it right?
Javascript: There are no test cases
in java translation u put input params as long but in test provide int.. it's not a bugfix kata, so fix it plz =)
Typo:
"sould" --> should
Thanks :)
For java it doesn't seem to want to work no matter what I do. It was originally setup using Long values. The test cases input int values but won't test for int values. Presumably the actual submission test is the exact same because I just keep getting an unknown error even though I am answering this one perfectly.
That's because there is a type mistmatch between the solution section and the test section of the code. The solution section wants the paramemter types to be long, but the testing section is testing for ints. There must have been a mistake in the translation. After I fixed the type mismatch my solution worked.
I dont know how I would fix the type mismatch. This is basically a broken kata for java
Just change the input and return types of your solution from long[] to int[] and it will work.
They should fix it. :(
It's not exactly 8th kyu when it is broken like it is! They really should
agreed...
I have changed return type from long[] to int[] but still getting "Unknown error" message when clicking on submit button. Actually one test passed, but "Random" case for some reason not.
Can someone please fix this!
Fixed
This comment has been hidden.
Your solution only works for numbers 0-9
Semantics of naming is important to better understanding the code and readability of identifiers in various contexts, so I (but not only) think it's a good practice to create functions (and object methods) with verb-based names at least in JavaScript. In the current case "checkDivisibleBy" or "findDivisibleBy", for example. Thanks for the kata.
For java, the solution is set up to use long parameter types but the tests are actually passing in int. Might be confusing for newbies (unless that was part of the challenge?).
Fixed
Ruby translation submitted, if you want to approve it :)
Should have many more test cases, including edge and random cases: let me know if you might appreciate a hand in that.
Being somewhat new to programming, I can't even figure out what could be wrong with my solution when there aaren't any test cases shown. Just felt the need to comment. Maybe somebody could write a post about what to do when your code fails..for example, how to go about figuring out what could be wrong. I DO want to learn.
I would recommend to only start with katas with sample test cases; if the need arises, resubmit after you have added a few strategical
print
statements to get how your code is doing.Python translation kumited
May I suggest many more tests, with edge test cases and more random situations?
You are right. I added more random and some edge test cases. Thanks for the feedback.
Thanks to you for considering my opinion :)
C# translation kumited.
If you want to know how to approve translations, you'll find here more information.
Test cases would be nice! Each kata should provide at least one for a better understanding. Besides this, it's a nice filter-kata!
The number
0
is divisible by any number so if you put0
in your arraynumber
you have to put0
in your result so all your test with0
are wrong. Moreover you should have more random tests.You got that right!
I have added your fix, thank you for notice it.