7 kyu
Count the Digit
1,209 of 49,793g964
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.
Esoteric
Tasty
yeah i have no clue of what is being asked
same so i skip
Count the appearances of the digit
d
in the squares of all numbers from 0 ton
.as feedback: I think it would make sense to anchor this task to some real-world example (rather than it just being a glorified equation)..
I have no idea what was going on half the time
The enunciation on this kata is...
This comment has been hidden.
what would help?
it helps undrestand the question better? :/ and then you can find the solution easier and faster.
what do you mean "waht would help";
what the hell is this????
Agreed!
just square if number for 0 to n. Once you have done that, count the number of d that are in n and return that
Excellent kata.
I could not run the tests when solving this in Kotlin. The a in assert is missing (ssertEquals instead of assertEquals) which break the test. Solving was not an issue on the other hand.
Does this happens after you click TEST, or ATTEMPT? I cannot recreate your problem and tests look fine to me. If your problem happens after clicking TEST, I think that you accidentally modified sample tests. To fix the problem, click RESET under the trainer and see if this helps (remember to backup your code first!)
This is the first 7kyu Kata after like 50 I could not solve, I did not even start, bacause the goal of this Kata is to hard to understand, especially for a not native English speaker. Also those only math problems are lame.
Seconding what everyone else said, this description is confusing and unhelpful, especially for a 7-kyu problem. Provide more examples and make it more clear, please.
The most offensive line is "Count the number of digits
d
used in the writing of all thek**2
"Very unclear.
It should be written as "Count the number of occurrences of digit
d
in all squared values between 0 and n inclusive"Also, the phrase "Note that
121
has twice the digit 1"Is a little off, and should be written "Note that 1 appears twice in
121
"Is it necessary to write "Square all numbers
k (0 <= k <= n)
between 0 and n"when "Square all numbers between 0 and n inclusive" would suffice?
Specifying that digits fall between the range of 0 and 9 inclusive is redundant; using a base 10 digit system is implied.
Revised Problem Description:
Return the number of occurrences of digit 'd' in the set of squared numbers between 0 and n inclusive
Constraints: (0 <= n <= 1_000_000)
# NOTE: The problem theoretically includes infinitely large numbers. There should be a constraint for n other than n >= 0. Also, neither k nor d need to be specified as a range.
Revised Examples:
Lol it only made sense to me after I read your explanation. Thank you!
This comment has been hidden.
I don't know enough about R to answer your question, but it is a question, not a kata issue. For such posts, use question label :P And also don't forget to mark your post as spoiler (I did it for you this time).
Alternatively, you can also reply on the solutions page itself, but also mark your post as spoiler.
:-)
my code is running perfecly in VS, but no here, I don't understand
#11bfn_42t
excellent kata .
yo these math questions are wack and confusing.
Description makes it difficult to understand
The description of this kata needs work because it's unclear how k is determined, especially since it is not a parameter of the method.
good kata, but need to read the task more than 10 times to understand it.
This comment has been hidden.
ya, true. took me a while as well.
This comment has been hidden.
I've spent a lot of time trying to get handy lists of all the n*n's. And a list of digits where 'd' occurs. That's not what I should have done T_T
Nice kata, if understood correctly!
This comment has been hidden.
It says <= so both are included.
This comment has been hidden.
Python update (new testing framework)
Looks good to me, approved.
Very pure discription!
solved it after going through the discusion and realized there is a bit of info hidden, good kata
This kata has some bugs in random tests it keeps giving errors
No, there is no problem with the tests, and your current code works.
This is one of those where reading the question is the hardest part of the challenge. fun stuff
This comment has been hidden.
This comment has been hidden.
You are checking whether a string contains a character literal of
d
(which lies in the range of characters between 0 to 9, both inclusive, in the ASCII table). Instead, you should convertd
to an actual character or string representation for comparison.(Prolog) Random tests break if the user imports
clpfd
. This is due to the reference solution not properly sharing external variables in a lambda.Fix is here
Yes I had seen that in some of my kata at CW (not in my version of SWI-Prolog) but I didn't know the relation to "clpfd". Who needs "clpfd"?:-) I approved your translation, thanks!
I think it also happens with other modules. I think some modules cause terms to be compiled, which causes the error, but the bug was brought to my attention from a user trying to use clpfd :)
enjoyed this one; thanks!
Thanks!
enjoied this, good
Update to Scala 3
Approved by author secretly
Enjoyed this kata, good job!
Thanks!
Clojure 7 kyu :-)))))))))))))))))))))))))))))))
This comment has been hidden.
you're not supposed to call the function explicitly
you just need to return the answer from within the function, just printing it won't pass
;)
This comment has been hidden.
This comment has been hidden.
This Kata is poorly described and not a 7 kyu puzzle
I think the description is quite clear? It specified the range and all, and the solution involves basic loops (which is a 7 kyu descriptor I think). What would you like to add to the description for clarification?
This comment has been hidden.
You're not starting at 0.
Thank XoRMiAS, you were spot on. Fixed.
Description is extremely confusing so I've rewritten it, hope this helps people in the future:
there's not been a problem before, its highly unlikely that you've found something new
in the off chance that you have, publish a fork ;)
I'm not claiming to have "found something new," I'm just trying to help people understand the description. There are many comments from people who are confused by the wording.
Your description helped me understand this kata better. Thank you!
Oh, such a nice comment in here. God Bless you, warrior! Thank you!
Thanky you! I was approaching the problem as if it was just looking for the total number of results that contain d, not the total number of times d appears.
Thank you! So frustrating when a kata's most difficult challenge is its poor description.
Thank you. I finally know what I am supposed to code.
this description its way more understandable
I was confused by the question's description, then I saw this and solved it in less than 10 seconds.
Thanks for this clarification. Hopefully the description will be updated.
This description actually made me understand the Kata! Thank you so much! Solved!
Thank you!
the k*k that contain the digit 1 are:
1, 16, 81, 100, 121, 144, 169, 196, 361, 441. (Only 10 numbers here)
So there are 11 digits 1 for the squares of numbers between 0 and 25. (Counts it as 11, because 121 contains 1 two times)
kata hint != kata suggestion
This comment has been hidden.
really
This comment has been hidden.
Ran my csharp solution in a console app and got the correct result returned in far less then an actual second. Yet codewars seems to time out... Well yes I did go the string route, but that is barely going to affect anything in csharp to be fair.
Improved JavaScript version upgraded to Node v14, use
chai
for assertions, added inputs to assertion messagesApproved.
decifrar este kata fue una tortura, pero aun asi fue un reto divertido xd
This comment has been hidden.
Where are you returning anything?
o looooorrrd, im a goof ball.
thanks
This one was pain in the a**. It was hard to understand what to do.
word
COBOL translation.
Approved.
I was tempted to go string-based way, but it is too inefficient.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
my count is off by 1 what could be the reason. i am doing it in c++ and i cannot find the problem in my code
You are not taking d=0 into consideration, so in such test cases your count is off by 1.
That was so helpful, thanks!
Ok, first i was confused, read some replys here, thougth i understand it, i clicked Train and now confused again Did the permute (4kyu) Kata right before and felt now like for something more smooth and warming up ... uaahhaha
ok, what i realy miss in the description: it says "numbers of interest are ..." followed by a bunch of numbers; i thought, ok this numbers were given as array or something, square them from 0 to that first parameter int, right? Task is then the sum of occurance of that 2nd given parameter, so far so good (?)
Ok, now, after clicking Train: those "number of interest" arent given?! i have to calculate them out by myself within that first parameter? e.g. 5750? What is the condition to generate those numbers of interest? are they given blackboxed within the test? primes? unicorns? beavers?
sry, can somebody enlighten me? Thx
The numbers of interest are all the number between 0 and
n
which squared contain at least one digitd
. Is it clearer now? And no, they're not passed to you in any way, you have to get them for yourself.ahhh, now i can understand why somebody mentioned it in a comment as "it's actualy a performance test-alike" Kata
Ooook, thanks ... but, with where as you describe it, how does the author then come to these numbers which are just not consecutive 0 to n; I mean there are gaps between them; is his example in the description just inaccurate?
What i mean is this- he wrotes:
"nb_dig(25, 1): the numbers of interest are 1, 4, 9, 10, 11, 12, 13, 14, 19, 21 which squared are squared are 1, 16, 81, 100, 121, 144, 169, 196, 361, 441 ... etc"
When you write "numbers of interest are all the number between 0 and n" - there are numbers missing, there are gaps - all good, but i cant see the conition of those gaps?
Thanks again
OK - STOP - i see / understand now!
the mention of a possible / partly recursion would have been more helpful by the original author
Thank you!!
Prolog translation.
Approved.
My counts are off by smalls amounts (e.g.: 1,3,4). What should I be considering my code?
Google Python range.
Make sure you are including the very last value in your code. If you are loopin up to the last value then it will not include the last value in your solution
Sorry, but i can't understand what you're trying to ask for.
Are you asking for counting how many "similar digits" are in each square?
i don't understand how we go from "1, 4, 9" for squaring each iteration to "10, 11, 12, 13, 14, 19, 21" can someone explain this?
Those are the
k
which squared have at least a single digit1
.You have a number n(let's say 10) and you need to square all numbers from 0(including) to 10(including). 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 --> 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
Let's say that we want the digit '1'. In squared array we need to sum up all digits that are '1'. (Keep in mind that if we have, for example, squared number 121, that has two digits '1', then we are adding both of them to the final sum/counter). 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 --> 0, 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 1 = 4
I hope this helps. :)
I have the "5750, 0 -> Expected 4700, got 4699" issue, but the other test work fine. Would someone have a clue to share on why or how ? Edit : Occurs in Python
Happend to me as well, because I forgot to include - 0^2 - , so my counter did not count the first 0. Also make sure to count the upper-bound - n^2.
This comment has been hidden.
Make the instructions clearer. After a couple hours i had to unlock the solution because i didn't understand what was really being asked. Made less sense than my wife's bf.
Maybe you could have mentioned in the instructions that this is a performance kata - could have saved us some time writing useless loops.
Lots and lots of solutions have loops...
The instruction is a littel miss leading
You should explain why.
excatly!!!how does it feel?
this feeling of : what ???? what did i just read??? this is not your best kata
Kata was good! I just felt that nb(25,1) example caused a bit of confusion. I understand that its been stated 'numbers of interest', but it would be better if all the numbers would have listed and then counting no. of d from their squared forms.
My code passes the (12526, 1) test but counts 26 fewer digits than required for the (5750, 0) test, does anybody know why? I assume it's some special case with 0, but can't figure out what it could be. I can elaborate on my method if this would help.
Turns out it was because R was writing some numbers in exponential notation.
that was nice. thanks for kata.
This comment has been hidden.
If you still have troubles, try looking what the bounds are of the numbers that should be exponentiated
.
The descriptions to g964's katas are not for the fainthearted. The katas themselves, once you plow though the text, are good and quite fun.
Terrible explanation.
agreed
Yep, I came to the comments after looking at the question and example and wondering... what do they want?
This comment has been hidden.
More interesting thing is what you use for "making large string of all squares"? This part often trips newbies up, because often they do not know why the most obvious way is wrong.
https://stackoverflow.com/questions/1760757/how-to-efficiently-concatenate-strings-in-go
Terrible example tests for debugging, but rest was nice kata.
This comment has been hidden.
Don't be so hard on yourslef! There is a large variation in difficulty between katas on the same level. This is just because what is easy for some is hard for someone else because they are unaware of some module/function that does all the hard work (especially true in python). If you want, you can go to the kata list, sleect difficulty, and then sort by "most completed". This will show you the easier ones ;)
I will try like that, I just don't like to skip them :D, I would prefer to solve them when I start training on them
g964's katas often require a math solution or an algo with better time complexity to pass. Sometimes it is really difficult to find out that algo, if you haven't used it ever before, so sometimes it also needs a bit of research. The good thing is, once you used this algo you will always keep it in mind and you can improve all your programs in future.
And always keep in mind, your not a just getting better if you solve the kata you are also getting better if you just TRY solving the kata :) Good luck!
I had an issue with the first test ->dotest(5750, 0, 4700)<-, if I change it for ->dotest(5750, 0, 4699)<- it works perfectly and ALL the other tests pass as well... My code works just fine for the given examples on the description and on all the other tests too... :/
And how is your solution being wrong an issue?
This comment has been hidden.
can someone please explain why it is 14,19 then 21 for the (25,1) example? thank you
Because they're the only ones which their square contain the digit 1.
Respectfully, I never fully understood the description of the exercise. What I understood to begin with would solve the example for n = 10 and d = 1, but the answer was not made for n = 25 and d = 1. excuse the wording, I am using google translate.
Read again the description. For n = 25 and d = 1 the description says:
so the answer is 11. Moreover in "Sample tests" you have 4 examples:
You should try more 8 kyu kata and then little by little 7 kyu kata.
I tried understanding description for good 5 minutes but still nothing, either the person who created this is not very good at English or it is written in such convoluted way that it's hard to understand what is it that I have to do. Even example seems like gibberish to me.
Same
This comment has been hidden.
Someone updated the kata to Clang8C++17... I don't understand what happens now... Posted a bug report. Thanks!
A fix has been deployed at CW by @kazk.
Nice thx for reporting it :)
I can pass the standard test but not the randomtest du to a timeout.
my best average time is 2,7 sec (with multiple solutions) for the standard test and I can pass 21 maxrandom tests.
it's maybe hard to use code optimisation on 7 kyu.
It's not about code optimization, but about using the correct algorithm (don't mistake "using the correct time complexity" with "optimization" which suppose you're always keeping the same time complexity).
All in all, you need to find a better alogrithm, not to optimize your code.
EDIT: I just saw you use Shell. Don't forget to give that kind of indication in your message. Especially when it's a niche language like that x) )
This comment has been hidden.
Very poor description...
In Rust (and any strongly typed language really) the digit should be unsigned
The description says:
Storing a number d (0 <= d <= 9) in an i32 does not cause any problem. Moreover I will not change the signature of the function when 160 guys passed the Rust kata, I will be afraid that invalidates all solutions. Is it that which prevented you to pass?
It didn't but Rust is very picky about type conversions, u32 is what https://doc.rust-lang.org/std/char/fn.from_digit.html takes. You can cast with "as" but it is not ideal. If this causes problems to existing people who passed the test then I agree that we shouldn't change it.
Thanks for the link!
This comment has been hidden.
If you have passed you can have a look at the different solutions.
In R, scientific notation can sometimes yield incorrect answers for a few test cases, depending on how the result is derived; it might be worth adding as a note that scientific notation should be disabled in R. Thanks again.
you're a savior
Hi,
Basic tests passed, but I have random tests error: Execution Timed Out (16000 ms)
How can I solve this??
Either you're using recursion / looping infinitely, or your algorithm is very slow. I'd bet it's the first option, I'm passing JS tests in 2 secs with inefficient algorithm. Try to figure it out with sys-out printlns.
This comment has been hidden.
Mark your post as having spoiler content next time, please.
About your code, the range is wrong and why are you using that filter for? Those things are what makes your code so slow.
This comment has been hidden.
This comment has been hidden.
too many random test, it makes no sense
This comment has been hidden.
This comment has been hidden.
Try printing the input values, all those errors don't give information about which result is wrong without it.
This comment has been hidden.
Dart and Groovy translations.
I tried to approve the Dart translation but to no avail. Each time I click "Approve" nothing happens. Update: I fork it but same thing -> impossible to approve!
I
ve attempted this kata multiple times, but I don
t uderstand what I should do?is there any way that I can setup this on my vs code? I prefer to test in on my computer than on a broswer.
Thank you in advance.
Install Node JS on your computer and then run
node name_of_your_file.js
If you're JS guy - install Node and extenxion in Vs code named Quokka! Happy Coding :)
execution time out =/
This comment has been hidden.
In which language?
This comment has been hidden.
Your code is not doing that, hence the difference.
And I can't see Scala in the language selector, can you? If so, that's weird.
Thank you @Chrono79 my bad, I missunderstood the exercise.
No problem. Solved then.
This comment has been hidden.
Your code is failing one of the sample tests too, check that, and how you build you array, that'll help.
This comment has been hidden.
What's the first number in the array you build?
What's the value of d in the tests you're failing? You can use
console.log
to print the input values.This comment has been hidden.
Poorly written instruction, too many random tests.
The instruction is almost exactly like how some clients explain how they want what they want. Took me a while to understand
hello friends
That was horribly explained, the description should say something along the lines of "find the number of occurances of digit
d
in all numbers from 0 ton
squared"When you want to give lessons, write correctly: "occurances" should be "occurences"...
I am dyslexic and chrome didn't flag it, get over it.
No offense to the author, since g964 contributes quite a large number of kata to the website, but I've found this issue being the case in many of his kata descriptions. Usually the kata themselves are quite decent, but the way he explains it is frequently not clear. It sometimes can be a good idea to check the author's name, or find particular authors that like the style of. There's an insane volume of total kata on the website, so fortunately if you don't like the description of a particular kata, it's not hard to just do a different one instead.
At 4k honor, users unlock the ability to "coauthor" a kata. This allows things like description changes and approving translations, but based on the leaderboards, there's not a crazy amount of users with that much honor (there's only around 2700 people with more than 2k, which is my current honor amount). It seems that any older kata on the website just gets buried and forgotten about since there's not much incentive go back and make descriptions clearer.
You're 100% correct in that this kata could be a lot better explained, but that change will likely not happen. Usually the only changes made to existing non-beta kata are translations, or exploit fixes. My advise is to just do a different kata and hide an unclear one by clicking "train" and then exiting out. You can sort by "kata I have not trained on" to ensure every one of the challenges on the list are ones that you havent attempted before. Sorting by "most completed", "popularity", and "positive feedback" are also good methods to significantly improve the average quality. Don't feel like you'll run out of katas from skipping ones you dislike, there's plenty on the website.
Thank you!
Please let me know the explanation to this part:
nb_dig(25, 1): the numbers of interest are 1, 4, 9, 10, 11, 12, 13, 14, 19, 21 which squared are 1, 16, 81, 100, 121, 144, 169, 196, 361, 441 so there are 11 digits
1
for the squares of numbers between 0 and 25.if k is between 0 and n, I assume it should be:
rawK = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}
instead of:
rawK = {1, 4, 9, 10, 11, 12, 13, 14, 19, 21 }
?
0, 2, 3, etc. squared don't contain 1, that's why they weren't shown (they aren't numbers of interest there)
this: the numbers of interest are should be written as follow:
the numbers of interest are (the numbers from whole range from 0 to n, containg 1 as a digit)
it would be more clear.
In the second example (nb_dig(25, 1)) it should start with 0: 0, 1, 4, 9, 10, 11, 12, 13, 14, 19, 21 which squared are 0, 1, 16, 81, 100, 121, 144, 169, 196, 361, 441
No, because it's listing only the numbers of interest, not all k. As you can see, 0 squared doesn't contain 1.
This comment has been hidden.
.flat()
is still experimental And I get an error on.match
with your code because it is a String method, not an Array one.This comment has been hidden.
"My code doesn't work" is a question, not an issue ;-)
val >= 0
is not correct ;-)And there are other things you need to fix too.
ok thank you for replying
This comment has been hidden.
What is your problem?
the output iis always 0
This comment has been hidden.
Add this line to the sample tests
$this->revTest(nbDig(25, 1), 11);
and figure out what is wrong with it. There is no invalid input afaik, so your code should be fine without doing any input validation.This comment has been hidden.
This comment has been hidden.
Exactly.
I will repost someone's comment to save you having to scroll down to find it:
The clarity of the kata's description could be improved by giving it a real life example such as. "Bob is using a typewritter to type all the squares of numbers from 1 to n. Write a function which returns the number of times he hit a particular key from d (between 0-9) in order to complete his task."
It's the most concise description for this kata.
Cannot submit even though it's correct because of size of buffer(1.5 MiB)
Why did you put high numbers that much big?
I've tested my javascript solution to see if anyone changed the testing range and it worked just fine, maybe you're using a wrong data structure or writing a lot to the console? You could share your code marking the post as having spoiler content and using proper markdown
I have tried so many times to submit.I tried to put values on my local machine and it works(all answers are correct).On a computer i have Java 10 For example with number 5750 and digit 0 i could get 4700 on the computer but to submit i get 4699.How to solve it?
Same issue. All examples work on my local machine (in R) but are not passing the tests...
i wish i could submit my solution :/
No explanation. Not an issue.
Sorry, i mean, there is no submit button. Is that normal?
Not normal. You should have "RUN...", "ATTEMPT" and if your attempt is successful "SUBMIT".
Try changing your browser zoom level.
seems like changing from firefox to chrome solved
I forked and reviewed uniapi's NASM translation. Please approve my fork.
Approved, thanks!
This comment has been hidden.
Check your Split("") method , it doesn't return what you intend to get from it, for solving this Kata.
OP solved it, closing
Why not write the description in a language-agnostic way?
Nice kata, Thanks :) I enjoyed reworking my solution to reduce execution time as much as I could... for now :P
Poorly written kata description. I could not decipher what the kata was asking me to do.
Eventually you can come about the answer but I, like many others, feel like the description could be slightly clearer. Other than that, I did enjoy it.
This comment has been hidden.
No issue with the kata, your code is (very) bad. Useless module, useless global variable, wrong digit counting, no return statement (possibly other issues if you've run into EOF).
This comment has been hidden.
It's a limit on recursion, not a kata bug.
Thank for the info, I didn't know that.
This comment has been hidden.
n >= 0 , this might help
Java bug when running
symbol: nbDig method (int, int) location: class CountDig
runTest: passed
Why n+1??
How many random tests are there? I'm timing out so just curious.
Ruby? 111.
Disregard found a faster way to solve. Oh and there are 111.
Yeah I just finished a refactor. I was hitting 101 and timing out.
Thanks.
This comment has been hidden.
This kata should be 6kyu or 5 kyu.
no this is definitly a 7kyu in my opinion. It's rather easy or atleast in c++ it is. I don't think this contains enough depth to make it qualify as a 6kyu or 5kyu, though g964 discriptions aren't always the clearest :P
This comment has been hidden.
Not an issue, a question.
Your code has undefined behaviour which causes it to fail starting from
n = 8900
.This comment has been hidden.
what's the meaning of k**2?
**
usually denotes exponentiation, akak
to the power of2
.Doesn't k^2 denote exponentiation(to the power of 2)?
My code passes all the sample tests except this one (5750,0). The output of the code is 4700 but to me is 4699. Is it maybe a mistake in sample test?
Look at the top of the page: 1133 guys passed the Python kata so there is no mistake, sorry:-)
This comment has been hidden.
try to test with (0,0), my solution returns 1 and yours return 0, I think that is where the difference is, looking at your solution, for k values of zero, your while loop does not trigger, so the sum never generated eventhough d and k%10 are equal.
I can't pass the tests because of errors...
" Time: 0ms Passed: 1 Failed: 0 Errors: 1 Test Results: Build Output Test Suite test(CountDigTest) test1(CountDigTest) STDERR:
Max Buffer reached: Too much information has been written to stdout.
Signal:
Process exited prematurely with a SIGKILL signal. "
1,216 guys passed the java kata (see top of the page). Maybe you print to the console?
Your'e right! Sorry for that! Thanks for reply!
why my code is showing error i m unabele to understand
This comment has been hidden.
Don't post an issue when you want help, you make the author lose points. Post a question!
This comment has been hidden.
What happens when the squared number has more than one
d
? See the last example.In C++, there is no reason for this to be a class member function. Have the user declare a bare function.
Yes I know and for new katas I have changed my mind. Many C++ katas are written as classes...
This comment has been hidden.
This comment has been hidden.
check your for loops try adding one to n in the condition statement.
This comment has been hidden.
RIP, just ended copying and pasting another solution to make it pass, its a weird error if i try to substract just one from the answer it substracts 2 from the random answer. i will just try and solve it another time.
also if i use std::count instead of just manually counting with a loop i get one less than then answer, and manually adding 1 adds 2 to the answer.
This comment has been hidden.
OP solved it, closing
Having trouble getting the last test to pass correctly in C++. My code works good if the number is not too big but seems to fail otherwise. Any advice ? Maybe something linked to integers limits but that seems unprobable.
This comment has been hidden.
This kata until now had no problems (67 guys have passed), something at CW has been changed somewhere.... I corrected this kata replacing all "tabs" with "spaces". Now you could try, it works. I reported this bug at CW: https://github.com/Codewars/codewars.com/issues/new bug #700. Unfortunately I can't change all my Haskell katas this way! Thanks for your post!
The Haskell image did get updated but I can't reproduce. I've tried running the code provided here about 20 different times and every time it succeeds. Also the code isn't tabbed so thats odd.
@AntoineGagne are you still able to reproduce?
You can't reproduce on this kata because I have there replaced all tabs with spaces as you can read above! Before the update tabs were allowed. I thought Haskell was frozen.
C#:in examples: Test Results: NbDigTests test1 (1 Passed, 0 Failed) You have passed all tests! :)
but in suite: Process was terminated. It took longer than 12000ms to complete
It is not an issue of the kata, your code is not fast enough. Try to optimize it.
really messy explanation, couldn't figure it out
Hi g964, The clarity of the kata's description could be improved by giving it a real life example such as.
"Bob is using a typewritter to type all the squares of numbers from 1 to n. Write a function which returns the number of times he hit a particular key from d (between 0-9) in order to complete his task."
Good example; if I can re-publish the kata I will put that in the description. Thanks!
This comment has been hidden.
Not a kata suggestion~~
Not properly explained.
So could you explain what is not properly explained...
This comment has been hidden.
ERROR: /CountDigTest.java:34: error: cannot find symbol Log: ......
it looks like your Test file has errors.....Please fix it......I cant execute my code because of this.
381 guys passed the Java kata so I am pretty sure there are no errors.
sir, your test is looking for "nbDig" but in the java version of this test its "nb_dig"
So when I alter the test it works perfectly!
import static org.junit.Assert.*;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class CountDigTest { private static void testing(int actual, int expected) { assertEquals(expected, actual); } @Test public void test() { System.out.println("Fixed Tests nbDig"); testing(CountDig.nb_dig(5750, 0), 4699); testing(CountDig.nb_dig(11011, 2), 9481); testing(CountDig.nb_dig(12224, 8), 7733); testing(CountDig.nb_dig(11549, 1), 11905);
} }
You are mistaking somewhere. Here are the "Example test cases" in Java:
Ok sir i got the solution....... i just converted the pre-givin "nb_Dig" to nbDig and it solved everything..... Sorry for bothering you and yeah Thanks again for Making this KATA :D
Look, the pre-giving solution is:
There was no error in that!-)
The examples seem to contradict each other, have no idea how to interpret these instructions.
Could you give examples of these contradictions?
I do not understand the instructions either please clarify a little more please.
Ze-Marcos, you have to count from 0 to n, and square each number. As shown in the example if n = 10, then you do 0,1,2,3,4,5,6,7,8,9,10. Then you square each of this numbers so you'll get 0,1,4,9,16,25,36,49,64,81,100. Now, you have an integer "d" which is part of the test, and you want to find how many times this integer can be found in the result of squaring all those number. For this example, you can find that the numbers 1,16,81,100 contain the integer defined by d, thus the answer is 4. You also have to paid attention that if there is a number such as 111 the digit will count three times. I hope this clarifies rather than confuse even more.
I think the description of this kata is not well written. instead of " Count the numbers of digits d used in the writing of all the k2" this should be alot more descriptive: " Count the numbers of times digit d is used in the writing of all the k2 numbers" and i think the is also a little messy.
Thanks for your post, I will think about that but please let us note that almost 1000 guys passed:-).
@sharifahmad: I could see a bit of difference between your proposition and the description...
Please clarify in the instructions the maximum value of n we should expect. Anything greater than 46340 will have a square that doesn't fit into int and needs some care to be counted correctly. Even greater numbers will pose even more challenges. Ex: For n=46341, d=1 the expected count is 57995 (not 57993)
Please where did you find this number? Which language?
Oh, my bad. It's Java and 46340 < sqrt(Integer.MAX VALUE) < 46341
But you passed and you could see the max for
n
:-) which is far from 46340, no problem...I'm trying to do this kata using c++, but it gives this output:
nbDig_Tests Fixed_Tests No tests were provided Process took 18ms to complete
I believe this is a problem of the kata itself and not of my code.
This comment has been hidden.
It's a CW problem, the kata has a lot of tests. Report that at CW as a bug: https://www.codewars.com/topics/bug-reports.
I've ran the tests but the answer is not getting submitted. What's to be done?
Please which language?
The instructions are bordering on gibberish.
It could be:
"Create a function nbDig(int n, int d) which counts the number of occurences of the digit 'd' in the sequence of square numbers from 1 to n."
Yup it's a nice enough task but those instructions could be clearer. Thanks for your post though, I thought I was being a bit slow.
I actually didn't understood what I had to do until I read this. Thank you.
This comment has been hidden.
In the second example he only listed the k's whos squares contains the digits 1. k whos squares does not contain the digits 1 he omitted.
It was not useful to put numbers the squares of which contain no digit
1
.I also found the second example confused what was otherwise a clear understanding of what was required; obviously the opposite of what an example should do!
I feel it would be valuable to clarify that some unimportant numbers have been omitted from the second example for brevity.
In the second example in the instructions, I believe 0 and 25 need to be included. This can be confusing.
Slightly modified, thanks!
This comment has been hidden.
Please which language?
oh, sorry forgot to metion. Ruby.
This comment has been hidden.
ok, I'll try..Thanks alot.
This comment has been hidden.
I already used .count (step 6) but the other stept can go as you said. I'll try now.
When I launch test my prog run fine, but when I submit It says me "Max Buffer reached: Too much information has been written to stdout.", but i have 0 fail and 1 passed on summary. I use Java, anything can help me ?
N.B: Sorry, I have made a little mistake, good kata :)