7 kyu
Is n divisible by (...)?
3,262 of 7,937IVBakker
Loading description...
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.
The description should probably state that the divisors are non-zero.
What to do if a variable is not specified in a function?
You have to come up with the correct signature for the function yourself, that's part of the task.
I think it's hard for level 7
python new test framework is required. updated in this fork
Approved
Rust translation
Scala translation
Approved by someone
In java:
Why does it give me errors right before I even type anything?
It says,
"illegal start of type public static boolean isDivisible(...) { ^" Not to mention that this was how the code was when I started this kata.
I'm not sure if that's a problem or something.
Not a kata issue, you should replace the
...
with something that makes the function able to take an arbitrary number of arguments. It's like that in every language.This comment has been hidden.
Java is no different than other languages in this regard; part of the task is managing a variable number of inputs. So, the set up is correct.
i see we have different amount of arguments in the parameter, does that mean that the parameter is an array?
No.
How would I know what arguments were use in a method thru stack trace only? I'm having a hardtime about the stacktrace: expected but . Like how will I be able to debug this if all the arguments given returns the right result
CoffeeScript translation updated
Approved
the python version dosent have an argument for the function
It is like that in almost every language, part of the task is figuring out how to handle a random number of arguments.
A little typo in the description: "... checks if the first a[gr]ument n is divisible".
changed
Just returning true passes all the tests in C#, please fix.
Can you check now? I wasn't the author of the C# version and I'm a bit rusty on C#.
Fixed.
Although the code should still pass in most cases, line 1 of the description example code block has an extra and unnecessary trailing comma:
isDivisible(6,1,3,)--> true because 6 is divisible by 1 and 3
Thanks, typo removed
Don't have to change anything in C# for all tests to pass.
Can you check now? I wasn't the author of the C# version and I'm a bit rusty on C#.
I am just getting errors when submitting a previously working solution, although you can no longer pass it just by pressing submit like before. I am just learning so not sure if it is still pass-able :)
Whoops I shouldn't have submitted it. Did nothing.
I did absolutely nothing on the C# version and all tests passed. I did the attempt and all tests passed. I did not submit it obviously.
This comment has been hidden.
Hi,
This is Java and I'm not totally expert but from what I can see you are misunderstanding index and value.
Is other an index or a value?
when you say if(other == 0) continue it just skips that number and moves onto the next number so if all the other numbers are divisible it would return true when actually because one of the numbers was 0 it should return false since division by zero is not allowed. You may have already figured this out by now since this is 7 months later but try changing the continue to a return false and it should work.
This comment has been hidden.
Hi, try to understand the difference between: this kata and the kata here http://www.codewars.com/kata/is-n-divisible-by-x-and-y
The Java initial code both wrong syntax and wrong type for the given test data:
Wrong Syntax, wrong type:
public static boolean isDivisible(Double numbers...){
Right Syntax, wrong type:
public static boolean isDivisible(Double... numbers){
Right:
public static boolean isDivisible(int... numbers) {
Thanks I didn't notice that. I changed it to
public static boolean isDivisible(...) {
which gives some information but not too muchHow can you pass in arguments in the test cases but create a defaut function def is_visible() with no arguments? (Using python) _Are we supposed to be passing in a list?
This comment has been hidden.
Sorry I marked it as an issue and I do appreciate the help. Will mark as question in the future :)
This comment has been hidden.
This would make a good intro to JS arrow functions... they make the code really simple...
hmm in the test case...
what's the point of
*args[:]
?Isn't that the same as
*args
?I think whoever wrote that was intending to pass a copy of the list, instead of allowing manipulation on the list itself. I'm not sure it was really necessary here, though.
Shall the first argument be divible on sum of rest or on every each argument?
For what I know the first argument is divided by the rest of the argument seperately.
Typo -- agurment :)
Fixed, thanks
By "all other numbers", do you mean the sum of all other numbers, or all numbers one by one?
n by all others, so first argument vs all other argument not one by one (first example should be better to understand)
Kata greenlit :)
JS initial solution isn't even a function. The initial solution should at least have the correct syntax, e.g.
Oh, right, I forgot to fix that: done, thanks :)
This comment has been hidden.
@IVBakker: That's why I left the arguments in the list ;).
By the way, Haskell translation kumited.
But the previous version was without round brackets (or parentheses or however you call them in English), which would be anyway mandatory in defining a function, wouldn't they? And I doubt anyone who does not know about undetermined parameters already could figure it out seeing a half-made template.
Just my 0.02€ of course: the last word is of course yours here :)
isDivisible()
make more sense then, agree.Accepted Haskell translation, thanks a lot
And so I happened to stumble across this little good kata just before going to bed, to fall captivated by it, to complete it and while at it, to translate it into both Ruby and Python, still in case you may consider adding my work to your own here too :)
I may be seeing things as I start to feel sleepy, but I think I saw a familiar kind of code for testing it all. And it was a nice reading :)
Well, thanks for this one too :)
I had to fork because I re-wrote the description -.- Thanks a lot!
I fear that may have robbed me of about 30 honour points, but, oh, well :D! Worst case, you will have to upvote my solutions or comments 30 times to get even with karma :D
Jokes apart, next time I would first see for translations, then edit the description, as it seems to be a rather troublesome process and often it takes more than a trial to get the translation approved.
Oh, of course I would not mind forking my translation again myself, if you will ever need it again :)
Said from someone with
Honor:7512|Leader Position:#4
^^ Terribly sorry about that. Yes next time I would know, it was my first translation merge.I hope Leader Position would be #3 within the day ;)
But of course I got that far doing the honour Scrooge of this site, so atone +1ing every activity of mine :D
No, jokes apart, I am well aware that I am quite FAR from being as good as most (if not all) top rankers are: I am a mere amateur, but being able to compete with skilled and talented individual gave me much, as did giving myself the goal of becoming the top ranker even if I started as the least of the underdogs (a few months ago I had to Google in order to remember how to to for loops in JS, sigh...).
You're aware that Zozo is #3? That will take a while…
Yesterday I was like a point away from him and if I got some more honour I recently lost, I would probably be already there. Even so, I am glad I will have to sweat for that spot.
Not that it will ever make me remotely close to being the third best coder here, of course. Just an alluring milestone to put even more effort in my training :)
It is not very clear that the first given number is the test case. I at first assumed every n had to validate with every other n.
It took me a glance at the examples to understand what was being asked.
Seems pretty clear to me ("check if a number n is divisible by all OTHERS numbers", then you get examples down below): any suggestion to improve it or idea about where the ambigous parts are :)?
On first glance I figured "a number n" wasn't a specific n (as in "a number, n" or "the number n") but any of the given numbers. You'd ensure they all individually resolve with their respective "other" numbers.
It's definitely not something someone should get stuck on, but it confused at least one other person for a moment as well.
Coding is like driving, don't code and drink, that's dangerous. I re-wrote the description, if it was really necessary.
Forgive my ignorance, but when I use the given unit tests, mine is passing, but when I try to Submit it, it's failing some arbitrary tests.
Are these test outlined some place where I can actually test against them and try to figue out how my solution is failing, or is it more of a 'submit it until your code passes all tests' etc?
The proposed tests are a sample of what is submitted.
There is in the submitted version some random tests. So if it doesn't pass the first time it's not going to pass the 50th time. I suggest you to write your code not to try to beat my tests but to answer the problem. If your solution fail, print out the arguments passed and write other unit tests to see what's wrong in your solution.