7 kyu

Count the Digit

1,209 of 49,793g964
Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • Doey Avatar

    Esoteric

  • Jihao_L Avatar

    yeah i have no clue of what is being asked

  • MikkelBJohansen Avatar

    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

  • Attarya Avatar

    The enunciation on this kata is...

  • younesabbasi1991 Avatar

    This comment has been hidden.

  • kaito__Kidd Avatar

    what the hell is this????

  • Vanja_Vici Avatar

    Excellent kata.

  • BrunoCharb Avatar

    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.

  • benhautmann Avatar

    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.

  • AxisByte Avatar

    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.

  • 631543791 Avatar

    This comment has been hidden.

  • kiko_camba Avatar

    my code is running perfecly in VS, but no here, I don't understand

  • p3yif102 Avatar

    #11bfn_42t

    excellent kata .

  • Angcruz831 Avatar

    yo these math questions are wack and confusing.

  • popcode Avatar

    Description makes it difficult to understand

  • Loxton Avatar

    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.

  • rsschool_e3c2f8a34437cd28 Avatar

    good kata, but need to read the task more than 10 times to understand it.

  • Victor Benedict Avatar

    This comment has been hidden.

  • Zero20072022 Avatar

    This comment has been hidden.

  • MrBalbesina Avatar

    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

  • haachico Avatar

    Nice kata, if understood correctly!

  • Raxxillion Avatar

    This comment has been hidden.

  • jimmythenouna Avatar

    This comment has been hidden.

  • yLaWy Avatar
  • rsschool_2ae7c0b867bae0ab Avatar

    Very pure discription!

  • muturi254 Avatar

    solved it after going through the discusion and realized there is a bit of info hidden, good kata

  • DevMonzer Avatar

    This kata has some bugs in random tests it keeps giving errors

  • neniak Avatar

    This is one of those where reading the question is the hardest part of the challenge. fun stuff

  • nayopaP Avatar

    This comment has been hidden.

  • Elrond95 Avatar

    This comment has been hidden.

  • Kacarott Avatar

    (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

  • cuadchris Avatar

    enjoyed this one; thanks!

  • pashaOrg Avatar

    enjoied this, good

  • KayleighWasTaken Avatar
  • adam2000phillips Avatar

    Enjoyed this kata, good job!

  • eb110 Avatar

    Clojure 7 kyu :-)))))))))))))))))))))))))))))))

  • IgorTheOverlord Avatar

    This comment has been hidden.

  • user3369223 Avatar

    This Kata is poorly described and not a 7 kyu puzzle

  • eilenart Avatar

    This comment has been hidden.

  • m_tofu Avatar

    Description is extremely confusing so I've rewritten it, hope this helps people in the future:

    You are given a number "n" (n >= 0) and a digit "d" (0 <= d <= 9).
    
    Write a function nbDig(n, d) that finds the square of each integer from 0 to n, and returns the number of times that the digit d appears across all the squares. Note that d might appear multiple times in a single square.
    
    Example:
    
    n=12, d=1
    Squares from 0 to n=12: 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144
    The function returns 7 because the digit d=1 appears 7 times: in 1, 16, 81, 100, 121 (note: 1 appears twice in 121), and 144.
    
    n=10, d=0
    Squares from 0 to n=10: 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
    The function returns 3 because the digit d=0 appears 3 times: in 0 and 100 (note: 0 appears twice in 100).
    
  • ullvang Avatar

    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)

  • madhaus Avatar

    This comment has been hidden.

  • druashley Avatar

    This comment has been hidden.

  • HendrikCromboom Avatar

    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.

  • Madjosz Avatar

    Improved JavaScript version upgraded to Node v14, use chai for assertions, added inputs to assertion messages

  • josue11221 Avatar

    decifrar este kata fue una tortura, pero aun asi fue un reto divertido xd

  • peiurdntymetcmedzntz Avatar

    This comment has been hidden.

  • laurelis24 Avatar

    This one was pain in the a**. It was hard to understand what to do.

  • akar-0 Avatar
  • SergeyFM Avatar

    I was tempted to go string-based way, but it is too inefficient.

  • scibuff Avatar

    This comment has been hidden.

  • Whoopalla Avatar

    This comment has been hidden.

  • Sarnak Avatar

    This comment has been hidden.

  • Coding_Deity420 Avatar

    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

  • SENSENEL Avatar

    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

  • B1ts Avatar
  • Coptain Avatar

    My counts are off by smalls amounts (e.g.: 1,3,4). What should I be considering my code?

  • Asurakun1 Avatar

    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?

  • Jaune9 Avatar

    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

  • Dezoway Avatar

    This comment has been hidden.

  • doremaxime Avatar

    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.

  • jan_winkler Avatar

    Maybe you could have mentioned in the instructions that this is a performance kata - could have saved us some time writing useless loops.

  • A9B9 Avatar

    The instruction is a littel miss leading

  • Shreyas Chopra Avatar

    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.

  • KaptainKris Avatar

    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.

  • Heathro Avatar

    that was nice. thanks for kata.

  • wilsonteh Avatar

    This comment has been hidden.

  • costagavras Avatar

    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.

  • papansarkar101 Avatar

    Terrible explanation.

  • vasilev-gregory Avatar

    This comment has been hidden.

  • zLuki Avatar

    Terrible example tests for debugging, but rest was nice kata.

  • Sergiu Pop Avatar

    This comment has been hidden.

  • lbrozado Avatar

    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... :/

  • theleewise Avatar

    This comment has been hidden.

  • LinhVNVN11 Avatar

    can someone please explain why it is 14,19 then 21 for the (25,1) example? thank you

  • eladio.feijoo Avatar

    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.

  • Hunahpu2 Avatar

    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.

  • gkontadakis Avatar

    This comment has been hidden.

  • Sapho Avatar

    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.

  • DavidFromNorth Avatar

    Very poor description...

  • aruiz Avatar

    In Rust (and any strongly typed language really) the digit should be unsigned

  • penguinsunited Avatar

    This comment has been hidden.

  • GoodNews970 Avatar

    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.

  • MarosMT Avatar

    Hi,

    Basic tests passed, but I have random tests error: Execution Timed Out (16000 ms)

    How can I solve this??

  • Cuk Avatar

    too many random test, it makes no sense

  • xdldal Avatar

    This comment has been hidden.

  • theMGI786 Avatar

    This comment has been hidden.

  • villesau Avatar

    This comment has been hidden.

  • user8436785 Avatar

    Dart and Groovy translations.

  • marcoazzurrini Avatar

    Ive attempted this kata multiple times, but I dont uderstand what I should do?

  • luix Avatar

    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.

  • Whateven Avatar

    execution time out =/

  • agusgambina Avatar

    This comment has been hidden.

  • CbHyBaM Avatar

    This comment has been hidden.

  • Julian42 Avatar

    Poorly written instruction, too many random tests.

  • aidil Avatar

    The instruction is almost exactly like how some clients explain how they want what they want. Took me a while to understand

  • willthestevens Avatar

    hello friends

  • oauo Avatar

    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 to n squared"

  • luca118 Avatar

    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 }

    ?

  • lecso2 Avatar

    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

  • CamiloCase Avatar

    This comment has been hidden.

  • meonu Avatar

    This comment has been hidden.

  • stepanovich Avatar

    This comment has been hidden.

  • sigmanphi Avatar

    This comment has been hidden.

  • glynester Avatar

    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."

  • soyu123 Avatar

    Cannot submit even though it's correct because of size of buffer(1.5 MiB)

    Why did you put high numbers that much big?

  • Arthur5233 Avatar

    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?

  • Paradox86 Avatar

    i wish i could submit my solution :/

  • monadius Avatar

    I forked and reviewed uniapi's NASM translation. Please approve my fork.

  • cyan4936 Avatar

    This comment has been hidden.

  • imago.dei Avatar

    Why not write the description in a language-agnostic way?

  • staticVoidMan Avatar

    Nice kata, Thanks :) I enjoyed reworking my solution to reduce execution time as much as I could... for now :P

  • user3409270 Avatar

    Poorly written kata description. I could not decipher what the kata was asking me to do.

  • user4676773 Avatar

    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.

  • preetamnahak007 Avatar

    This comment has been hidden.

  • MRQQ Avatar

    This comment has been hidden.

  • divij42 Avatar

    This comment has been hidden.

  • MainDuelo Avatar

    Java bug when running

    symbol: nbDig method (int, int) location: class CountDig

    runTest: passed

  • nonama Avatar

    Why n+1??

  • kurohyou5280 Avatar

    How many random tests are there? I'm timing out so just curious.

  • tangweikun Avatar

    This comment has been hidden.

  • user1958379 Avatar

    This kata should be 6kyu or 5 kyu.

  • ilgimdemirel Avatar

    This comment has been hidden.

  • codewaggon Avatar

    what's the meaning of k**2?

  • user9742082 Avatar

    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?

  • RolfzRybnika Avatar

    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. "

  • Aman seth Avatar

    why my code is showing error i m unabele to understand

  • jotronin Avatar

    This comment has been hidden.

  • AungMyoKyaw Avatar

    This comment has been hidden.

  • chivano Avatar

    In C++, there is no reason for this to be a class member function. Have the user declare a bare function.

  • cromorg Avatar

    This comment has been hidden.

  • CompMath Avatar

    This comment has been hidden.

  • Rauru Avatar

    This comment has been hidden.

  • Dvisacker Avatar

    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.

  • AntoineGagne Avatar

    This comment has been hidden.

  • Rikishu Avatar

    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

  • Kaneco Avatar

    really messy explanation, couldn't figure it out

  • Sankarshana Rao Avatar

    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."

  • differentrain Avatar

    This comment has been hidden.

  • Toderesa97 Avatar

    Not properly explained.

  • Mrityunjay Bhardwaj Avatar

    This comment has been hidden.

  • Mrityunjay Bhardwaj Avatar

    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.

  • Naomarik Avatar

    The examples seem to contradict each other, have no idea how to interpret these instructions.

  • sharifahmad Avatar

    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.

  • gabimaier Avatar

    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)

  • Goncalerta Avatar

    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.

  • SindhuMadhuri Avatar

    I've ran the tests but the answer is not getting submitted. What's to be done?

  • svenk Avatar

    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."

  • capttrousers Avatar

    This comment has been hidden.

  • coldshower Avatar

    In the second example in the instructions, I believe 0 and 25 need to be included. This can be confusing.

  • dthuesen Avatar

    This comment has been hidden.