6 kyu
Multiples of 3 or 5
136,391 of 444,264jhoffner
Loading description...
Mathematics
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.
Please use the spoiler tag when posting your code - all unspoilered comments are visible from the home page, so this will show up even if someone hadn't solved the kata.
thank you, i will do that next time, now it is already marked or how can i do that?
This comment has been hidden.
I could only think about for loop. Not the best solution but works, yay ;)
My javscriopt console.log(result); equals the answer but it marks it wrong. Why?
Your solution seems to pass now?
Yes, I didn't read the instructions correctly. my mistake.
how do i do this
Think of how you would do this (without a computer) and then code it
This comment has been hidden.
Your code error lies here, not a kata issue :-)
this is too easy for a six
Yet so many people solve it by iterating. I think the main problem there is the fact that the test cases aren't large enough to cause timeouts.
This comment has been hidden.
"my solution does not work" is not a kata issue.
See if this paragraph helps: https://docs.codewars.com/training/training-example#writing-a-solution
also, @theSultain
please do not post code or discuss method solutions without using the spoiler flag
I have since added the flag to your comment
Nice problem. Easy to implement solution.
Something's wrong. My code is giving me the correct values, but the system keeps marking them as "incorrect". What's going on?
the error feedback message says
expected undefined to equal 23
Which means your code should be returning 23, but it returns
undefined
because it doesn't return anything. To pass kata you need to return a value, not print it.So are you working with numbers in a list or am I trippin
This comment has been hidden.
big dady
This comment has been hidden.
There is a couple of problems with your solution, but two biggest ones are:
This comment has been hidden.
Not a kata suggestion. See https://docs.codewars.com/training/troubleshooting#post-discourse.
C: The tests for
Quadruple_Digit_Tests
are the same as theTriple_Digit_Tests
, they have 3 digits instead of 4.fixed in the editor, thanks
i have a problem, the page said me my code is very slow(12000ms) but when i test it on my pc its works fine like Tiempo de ejecuci├│n(execution time): 186 microsegundos(microseconds). I think its internet
s speed
. Somebody Can affirm this ?You have a typo in your code and it has an infinite loop. Not a kata issue.
no its not, the real problem was the a lot loops there is in my code. But my code pass all tests without any problem except the last. Because, one the test is a random test like a number of 5 figures when my code try to solve it, is when the time begins. But thanks i resolve it, i eliminate some innecesary lines and works now
Yes it was the problem, you had the same var name in both loops conditions RomperCondicion5 (or 3, can't remember and you've changed your code now), but you had different var names inside, RomperCondicion3 and RomperCondicion5. So, instead of exiting the loop, it was running until it timed out because the changes you made to one var didn't affect the other. Well, that's a good reason to keep your code dry (dry = don't repeat yourself). Read this please: https://docs.codewars.com/training/troubleshooting
This comment has been hidden.
how i can save this kata¿
You can add it into collection --> read more info here
Thanks
bruh, I can't do this :/
233168
Why 16 should return 60? or what am I missing because if I just calculate multiples of 3 before 16: 3 6 9 12 15
it gives me 45
and multiples of 5 before 16
5 10 15
gives 30
and 45+30 is 75
You counted 15 twice.
thx!
This comment has been hidden.
Don't write a main method here, see the initial code and fill it in:
Read this: https://docs.codewars.com/training/training-example#writing-a-solution
Not a kata issue.
Shouldn't the description say something about the size of values being tested, so that one knows that something quicker than the straightforward approach is needed?
NO random tests in Groovy
Also in Java, and probably other languages...
my code is working and giving correct output on my vs code but when i am entering the same code here its gives error and wrong output??????????????????????????????????????????????????????????
Yes, this happens when code is wrong.
I would gladly take a look at your code. Also this code doesnt work if you register the increments in a console.log,aparently it breaks the console due to lack of space.
Did you make sure to keep the name of the function the same? When the test case is run it will call the the function "solution".
hi so... i just joined but i dont know what to do can anyone help?
You can start by reading docs, for example this introductory article: https://docs.codewars.com/training/training-example or you can visit CW Discord server and its
#beginners
channel.I tested it in pycharm everything is written right, but this tester is not working, reutrning some import error
...but your solution seems to pass all tests?
If you still have problems, we cannot tell what is wrong with your solution without seeing your code.
Ive noticed you are a mod,you should put a warning the code doesnt work on the attempts if you are registering your incrementations in the log due to lack of space, thanks in advance!
This comment has been hidden.
Not a kata suggestion. See https://docs.codewars.com/training/troubleshooting#post-discourse.
This is novice level?
Do you think it is harder or easier than novice level?
let me know if someone wants help, i would be happy to offer my help :)
Seriously, needing help with giving help is not a kata issue.
you'r right, i am new on this software but for me the best way to learn effective is to explain it to someone. so That was the reason...
я бы хотел, что бы мне объяснили озы, я смотрю в код и вижу обычные цыфры, понимания вообще нету даже на 1 %
For small test case, it says input 3 = 0... 3 is still multiple of 3.
Please pay attention to the description. Not a kata issue.
Still don't think the description is clear.
After "If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.", one line with "10 is not added since it is passed in number." will be more clear.
This comment has been hidden.
See this article how to use code formatting.
See if this article explains what you are doing wrong (it does, but maybe not in a direct enough way).
If you cannot get the challenge to work, the best way to get help would be to visit the
#help-solve
channel of Codewars Discord server.It is very bad reward structure when the shortest code shown at the top of the list is O(n) when there is a O(1) solution that is not much more code.
You can upvote other solutions that you believe are better or more performant to push it to the top!
Resolved since this is not an issue about the kata description / test structure.
Marking this task as 7 kyu makes more sense to me, I visited a lot of 7 kyu tasks lately and the difficulty is very similar, whereas the vast majority of the 6 kyu tasks are harder than this.
This comment has been hidden.
Despite being categorized as a 6kyu-level challenge, the task at hand appears to be relatively straightforward, requiring a level of proficiency that aligns with the lower end of the difficulty spectrum for coding exercises. Stay Hard
I'd say it would be an actual 6 kyu if it required you to do it in O(1)
Help me!!!!!!!!!!
Error: expected undefined to equal 23 :(
I have a console log,but its not working :(
Edit 2 min later: the "return" was missing :)
What does 'below the number passed in' mean at the end of this instruction?
"Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in."
TIA! :D
That if your function receives a 10 as input, then your function should return the sum of multiples of 3 or 5 until 9 inclusive.
Thank you so much for the clarification!
so easy for 6kyu
yup agree
Why is fizzbazz considered 6kyu?
It was an old kata and re-ranking it is not possible for now due to old DB setup, but it is already planned and will be done by community maintainers in the future!
I dont like most part of Codewars's exercises, 'cause it doesn't have clear instructions. I suggest that the exercises has instructions that really give the main idea of the tasks ang give good examples too.
Agree with u, even asked gpt for completly understand what i need to do
RISCV Translation
I used replit to test code before implementing for an attempt/test here. I received multiple fails on the attempt, when I looked it would say something like expected +0 and 10 to be 23, code was exactly the same in both places, yet on Replit my solutions were the exact same value as was expected. So I have no idea whatt i'm doing wrong here.
I'd add to the description a warning that big numbers can be used in the tests. I tried solving it with recursions but that throws RangeError: Maximum call stack size exceeded while for most numbers it would work, if you're not using over 10000 in size
Seems pretty straightforward that big numbers are being used.
Is it normal at 6kyu to have performance issues?
I am a beginner and was really happy, that I managed a 6kyu for the first time, but there was one test not passing because of performance issues. I only could finish with the help of GPT.
Yes, for yellow kata it is nothing unusual to expect a solution of some specific complexity class. Many yellow kata still accept solutions of poor complexity, but there are many which have stricter requirements.
Having said that, this particular kata has no special requirements, and slow solutions should still pass. Of your solution was timing out, it either had a bug and fell into an infinite loop, or was exceptionally slow ;)
OP solved it, closing
This comment has been hidden.
Don't use global vars, they keep their value between tests, not a kata issue.
This comment has been hidden.
Some of the solutions I'm seeing from collegues, they don't check if the number is less than 0. Is that right?
I think for most solutions using a loop, if you start the loop above 0, it never checks for values below 0.
natural numbers
cool how my function works as expected in VS Code but its failing here... ?
Please read the error message:
A const value can be assigned only once.
Cant thank you enough Chrono, I was going bald from this question. its always the little things.
...and remember what Chrono teaches us; error messages can be your best debugging friends!
...secondarily, keep in mind that your VSCode probably does not have all the same tests / cases that this site will have, so it will almost certainly be invalid if it doesn't match. The phrase "but it works on my machine" comes up rather often, but as equally often, it proves futile for the reason provided.
expected:<23> but was:<33>
????
Please read the description again, there is an example there.
This comment has been hidden.
With this (no-)formatting, I can't even tell what language is this.
Please see this paragraph how to format code blocks properly.
Totally BELOW. Never equivalent.
This comment has been hidden.
This comment has been hidden.
Numbers below 10, but not including 10
i am not understanding it want to return the negative values even it only wanted to get the sum of the numbers that are divisible by 3 and 5 and that's 33165.
Nice!
instructions didnt say anything about negative values. Obviously if you include those the solution of every input has to be negative infinity. I think you dont need to mention it in general, but it tests for a negative value explicitly, so you have to make assumptions.
In what language?
VB, does the description differ in the languages?
It should not differ, but sometimes it can. This kata used to have some bad note about negative numbers and I tried to make it clearer, but forgot to include VB.
I added the paragraph in VB, but I think I just need to finish adding negative numbers to all languages and make the paragraph about negative inputs not a conditional one.
or just remove the test for negative number. In think in that case you dont need an explanation. You return 0 anyways in that case, so nothing to gain from it
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Hi Mango22. I see you are a newcomer, so welcome. First of all, please don't raise an issue when you see your code is not working. Issues are for demostrated flaws in the kata design. You may rather ask a question. Secondly, please use format tags when you post code somewhere, or it is very discomfortable to read, as explained there: https://docs.codewars.com/references/markdown/#code-block
You are using
my_list
as a global variable. In general you should be very cautious when using global variable, they can be useful in determinated cases but they are not reinitialized at each function call, that's why the result will be correct the first time, but incorrect then. You must define your output list inside the function, so you get a new empty list each time a new input is provided, to avoid this.Hey, thanks for the patience (and explaining the basics of this site). EDIT: solved it, thanks!!!!
Nice. Also note you could have identified the bug in your code by printing intermediate values, using
print
.Too easy for 6 kyu
most of the solutions use loops, this one can be done without loop. Probably some test for very large number with time limit should be added.
looks nice tho
This comment has been hidden.
Not a kata issue, please read this: https://docs.codewars.com/training/training-example
Things you should fix in your code:
Also read this: https://docs.codewars.com/training/troubleshooting
This comment has been hidden.
Please read the error message:
That's a problem with your code, not a kata issue. Use
Question
label next time.Oh I apologize for the misuse, I will pay attention next time, it's my first time using this tool. Thank you for helping me out !
Easy +1
Too easy for 6 kyu, isn't it?
C Fork
Approved
This comment has been hidden.
This comment has been hidden.
.
This comment has been hidden.
It's a problem your code. You need to return, not print. See https://docs.codewars.com/training/troubleshooting/#.print-vs-return.
Seeing you're new to codewars, I also recommend reading the following article: https://docs.codewars.com/training/training-example.
This comment has been hidden.
for me it said that i was wrong in the practise where n = 3 and n = 8: i got 0 and 14 respectively, if you got the same, just try and atempt it as that is what i did
Why can I not use a Set here?
test expected:<23> but was:<233168> Stack Trace
Whats this? i checked my code with answers and ig its correct?
Your solution is not correct, it works only for number = 1000. What if number is 100? or 42? or 100000?
This comment has been hidden.
Below the number, 10 is the number, so 10 can't be one of those multiples.
This comment has been hidden.
This comment has been hidden.
.
This comment has been hidden.
Function's name should be
solution
, notsoluction
, fix that and your code will work.This comment has been hidden.
Return the result, not print it.
i have completed the code and i got the output too, now what should i do ?
Delete main method from your code.
can ypu plese tell me the algo that youve used
This comment has been hidden.
Don't post solutions in Discourse please.
This comment has been hidden.
Use the function's argument to get the input value, not input(). Also, mark your post as having spoiler content next time, please.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
because if you have number<0 you need return 0. Why are you check if i < 0: in your loop?
Too easy for kyu 6
This comment has been hidden.
You forgot this.
Thank you, forgot the age old rule to always read the full question.
you are counting 15 twice, so 75-15 = 60 is the correct answer
sir you have included 15 twice
This comment has been hidden.
Please see if this article helps: https://docs.codewars.com/training/training-example#writing-a-solution
Really fun one :)
This comment has been hidden.
Knowing your code would greatly help to find your mistake.
This comment has been hidden.
Having the code properly formatted would greatly help too.
This comment has been hidden.
Your solution has a small bug. You need to read the description again, and pay attention to details.
Your solution is not exactly correct (but it's close), it's not a kata issue.
thank you for helping!
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting#post-discourse
Remove the first line, you don't use
input()
here, use the function's argument. Also, read this: https://docs.codewars.com/training/troubleshooting#expected-the-samebe careful with instructions, i needed to read it four or Five times to get my solution work as expected
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
read the instructions carefully, start with the given exemple then try to make a program that do the same :)
This was quite easy. feels good after solving it.
Basically fizzbuzz in another format
Remember!: If the number is a multiple of both 3 and 5, only count it once.
it's a pity that there's only one color in the description
I tried to use a do {command} while (condition) thing but event the easiest already breaks the algorythm
i don't really understand the instruction. can someone enlightnen me?. thank you
Mine was complex but I took out all numbers that fit the conditions, put them in an array and i took the sum of the numbers in the array.
use set() that will only take the unique number. because we don't want the number's that are both multiples of 3 and 5.
So in a fit of rage I deleted everything and closed out the tab but when I tried to go go back I couldn't undo my deletion what do I do
There is None unless you had a file on your pc, in wich case you can use recovery tools like Recoverit - Data Recovery
DO NOT leave console log, when you attempt. It shows error, because of a full buffer.
This comment has been hidden.
This comment has been hidden.
Not a kata suggestion, please make all those comments in your solution if you want, but here, the kata should be solved on your own.
i have a problem. i write a function to do this named 'sumMult' and i declare "n" and at the end of the code i set sumMult(n), but i can't pass that. how should i complete i complete this? the code is ok and i test it in vscode. im new here plz help thanks. i use javascript i get this error: "ReferenceError: solution is not defined at Context. (test.js:22:18) at process.processImmediate (node:internal/timers:471:21)"
Use the initial code:
The function's name should be
solution
, notsumMult
. So rename your function and if it's ok, it should work. Btw, it's not ok.Instructions say that it returns the sum of all the multiples of 3 or 5 below the number passed in". The number passed in was 20, so it shouldn't be added, right? But the answer expected me to sum it.
Which language are you saying that happens? That isn't happening neither in TypeScript nor in Java, that are the two languages you worked on.
Facing a problem:"random cases: n=78439 - STDERR - Execution Timed Out (12000 ms)". Any help with this big numbers?
Don't use nested loops.
Ok, thanks bro.
This comment has been hidden.
I only know c++, so forgive me if I'm wrong, but as far as I know the operator
+=
is shorthand for= number +
, so your line equalscount = count +;
which gives a compile error.You should replace the line to
count++;
if you want to add 1 orcount+=(another number);
Now I should note that the number is already given as a parameter so you don't really need to ask for it again.
i do not think its is 6 kyu, looks like 7.
My scala code passes all the tests expect when n=100000 since answer is too large to be displayed as an integer. Can someone explain how you're supposed to return an integer that is too large to be returned?
I have the same issue, can anyone help?
Edit - I figured it out, you need to make sure your counter variable is of type Long
Hi! How is this problem solved with the local compiler?
EOFError: EOF when reading a line
This often means you're missing a closing bracket
Hi, bro! Reset the code and noticed that it was necessary to write code in the function, not enter values through the input and output the answer, not print. Everything went well!
This comment has been hidden.
why is this problem 6kyu? it's a simple fizzbuzz variation
It is one of the oldest katas on the site, back from March 2013 - the rating system was more generous back then (and still being adjusted I guess also).
ah, i see. thank you for the explanation
Python 3.10 - Times out after first test
Issues are for problems with the kata, not problems with your code. It sounds like your code is too slow, or perhaps gets caught in some kind of loop. You can post your code here (make sure to mark it as a Spoiler) if you want help debugging it.
This comment has been hidden.
This task good for level 8 but not 6.
The test is not checking the NEGATIVE inputs. It should be fixed.
The most popular code in answers is wrong.
Please mention the language when reporting an issue. If it was Swift, it doesn't have random tests either.
Yeah, right, it was Swift. Thank you for comment
Added some fixed tests with negative values in Swift. There is an open issue about the lack of random tests below, so closing this one.
Same in R, if I'm not mistaken.
This comment has been hidden.
This comment has been hidden.
error CS0305: Using the generic type 'List' requires 1 type arguments. whats wrong? in visual studio work but here not
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting#post-discourse
About your problem:
The sum, not the count.
Thank you it worked
I encountered some problems. (C#) When i used int local variable in method, everything worked well. But when i initialized static int field in class (instead of variable in method), I've got problems with some tests(with inputs 20 / 200). Problem itself: out of nowhere to my summ on return was added 23, no matter how i changed my loops i always got additional 23, this problem was occured only on CW, while in VS everything went fine(right answers without addtion). What's root of problem. How static field affect result?
Your tests most probably would not work correctly in your local VS either. It will most probably fail if you run two test cases at once in your local VS.
Yep, probably. I thought about separate start of programm, if it's few calls of method in a row, then it's reasonable.
Thx, bro.
The outputs I got were incorrect if n = 75, how can the sum be 60? same goes for n=93, sum = 78 and n = 10308 and, sum = 9168.
Edit: the outputs are different from the sample tests for some reason
You're misreading the logs:
n is 16, and 75 is your wrong answer. 60 is the right answer. Not a kata issue, please read this: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
You're printing your output instead of returning it.
Appreciated. This helped me in my later submissions as well, and general understanding of writing functions. Thank you!
I love how this kata made me learn so much about ways to add the elements in an array and get rid of duplicates in an array, thank you sensei @jhoffner
I dont know why I am getting an ImportError. my code runs fine but its saying "cannot import solution from solution" im so confused.
In all Codewars katas your returned code/function needs to have the same name as what appears in the Preloaded code.
In this case - confusingly - the kata wants you to return a function called
solution
; you have changed the name tosumAP
andsumMultiples
.Renamed your function
sumMultiples
tosolution
and it should workthank you
I love this kata! It can be solved in so many ways! I suggest you try the following:
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
definitely not 6 kyu, it's way more easier than some 8 kyu
This comment has been hidden.
This comment has been hidden.
missing test case for:
Additionally, if the number is negative, return 0
Missing in which language?
Elixir
There was already a single test for that, added another one, and expanded the random range.
This comment has been hidden.
First of all, welcome to Codewars.
In general, if you want help it's best to state which language you are working in (so people can double check your code and/or the tests in the various versions of the kata).
As for your query - there is indeed a test with
n=200 -> correct answer = 9168
so it seems that maybe you are reading the error messages incorrectly?As a new user, make sure you read this useful page completely:
Troubleshooting Codewars - see especially the section on "Error messages, printing your input/output".
If you see
"...but returned 0"
this normally means (depending on language, hence my comment earlier) that it is your code that is returning 0.If you want to hard-code this, to debug, try writing:
if N = 200 return 9168
- this will let you know if the tests are working OK in your language.It should be 8 kyu instead 6 kyu
It's one of the oldest katas on the site so ranking/difficulty grading is a bit out of date.
Besides, if you think it is too easy; why not try to solve it in O(1) rather than your O(n) solution which times out for inputs ~
100,000,000
?8 kyu and I can't complete this task :\
this was hard for me as a beginner, took me like 5 hours to figure out
This comment has been hidden.
This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/133.
Please join the discussion to help us identify duplicate kata and retire them.
This kata was decided to stay.
I do not really understand the instruction. We are given a list of the natural numbers below 10. Why do we need to check for anything negative? And why the attempt suggests that the result of the calculation must be 78?
P.s.: I have submitted it, but I think that the Instruction must say that we have a list of natural elements below "number". And I still do not understand what it was with negative numbers.
You are not given a list of natural numbers, you are given a single number - the "upper limit" for you to consider.
If the upper limit is 10, for example, then you need to find which natural numbers below 10 are multiples of 3 or 5: as stated in description, these are 3,5,6,9.
The reason you check for "anything negative" is that if the input number is negative, then there are no natural numbers smaller than it, so the answer is
0
.The "result of the calculation" you are looking at, is for 1 specific test: with input value of
20
the correct answer is indeed78
because the sum of all natural numbers less than20
that are multiples of 3 or 5 is:3+5+6+9+10+12+15+18 = 78
I still do not understand why the result of calculation is 78, in the task the number equals 10, not 20. Explain please.
if the input is 10, the function should return 23
if the input is 20, the function should return 78
So it is saying 6 should = 8... 6 is comprised of 3, 5, and 6, which total 14. What am I missing here?
Firstly make sure you are interpreting error message correctly:
x should equal y
in python tests mean that you are returning x and the correct answer is y.Also, based on quickly reading your solution, make sure you read description:
"...sum of all the multiples of 3 or 5 below the number passed in..."
My mistake, I missed the crucial part of the instructions where it says to sum the numbers that are less than the input. Got it now, thanks!
@coreymccue no worries!
It's a very common little mistake, especially when the
input/output
specs of katas are written in plain english rather than using precise symbols like<
vs<=
.Welcome to Codewars by the way, and best wishes on your coding journey (by the way, you may be interested in the Codewars Discord - link in the sidebar on the left - where you can ask questions and generally get help quicker as you're starting out).
Passed the test, but programm doesn't check the latest number. First used for i in range(number + 1) but system didn't let me go. Some tests matched, some - not, so it gave me a clue that something wrong with the cycle ranges.
I am getting crasy. I have attempted my code so many times without success. I wrote all my variables in the function body and it works.
Your code worked.
This comment has been hidden.
16 = 60? not 75?
OP left the building... closing
This comment has been hidden.
Use proper indentation, your
return total
is inside your loop. Read this: https://docs.codewars.com/training/troubleshooting/ please.D translation
Approved!
This comment has been hidden.
Rust fork
Approved
C# fork
Approved.
What's the problem here my output is right in all tests but i get this Should return 3 for n=4 Log 3 None should equal 3
In Python the error message format is like this:
what_you_returned
should equalwhat_the_actual_correct_answer_is
So in this case,
None
should equal3
, means that you are returningNone
and the correct answer is3
.If you get the correct answer on your PC, maybe check that you are actually
returning
your answer rather than just printing it?thank you I used print instead of return
This comment has been hidden.
This comment has been hidden.
Logical and is
&&
, not&
. Your code is too slow, don't create arrays.You're counting them twice.
Thank you very much!!! I got it :)
Hi! maybe I misunderstand the condition?
Note: If the number is a multiple of both 3 and 5, only count it once.
But how can it be if all the tests pass and the last one does not?
I add only 1 element to the general list which is a multiple of 3 and 5
I can't figure out what the error is, help!!!!!
Should return 9168 for n=200 7818 should equal 9168
This is, at most, a question, certainly not an issue (= a problem in the kata itself).
and what to do then?
Debug your code, you're not understanding what to do:
That doesn't mean you count 0 and 15 and discard all other multiples of 3 and 5, it means you don't count 15 once for 3 and once for 5, that's what it means.
What happens is that the tests stop as soon as your function returns an incorrect answer.
The test cases dicourage efficient code. The original problem asked us to calculate for the number 1000, while the highest test case is 200. I think timeouts should be implemented and more extreme tests given. For example, my solution can get a result of 1890045000 from an input of 90000, in almost the same time as a low number. Going any higher gives the risk of breaking the ceiling of a signed Int32 (which can be be fixed by changing to an unsigned int32, or even an Uint64 hahaha).
Changing the test cases to a higher value will encourage mathematical thinking and efficient coding habits. This would also have to be reflected in the explanatation for the problem. I am new to codewars, so I don't know if there is some sort of "bonus points" system, which would fit this perfectly.
This kata is old, has been solved a huge amount of times, and changing its design in the sense of your suggestion would invalidate most of the submitted solutions, and actually would make it a completely different kata. This is not going to happen. Howerver, there exists a good amount of more challenging katas relative to arithmetics and divisibility for those who are interested in it..
And to answer to your last question: No, there are no bonus points here. The tests don't analyze your code; they just control your answer (I think this would just be practically impossible).
for python, it's too easy for a 6kyu, it should be 8kyu for py
Ranks are shared across languages and cannot be changed. It's not useful to complain about that, just enjoy the cheap points.
I think the developer programe is cracked
This comment has been hidden.
This is not a kata suggestion, it's a recipe for solution, please don't post this in Discourse.
Thank you. oops I got it
This comment has been hidden.
Please don't post solutions to katas without using the Spoiler flag below the text box - everyone can see your answer on frontpage.
Also, no need to post your solutions on Discussion page; you can use the Solutions page to comment on your & other peoples' solutions.
Finally please if you want people to read your code in future, use Markdown to format your code otherwise it is unreadable - read the documentation here to learn how to do this:
How to format code in markdown on codewars
This comment has been hidden.
Please use a spoiler flag when you post code, so that users who didn´t solve the kata cannot see it; I put the flag on for you this time. Also use markdown tags to format your code or it's not usable. Refer to the documentation about this and more: https://docs.codewars.com/training/troubleshooting/#post-discourse
&
and^
operators probably don't do not what you think, refer to the documentation of your language.Too easy to be 6 kyu...
This comment has been hidden.
Please don't post solution code in the discourse without marking it as a
Spoiler
.You are printing the result. You should be returning it.
This comment has been hidden.
Please use a spoiler flag when you post code, so that users who didn´t solve the kata cannot see it; I put the flag for you this time. Also use markdown tags to format your code or it's not usable. You can refer to the documentation about this and a more general help: https://docs.codewars.com/training/troubleshooting/#post-discourse
You must
return
the result, not print it to the console, it's the same in all katas.I get this error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 134217736 bytes) in /home/codewarrior/run.php on line 10
I only have a for loop in line 10 where I add some numbers to an array. how can it be so big? php, im on mobile
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
why do i get this "The expression (solution(10)) == ((23)) is false." even though log output is 23 in C programming
Read this: https://docs.codewars.com/training/troubleshooting#expected-the-same
Your function always returns 0.
Not a kata issue.
This comment has been hidden.
The note got removed for languages which have no tests for negative numbers.
This comment has been hidden.
Had a solution in my IDE with no problems. Copy pasted and passed all but one test saying "0 matches 23" or something along those lines.
Left this site, came back, retried, and passed all tests with exact same solution.
Very cool.
This comment has been hidden.
You need to return the result, not print. Also, please format your code when posting or it's unusable: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
Hi. Please use markdown tags to format your code or it's not very usable, as explained there: https://docs.codewars.com/training/troubleshooting/#post-discourse
You need a 'return' statement at the end of your code. Right now you are only returning a result if n is negative. If n is positive you aren't returning anything so output is undefined.
This comment has been hidden.
It's very ambiguous that C# has almost nothing to test then you submit your solution.
OP left the building... closing
This comment has been hidden.
Your solution will recurse up to 100000 times with some tests in the test suite. This is too much for codewars' node.js stack size. I'm not sure what it is in bytes, but I set up a recursive function that increments a single value and then calls itself and then prints that value upon an exception. With this function, it seems codewars' stack size will allow 15630 recursive calls (at least for my test function) before throwing an exception. I think you'll have to find a non-recursive solution, or at least a solution that doesn't recurse so deeply.
Thank you so much BobtheLantern! I was able to solve it with this advice. I saw someone else had asked a similar question so I'm trying to delete my question to reduce redundancy but I can't figure out how to do it. (I'm new to this site)
also I thought I posted this in questions, Sorry about that!!
I wouldn't worry about it, the discussion page is at least partly for asking questions. I don't think it's possible to delete a comment once someone has replied to it, besides now that this chain is at the top of the discussion page, someone else with the same question won't have to go searching for an answer.
This comment has been hidden.
interesting to see all the different ways to do this
simple ariphmetics :)
Sample tests Should return 3 for n=4 Log 3 None should equal 3 Completed in 0.01ms
help please
Same here =(
Please see this bullet point : https://docs.codewars.com/training/troubleshooting/#.print-vs-return
I found the solution and I wanted to write it but they beat me ;) thanks!
I had difficulty to understand the question at first. until I read the hint as "varaiation from FizzFuzz" from other comment.
"Unexpected exception raised": is this supposed to happen, no matter whether my code is right or wrong?
I think this happens only when your code is wrong.
"Unexpected exception raised": is this supposed to happen, no matter whether my code is right or wrong?
No, it's unexpected.
too easy for 6 kyu...it's 8 kyu
I agree.
(maybe 7kyu, but not 6kyu)
This comment has been hidden.
3 important things:
About all this, and more, I strongly advice you to read carefully the documentation: https://docs.codewars.com/training/troubleshooting/
Also: don't post several times for the same thing. You posted an identical message just below. Please delete it if you can.
ok thanks will do. very new to all this and wasnt aware i posted in the wrong place.
This comment has been hidden.
This comment has been hidden.
multiverse
How do i deal whit this?
'EOFError: EOF when reading a line'
Make your code end correctly.
Don't use
input()
it worked, thaks =)
This comment has been hidden.
This comment has been hidden.
This probably means you return 93 while the correct answer is 78.
but when I click on test it shows: You have passed all of the tests! first error show up when I click on attempt button. I confused finallt its write or wrong :|
add a negative number check. In other words try the function with -10 or something.
Most languages already do. And better for those that don't, since it doesn't bring any value to the task.
honestly i disagree, error checking should be part of any programmer's arsenal, this exactly how security bugs are found. and the lack of such a check has resulted in almost all answers not relating to such a case.
We're not making arsenals here, we must write a program to do a task. Input validation has been done in many old katas and is now considered a bad practice for the reason I mentionned. Checking the input is a negative number is 8 kyu kata level. It's of course interesting to know how to do that, but mixing this with a totally independent task like finding multiples of a number doesn't bring any value, in real context it'd be better to handle input validation separately from the main algorithm.
In the problem function(10)=23, but in the test the result must be 55. Useless instruccions
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
you need to put the 'return sum' inside your function
@Trapyy: Please use a spoiler flag when you post code in a comment (I put the flag for you this time).
@Trapyy I've got it, thank you
@akar-0 sorry, wont happen again
When I click test my code works, I hit attempt and then theres a 12 second wait and then it says that my code took to long to run so it didnt do it. My code isn't that complicated, just a for loop that runs as many times as the input so I dont get why this is happening. Does anyone know what to do if this happens?
you need to rethink your algorithm
are you sure you're program is O(n) time complexity?
Maybe it's because an infinite loop has been produced
I fixed it aparaently the problem was a != if statement, wich was fixed by replacing it with >. Idk why the not equal didnt work and made an inifte loop but its fixed now.
where do i put my awnser?
when you train on a kata, you have 3 boxes visible on the screen. the left box has the description and the output of the program. the right middle box has your code editor. the bottom right box has the sample tests
you can see this for more details
It says you should only return 0 if negatives aren't supported in your respective language but if you return the sum of the negative multiples of 3 or 5, it gives an error.
That's not what it says, it says if there are negative numbers in the tests in your language, return 0.
why my code work in my comiler and don't work in the website.this website don't give me sample input and sample output to test .bad website i will continue in codeforces
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I think it is a bit to easy for 6 kyu
assert_eq!(solution(-1), 0);
Why does this not test negative numbers?
your language possibly doesn't have them
This comment has been hidden.
yeah
Why don't you add more example test cases ?
you can add/edit/remove example test cases yourself based on examples that you want to try
note that this is only local and does not affect the kata itself
i can code. i just don understand the task...
a piece of piss for 6kyu;
Is your solution's time complexity is O(1)?
yeah my solution is satisfy the O(n) time complexity with O(1) space complexity by using 1 loop and 1 variable
Time complexity of your solution is not O(1), it's linear (i.e. O(n)).
This was kind of easy, a variation on FizzBuzz
good kata for beginners, there are many ways to solve it
This comment has been hidden.
This comment has been hidden.
The first paragraph of the task kinda brings confusion and is unnecessary imo
is there any error in this question, i ducble checked it for the vaue of 23 and the answer supposed to be 119 but its saying 70
You are probably reading the feedback off-by-one. The log appears above the test result.
COBOL translation (new framework)
Approved
This comment has been hidden.
If you mean
conio.h
then its not installed on Codewars, but you also do not need it. What would you need it for? Your solution should not interact with console in any way.No random tests in C++
There's random tests in C++, you must have select wrong language
This comment has been hidden.
You can see other solutions in Solutions section, please, don't post solutions in Discourse. About your question, yes, there is.
This comment has been hidden.
I don't get it, it doesn't give an error that I failed to get a multiple, it says "Max Buffer Size Reached (1.5 MiB)".
If you're filling a huge array or printing too much to the console, or have some infinite loop, that's your code's problem, not a kata issue.
Please read this: https://docs.codewars.com/training/troubleshooting
i wrote the correct code, it works well in the ide of my pc,But when i test code here it says my code returns 11 instead of 8 when the input is 6, but my code returns 8 for input 6 when i tested it on my pc, whats the problem here ?????