8 kyu
Count by X
56,814 of 151,382shums16
Loading description...
Arrays
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.
This comment has been hidden.
This comment has been hidden.
Interesting kata, but I can't understand why it should fit into level 8 kyu. It is certainly unnecessarily off-putting when beginners come across it. Possibly as a first kata, as has already happened according to the comments. And we're talking about commenters here who have stuck with it and not dropped out. :-( Can the level be changed? The kata would be good there.
Maybe some languages are less suited to this problem, but for C, it is definitely a beginner exercise.
This comment has been hidden.
First thing first, don't change the function's name, the tests will look for
count_by
.This comment has been hidden.
I was not expecting to learn this much about Arrays in a level 8 SQL kata...
cool cool
Poorly explained, 7kyu question.
real.
Все очень просто, x умножить на номер итеррации
ah yes
what a bad explanation
yuh.
Should be 7 kyu.
you think so?
This comment has been hidden.
ok did it!
Im stuck on the loop can anyone help me out!
sorry :)
The reg name is rsi not esi, thanks for wasting 1hr of my time wondering why my asm code did not work.
While submitting SQL solution I got (on attempt) errors several times, then eventually these errors were gone and I was able to submit. Seems not is ok here.
This comment has been hidden.
This comment has been hidden.
oh on second thought - my code works for what I thought I was solving.. but I think I misinterpreted the problem.
The examples given support my first concept of what I was trying to solve so it threw me off. I finally completed this kata and it is simple, just very easy to go off course if you are like me and try to come to a conclusion early :)
This comment has been hidden.
You are not returning anything back to the caller, read this on how to write solutions on Codewars
Godness
this is my first question I solved on my own on codewars, feels great. I'll never forget this 😭. Good luck to all
goodluck xD
This comment has been hidden.
This comment has been hidden.
you are expected to simply
return
the value itself; not try to useprint
Thanks for the help, appreciate it.
This comment has been hidden.
This comment has been hidden.
Not sure why so many people didn't like the language. "Create a function with two arguments that will return an array of the first n multiples of x" alone seemed enough.
It was hard for an 8, though!
This comment has been hidden.
What do you think is missing in the description? As far as I can see, all you need is written there.
The first line of the directions alone proivides a clear description of what is expected. Anyway, no response from OP; closing.
This comment has been hidden.
This comment has been hidden.
It works for me, please mark your post as having spoiler content next time and use markdown formatting as stated here: https://docs.codewars.com/training/troubleshooting#post-discourse
oopps so sorry about that, i'll ensure I do that from now on
This comment has been hidden.
Hey, your solution is correct, however you need to return the data instead of printing it to the console. (Use return statement instead of print)
This was my first slightly challenging kata. I actually had to do some research, so I learned something!
This comment has been hidden.
Your code returns teh result of calling
range
which amounts to animmutable iterable
. Instead, you need to return alist
type.This comment has been hidden.
Please use the spoiler flag and appropriate formatting when posting code. See https://docs.codewars.com/training/troubleshooting/#post-discourse.
Your function is printing the output instead of returning. See https://docs.codewars.com/training/troubleshooting/#.print-vs-return.
Seeing you're new to codewars, I also recommend reading https://docs.codewars.com/training/training-example.
Language Translation to Portuguese-Brazil:
Crie uma função com dois argumentos que retorne um array que multiplique n por múltiplos de x.
Assuma que os dois números da função serão números positivos maiores que 0.
Retorne os resultados como um array ou list (dependendo da linguagem).
Exemplos
count_by(1,10) #deverá retornar [1,2,3,4,5,6,7,8,9,10] count_by(2,5) #deverá retornar [2,4,6,8,10]
not a kata suggestion. Users can translate using their own tools or just learn English :)
Well at least to me the instructions were unclear
My answer was the exact same as the tests but it was showing error, pretty sure i've done it right.
Not sure what you did, (forfeit the kata?), because your solution code is identical to the top rated solution, which of course passes the kata... but your account shows you've only passed one other kata.
¯\_(ツ)_/¯
I tried my solution a few times and it didnt work so i got the top solution to see and worked just fine. I guess my answer was not proper but the results were the same for both codes =)
False. If your code had worked correctly, then you would have passed the kata without error, and you would not have made any comment in the first place.
Idk how it works, because in the test screen my answer was the same as the requested one. The test request was like [2, 4, 6, 8, 10], [100, 200, 300, 400 ,500] etc, and right above my solution was the same so idk?
yeah, clearly is NOT possible that it was the same as a correctly working solution
you're just not being logical, I mean look at this statement:
that just makes no sense
Without your code we can only guess, was your code returning the answer or was just printing it to the console? Read this: https://docs.codewars.com/training/troubleshooting/
It was probably printing, now i see why it didnt work, thanks for the help
This is my first time use codewar. Any suggets what should i do next?
start with fundamentals and 8kyu problems, and then do rank-up questions.
it wasnt clear to me at first that the memory was already allocated lol
I use += instead of multiple lol
This comment has been hidden.
This comment has been hidden.
not a kata issue
This is my very first submission that I figured out 100% by myself, awesome feeling!
same, this is my first time use codewar. Any suggets what should i do next?
me too lol
Nice kata :D
harder than the usual 8 kyu, but really good problem imo, forced me to think
This comment has been hidden.
Printing is not the same thing as returning. You're returning the output of
console.log
which is alwaysundefined
. That's why the assertion message isexpected undefined to deeply equal <expectedValue>
. This message indicates that your function returnedundefined
when it should have returned<expectedValue>
.I see my problem now. Thank you for the help!
I solved this kata very fast, but i can't explane how my code works. :)
Array index must start with 0 not 1...
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
realized I needed to swap n and x lol. also setting i to x was the wrong move, was only thinking of the first test case
No way this is 8kyu...
This is, in fact, an 8 kyu kata but even if it wasn't, ranks can't be changed so please don't raise issues if you don't agree with the rank of a kata.
This comment has been hidden.
This comment has been hidden.
Please don't post solutions in Discourse.
I'm new to "let" and i see that the code is set up with it, so i just wonder... what should go there, the final array, the "result" array ?
Yes, you can use z to hold the resulting array, you can also delete it and write your code inside the function too if you want.
Thanks for quick reply!
Nice Kata, thanks ! 🐺
This comment has been hidden.
Solution hint != kata suggestion
ok (^^)
This comment has been hidden.
this is the hardest 8kyu problem
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting. What is
b
, what isl
?thank you for the link, found my mistake!
This comment has been hidden.
This comment has been hidden.
LC translation
this translation modifies the description
Approved
This comment has been hidden.
This comment has been hidden.
i don't really get the instruction :/
Me nether, I don't even know how to go about this...
Describing tasks is not an easy task :-) So, when you do not understand it, check the examples:
count_by(1,10) #should return [1,2,3,4,5,6,7,8,9,10] count_by(2,5) #should return [2,4,6,8,10]
and try to figure out how the results were calculated.
C Translation
Rust fork of pending translation
Author of kata inactive Author of orginal translation inactive this month
Approved
Go translation
D translation
im getting "Array does not match: expected [ 2, 4 ] to deeply equal [ 2, 4, 6, 8, 10 ]", but when i copy paste the exact same code im actually getting "[ 2, 4, 6, 8, 10 ]", pretty confused
Nice kata!
yeah, there is an error in description, two arguments should be swap in description.
How that?
n
andx
refer to the variables provided in the initial code with the same names. This is correct (please note this kata has been solved more than 38,000 times, it is really unlikely the description is wrong and nobody noticed it before)..
If you click through to actually try to solve you'll see it is correct.
I'm not sure there is actually a way to word it in the reverse.
But compare their examples to the function and arguments given, and you'll see it matches the instructions.
kata is broken (Python) everything is working in VS Code.( I spent 2 hours, realizing it(
No, it's not:
Kata works perfectly in Python and over 11000 completions prove it.
This link might help you: https://docs.codewars.com/training/troubleshooting
Anyone else think this should be a 7 kyu instead of 8 kyu?
Please don't mind about that. This is really not significant and kyus of approved katas won't be changed but in very exceptionnal cases.
yeah no need to change it, am just curious as to what other people thought
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Please, in JS, use let instead of var, specially having in mind that an 8 kyu kata is intended for beginners.
fixed
Great work but I think its should be another Kata. Maybe 7 or 6
wow, this was actually a bit harder than i tought...
Please, NASM Translation
Approved
Java translation
Julia translation
R translation
(author inactive)
Approved
First banch of tests works good, then press "ATTEMPT" and get this:
Fixed.
Wow that was quick! Hah Thanks! :)
This comment has been hidden.
This is fixed.
The racket description is incorrect, one of the examples is
(count-by 1 10) ; returns '(1 2 3 4 5)
, it should be(count-by 1 10) ; returns '(1 2 3 4 5 6 7 8 9 10)
This is fixed.
This anybody here gus?
This comment has been hidden.
The instructions are very clear, you receive two numbers x and n, you have to return an array (or list depending the language) with the first n multiples of x. See the examples in the description, with x = 1 and n = 10, you return this:
[1,2,3,4,5,6,7,8,9,10]
the first 10 multiples of 1. And so on. I'm not sure what is it that confuses you, so, if you still don't get it, try to elaborate about what you don't understand.My solution is correct, but codewars is saying I am wrong
There is no problem with Python, your code must be wrong, are you printing or returning the result?
Thank you for the advice, I was printing instead of returning. That also solves past Kata problems I had. I am curious as to why return is correct and print would be incorrect?
Because if you see the tests, what's checked is the returned value of your function. If you only print the value, your function will return the default value of
None
.This comment has been hidden.
It's a problem with your code.
Check your loop.
C++ Translation
Julia translation TypeScript translation
TS forked and approved to update to latest version ^^
Dart translation Which ever 2 get approved last will have a merge conflict :trollface:
(Crystal already had a conflict with Groovy.)
Racket translation
Thank you!
Crystal translation
Please enable latest version of Python
Done.
Shell translation is available.
Lua translation is availalbe.
FWIW, instead of saying
a list of length (n) with multiples of (x)
it might be more specific and clear to saya list of the first (n) multiples of (x)
same
done
This comment has been hidden.
Check out the list of solutions to see what the most popular and/or creative solutions are. There are some easier ways of solving this one.
Pls enable Python 3
Done.
Solidity translation added.
description was quite unclear.
Funny)))
C translation kumited. :)
PHP translation added.
Forked to add PHP example.
I completed and tested my code using the same arguments they would use to get the desired results and they pass the test on repl.it bit not omn codeWars. Is anyone else having this issue?
I keep getting this error when I try to submit an answer
TypeError: 'NoneType' object is not iterable
but the solution I provided runs perfectly well in PyCharm without errors
No details... You probably returned
None
.Inexplicably breaks for me on random tests. Copied and pasted: Random Tests ReferenceError: k is not defined at Object.Test.describe
I just tested this and it seems to be working fine. I would go back and give your code another once over.
Good luck!
This comment has been hidden.
The last expression is
puts ...
, it returnsnil
.Why mix Int and Integer in the types? I think they should both be the same.
I'm not sure what "types" you are referring to. Can you be more specific?
In the Haskell version of the problem, you use both Int and Integer:
countBy :: Integer -> Int -> [Integer]
I didn't build the Haskell vesion of this kata. I will attempt to reach out to the creator since Haskell is very literally a different language to me.
This comment has been hidden.
Try to run it again. It's possible you were getting a time out error because of a Codewars server problem.
This comment has been hidden.
First, I don't think your script will work as it is written. You are going to need to make some changes there but I'm not going to give it away since that defeats the purpose of this site. You also are missing something important the directions asked you to do.
I find it helps to use console.log() to monitor what your script is doing at various stages. This will help you troubleshoot where the problems might be coming from. Once you get a working solution you can remove the console.log() references to clean up the script.
not a clear description
Is there a particular area that is confusing? Do you have a suggestion for an improvement?
I was also confused by the description, ignored it, looked at the test cases and then solved the kata.
Suggestion:
Length of output: n
Fill output with [1x, 2x, 3x, (...), nx]
If you think that would be too short: http://www.joelonsoftware.com/uibook/chapters/fog0000000062.html
Description could be clearer with full examples.
I have added another example in the description. Hopefully that helps.
A nice little exercise. A minor problem: you seem to be repeating the whole description twice?
I removed the repeated text.
Cool.
Nice 1-minute kata; I have translated it into Ruby for you to add as a viable language (if you never did it, you will see the available translation pressing the "+" button in the header, to the right of the other languages' icons) as a token of my appreciation :)
Thanks for the tip!
My pleasure :)
Any luck approving the kata translation, provided you are ok with it?
It's great but I'm not sure how to approve the translation. I'm seeing it as an option but I'm not seeing anything like an approve option anywhere.
What's the process for approving this?
Not sure not being the creator myself, but - worst case - you could just edit your kata copy&pasting my work in the relevant parts; otherwise, if you give me permission, I can do this myself.
Translation added and I took the liberty to put some random test in the JS version too; I hope it is ok with you and thanks again for your work :)
Thank you for the extra work!
My pleasure again and now we have a much smoother kata sailing safely along its beta process :)
The kata would benefit from an example in the kata description (it could be one of the test examples).
You could also add line breaks to make the description easier to read.
In addition, indentation in the provided code is not correct and it is a good practice to add semicolons at the end of lines.
Thank you very much for the feedback. This is my first kata and I appreciate the advice. I have cleared up everything you outlined and republished.
Note: I keep getting a time out error when updating this. I'll get the changes pushed out once I can get a connection.