4 kyu

How many numbers III?

2,235 of 4,514raulbc777
Description
Loading description...
Fundamentals
Data Structures
Algorithms
Mathematics
Logic
  • Please sign in or sign up to leave a comment.
  • Egor318 Avatar

    Отличное Ката, я в восторге, было сложно, но интересно решать данную задачу. Автору огромное спасибо.

  • KayleighWasTaken Avatar
  • KayleighWasTaken Avatar
  • natan Avatar

    JS update

    • description: 2x there're -> there are
    • node 8 -> node 18 (this cleans up assertion messages which were converting to json and escaping quotes, this is the reason I'm forking)
    • fix nested it (it inside it) - this was causing them to show up red even when the overall thing passed, and is probably not allowed at all when using a real test framework anyway
    • some editing on the test code but the logic is untouched
  • NpkkSoldier Avatar

    Expected: '[8, '118', '334']', instead got: '[8, 118, 334]' I should return an array, but here the test wants a string instead of it. Please, check it.

  • Program1ng Avatar

    in cpp version code works fine locally on my visual studio and gives the right output while when i do test or attempt it gives wrong output on the site

    Example Error: Expected: equal to (1, 999, 999) Actual: (1, 118, 999)

    While it gives (1, 999, 999) on my visual studio all error like this on the site when i tried it on my visual studio it gives the EXPECTED CORRECTLY!

  • brodiemark Avatar
  • juni000 Avatar

    Great kata, 2 days to complete it and have to learn more about recursive.

  • Owltooth Avatar

    I didn't like it and I wish bad morning to the author

  • SS-Stefanov1 Avatar

    For anyone that's having trouble with this one, research how to use backtracking and recursion! :)

  • ejini战神 Avatar
    • JS (mocha + chai) should be enabled

    • assert.deepEqual should be used

    • The output should be BigInt instead of String for min and max (invalidating solutions for the sake of consistency is much better than bad output type)

  • ejini战神 Avatar

    Features of the random tests:

    Number of tests: 112

    However... only

    • 105 in JS

    • 105 in Ruby

    • 105 in Crystal

    • 110 in C++

    • 115 in Julia

    • 57 in D

    • 160 in Rust

    • 111 in C#

    • 110 in Java

    Also, inconsistency in the number of tests for different digit-sum and max-digit-length groups

  • ejini战神 Avatar

    Features of the random tests:

    Amount of digits between 2 and 17

    The amount of digits only go up to

    • 14 (Python)

    • 12 (Ruby)

    • 12 (JS)

    • 14 (Crystal)

    • 14 (C++)

    • 14 (Julia)

    • 15 (D)

    • 15 (Go)

    • 15 (Rust)

    • 15 (Haskell)

    • 15 (C#)

    • 15 (Java)

  • ejini战神 Avatar
    • Description should be language-agnostic

    • Note: if there're no values which satisfy these constaints, you should return an empty value (refer to the examples to see what exactly is expected).

    should be return an empty **array / list**

  • ahmet_popaj Avatar

    Very challenging and nice kata, compliments.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • KDavis006 Avatar

    The description does not clearly say that 0 is not a valid number to use. As long as you put it in the description it will be fine. Thx!

  • christph Avatar

    the Julia solution setup has a typo: Find_all(sumdig, digs) should be lowercase find_all(sumdig, digs)

  • lukeschu Avatar

    This was fun, thanks!!

  • Enesince98 Avatar

    I don't get the explanation. There are more than 8 numbers with 3 digits that sum of digits equal to 10. Like 442, 433, 505, 604 etc. What am I missing here?

  • MoAz101 Avatar

    Hello!

    I am a little confused on the Kata Details. From what i understood, he'd give me 2 parameters: One for the sum of digits, and one for the amount of digits.

    My task is to return 3 numbers where the sum of digits is equal to "sum_dig", and the numbers must have a specified amount of digits in them.

    My question is:

    test.assert_equals(find_all(10, 3), [8, 118, 334])

    Here the answer should be [8, 118, 334] but why is there an "8" there? shouldn't there be another 3 digit number that the sum of its digits equals 10?

    Thanks for reading

  • Mouadkouibaa Avatar

    Hello friends, my code is correct but it took so much time to execute. Any tips for me, please?

  • 23b00t Avatar

    This comment has been hidden.

  • raulbc777 Avatar

    For all users that want to solve this Kata in C++ version. We are having problems by the moment. I hope that we will be having a good solution for it in the next days. I express my apologies for these inconvenients.

  • OzgurEsm Avatar

    This comment has been hidden.

  • rico-de Avatar

    Hi!

    Problem with C++.

    Test is OK, but when attempting it throws:

    In file included from main.cpp:7:

    ./tests.cpp:22:40: error: use of undeclared identifier 'h'

    for (; lowest < 10; lowest++) r += h(n - lowest, digits - 1, lowest);

    1 error generated.

  • acortad Avatar

    Hi! I'm facing a problem in the Rust version.

    Initial tests pass 100% OK, but when submitting for full test suite, the following appears:

    Thank you


    Time: 1060ms Errors: 1Exit Code: 101 STDERR: error[E0308]: mismatched types --> src/lib.rs:81:59 | 81 | assert_eq!(find_all(n, k), reference_solution(n, k), "\nWith sum_dig = {}, digs = {}", n, k); | ^ expected u8, found i32 | help: you can convert an i32 to a u8 and panic if the converted value doesn't fit | 81 | assert_eq!(find_all(n, k), reference_solution(n.try_into().unwrap(), k), "\nWith sum_dig = {}, digs = {}", n, k); | ++++++++++++++++++++

    error[E0308]: mismatched types --> src/lib.rs:81:62 | 81 | assert_eq!(find_all(n, k), reference_solution(n, k), "\nWith sum_dig = {}, digs = {}", n, k); | ^ expected u8, found i32 | help: you can convert an i32 to a u8 and panic if the converted value doesn't fit | 81 | assert_eq!(find_all(n, k), reference_solution(n, k.try_into().unwrap()), "\nWith sum_dig = {}, digs = {}", n, k); | ++++++++++++++++++++

    error[E0308]: mismatched types --> src/lib.rs:87:59 | 87 | assert_eq!(find_all(n, k), reference_solution(n, k), "\nWith sum_dig = {}, digs = {}", n, k); | ^ expected u8, found i32 | help: you can convert an i32 to a u8 and panic if the converted value doesn't fit | 87 | assert_eq!(find_all(n, k), reference_solution(n.try_into().unwrap(), k), "\nWith sum_dig = {}, digs = {}", n, k); | ++++++++++++++++++++

    error[E0308]: mismatched types --> src/lib.rs:87:62 | 87 | assert_eq!(find_all(n, k), reference_solution(n, k), "\nWith sum_dig = {}, digs = {}", n, k); | ^ expected u8, found i32 | help: you can convert an i32 to a u8 and panic if the converted value doesn't fit | 87 | assert_eq!(find_all(n, k), reference_solution(n, k.try_into().unwrap()), "\nWith sum_dig = {}, digs = {}", n, k); | ++++++++++++++++++++

    error[E0308]: mismatched types --> src/lib.rs:93:59 | 93 | assert_eq!(find_all(n, k), reference_solution(n, k), "\nWith sum_dig = {}, digs = {}", n, k); | ^ expected u8, found i32 | help: you can convert an i32 to a u8 and panic if the converted value doesn't fit | 93 | assert_eq!(find_all(n, k), reference_solution(n.try_into().unwrap(), k), "\nWith sum_dig = {}, digs = {}", n, k); | ++++++++++++++++++++

    error[E0308]: mismatched types --> src/lib.rs:93:62 | 93 | assert_eq!(find_all(n, k), reference_solution(n, k), "\nWith sum_dig = {}, digs = {}", n, k); | ^ expected u8, found i32 | help: you can convert an i32 to a u8 and panic if the converted value doesn't fit | 93 | assert_eq!(find_all(n, k), reference_solution(n, k.try_into().unwrap()), "\nWith sum_dig = {}, digs = {}", n, k); | ++++++++++++++++++++

    For more information about this error, try rustc --explain E0308. error: could not compile challenge due to 6 previous errors

    NOTE: Line numbers in error messages can be incorrect due to concatenation.

  • TEAMENT Avatar

    when I test my solution everything is fine, but when I attempt, an error appears outside my code:

    In file included from main.cpp:7: ./tests.cpp:22:40: error: use of undeclared identifier 'h' for (; lowest < 10; lowest++) r += h(n - lowest, digits - 1, lowest); ^ 1 error generated.

  • nuss_ecke Avatar

    Hi there! Great kata in general!

    The setup of the python test cases seems a bit... unique. The test.it("Result = " + str(result)) statement after the assert_equals appears as a seperate test in the color red (regardeless of whether the solution is correct). This had me scratch my head since I thought my solution was still incorrect and I was failing test cases. It gets even more confusing when trying to print to the log, as the log message that pops up when clicking on the Result = ... "test-case" drop-down stems from execution of the following test, so the numbers are all wrong. I'm not an expert on the python test suite, but I believe there should only be a single test.it() statement before a test, and never one after the test it belongs to. Also, if I'm not mistaking, every test.it()should call at least one test.assert function.

  • LOLbit Avatar

    This comment has been hidden.

  • Swag_Legend Avatar

    Not too large random tests
    


    Test #0 Test for sum_digits = 37 and amount of digits = 3 Actual: [] Expected: []


    Test #1 Test for sum_digits = 35 and amount of digits = 5 Actual: [28, 17999, 77777] Expected: [28, 17999, 77777]


    Test #2 Test for sum_digits = 25 and amount of digits = 7 Actual: [158, 1111399, 3334444] Expected: [158, 1111399, 3334444]


    Test #3 Test for sum_digits = 36 and amount of digits = 5 Actual: [22, 18999, 77778] Expected: [22, 18999, 77778]


    Test #4 Test for sum_digits = 38 and amount of digits = 6 Actual: [94, 119999, 666677] Expected: [94, 119999, 666677]


    Test #5 Test for sum_digits = 29 and amount of digits = 3 Actual: [] Expected: []


    Test #6 Test for sum_digits = 39 and amount of digits = 8 Actual: [519, 11118999, 45555555] Expected: [519, 11118999, 45555555]


    Test #7 Test for sum_digits = 36 and amount of digits = 3 Actual: [] Expected: []


    Test #8 Test for sum_digits = 31 and amount of digits = 5 Actual: [52, 13999, 66667] Expected: [52, 13999, 66667]


    Test #9 Test for sum_digits = 34 and amount of digits = 7 Actual: [285, 1114999, 4555555] Expected: [285, 1114999, 4555555]


    Test #10 Test for sum_digits = 21 and amount of digits = 2 Actual: [] Expected: []

  • slimedog Avatar

    What's the expected time complexity of the algorithm?

  • akar-0 Avatar
  • akar-0 Avatar
  • Ekelen Avatar

    This comment has been hidden.

  • Knani1234 Avatar

    This comment has been hidden.

  • RSMacris Avatar

    This comment has been hidden.

  • pythonCodeuse Avatar

    This comment has been hidden.

  • pythonCodeuse Avatar

    I have a question. How do i submit my code for the question? This is my first time

  • Nam01ar Avatar

    any advise how could i optimize my code? it timed out...im new in coding..im doing brute force, iterating..its ok with sample tests but it times out when i go to the larger numbers..

  • twlghtzn Avatar

    This comment has been hidden.

  • Guaho121601 Avatar

    C#: tests done well, time to, but catch ArgumentOutOfRangeException. https://prnt.sc/1qfo1xj

  • FArekkusu Avatar

    C++ translation. Please, review and approve.

  • FArekkusu Avatar

    This comment has been hidden.

  • user4452518 Avatar

    This comment has been hidden.

  • jakubsvec Avatar

    This comment has been hidden.

  • SapphireSuicune Avatar

    I think my code needs some help...

    It takes 4717ms to complete...

    the sample tests.

    haha

  • orion_s Avatar

    Basic tests execution time (Time: 1256ms), the rest of the time is still more than 12000. How long should the basic tests be in order to execute the main tests?(python)

  • RealKenshiro Avatar

    Amazing and original Kata!

    Thanks to the author @raulbc777

  • stiff Avatar

    How Haskell solutions pass the tests in time if virtually all of them are just plain bruteforce?

  • DrunkenDolphin Avatar

    When I run my code in IDE all test cases is OK, but when I run code in CodeWars it fails. I noticed that prints (sout) from IDE and CodeWars are very different. (IDE is right) I copied code from IDE.

    Does anyone know why this might be happening?

  • walt1010 Avatar

    This comment has been hidden.

  • KirGear Avatar

    Nice kata with non-trivial algorithm! If you don't use brute force, of course.

  • dFuZe Avatar

    This comment has been hidden.

  • kenkre Avatar

    This comment has been hidden.

  • LevyLev Avatar

    expected: java.util.Arrays$ArrayList<[8, 118, 334]> but was: java.util.ArrayList<[8, 118, 334]>

    i get this , what i am doing wrong?

  • Felipé Avatar

    RUBY:

    You really need to consider how fast the methods you use are. There is a ruby method to create array very fast.

    Your sample tests should run in 1-2ms if you want to avoid timeout on random tests.

    I'm a bit disappointed in this exercice. If you don't have one precise method you won't succeed regardless of you smart you can be.

  • Tigerhub779 Avatar

    This comment has been hidden.

  • zrhhust Avatar

    This comment has been hidden.

  • user9644768 Avatar

    how to know how many test my code passed before time out? is there any general measure like for this set of numbers ,you have to get it done in this span of time? As, I wanna know my progress.

  • fire74 Avatar

    For Python 2.7:

    The code: return []

    Output: Passed: 17 Failed: 75 Exit Code: 1

    STDERR Execution Timed Out (12000 ms)

    It Kata is impossible.

  • m-hora Avatar

    This comment has been hidden.

  • hobovsky Avatar

    When I run full test suite in C#, I get following output in console:

    Log
    *
    *
    ***********************************
        %s
    ***********************************
    *
    -------
    Test #%d
    Test for sum_digits = %d and amount of digits = %d
    Actual: %s
    Expected: %s
    -------
    Test #%d
    Test for sum_digits = %d and amount of digits = %d
    Actual: %s
    Expected: %s
    -------
    ...
    

    It seems formatting of output messages is messed up.

  • ecolban Avatar

    This comment has been hidden.

  • KickStick Avatar

    Hello, i have Execution Timed Out (16000 ms) in 'How many numbers III?' every time. Tests on my laptop performed in 12ms. Help, please

  • Anton König Avatar

    Why is the number 109 not counted as valid sum of 10, why only 118? The kata description does not make sense.

  • JohanWiltink Avatar

    Haskell translation

    ( Please approve Crystal, below, first. I've done some description updates. Crystal-specific examples are included. )

  • Firefly2002 Avatar

    Crystal translation submitted

  • KataSideKick Avatar

    This comment has been hidden.

  • udovr Avatar

    Holy Moses! It was staring right in my face. Excellent Kata, @raulbc777 !

  • udovr Avatar

    106 tests passed, 65-12 gets done in under 20 seconds on my laptop (yeah I know, maybe not a reference).... AAAARGH!

    It FEELS like i'm close but will hit a bullet proof glass wall at 110 tests...

  • cocoderrr Avatar

    This comment has been hidden.

  • Shiv  Singh Avatar

    This comment has been hidden.

  • tspencer9 Avatar

    are we allowed to use functional programming in this kata? i was unable to import stream and function. i am new to functional programming so perhaps i was just importing it and using the libraries wrong.

  • jkurinsky@fastmail.com Avatar

    This was a fun one; thanks. No idea if the solution I came up with is what you had in mind.Went through several rounds of optimization before it passed, but now I can't get it to replicate... time to find another corner to cut...

  • seger Avatar

    This comment has been hidden.

  • niv271 Avatar

    does anybody else get this error? [javascript]

    /home/codewarrior/index.js:129 }); ^

    SyntaxError: Unexpected token ) at createScript (vm.js:80:10) at Object.runInThisContext (vm.js:139:10) at Module._compile (module.js:616:28) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at [eval]:1:1

    what should i do?

  • joshua082390 Avatar

    Quick suggestion, I did the java version and noticed you use List but don't import it to begin with, leaving it to the programmer to do this. I know it's small but it should be easy enough to change.

  • gabtotal Avatar

    Nice kata, thanks!

  • SmartShade Avatar

    I try to "Run simple test". Then I see that test falled with message: "expected: java.util.Arrays$ArrayList<[8, 118, 334]> but was: java.util.Arrays$ArrayList<[8, 118, 334]>" This test expect List. Fix it, please.

  • tandav Avatar

    My solution is slow! Is there any particular algorithm that I need to study to make it fast?

  • Blind4Basics Avatar

    This comment has been hidden.

  • henrebotha Avatar

    This comment has been hidden.

  • glebec Avatar

    I'm working on the kata, enjoying it in general. However:

    This kata does something I really dislike. Not a problem, just an antipattern. When you want to return multiple heterogenous results, contain them in an object, not an array. Arrays in JS are just objects with a magic .length and numerical keys instead of string keys after all. It's asinine to refer to things like results[1] instead of results.min. Arrays should be for lists of uniform type, where ops like map, filter, etc. make sense. Objects are far better for records / dictionaries of heterogenous types and meaning.

  • gtzampanakis Avatar

    This comment has been hidden.

  • memyselfandhai Avatar

    Any tips/hints for optimizing the algorithm? Currently passing the sample tests okay, but timing out on the attempt. Thanks!

  • tiago47 Avatar

    This comment has been hidden.

  • Nlckname Avatar

    This comment has been hidden.

  • Daut44 Avatar

    This comment has been hidden.

  • MateuszSenpai Avatar

    this Kata is very interesting but the description is very misleading.

    This should be splitted into 2 parts.

    The first part is explaining the problem. This part is too small and poorly written. It made me think that I have to write the function that returns the sorted table of all n-digit numbers which digits sum to the given number. "the increasing order" made me think this is already a part of the task. And in the second part; even function name confirmed my thoughts that this is what i have to do: find_all() --- right??? --- so i have to find all the variations? WRONG I looked at result of find function and was confused. Why are there only 2 numbers and WhyTF is there 8?

    Thats why a big "BUT THATS NOT WHAT WE ARE DOING" between 2 parts would be helpful

  • Voile Avatar

    This comment has been hidden.

  • brendanvos Avatar

    The description for this kata is not gramatically sound and does a poor job of communicating the problem. Specifically:

    We want to generate all the numbers of three digits that adding their corresponding ones equals to 10 and being all of them in increasing order (the numbers may have two or more equal contiguous digits)
    They are 118, 127, 136, 145, 226, 235, 244, 334.
    Make a function that receiving the total sum of digits and the number of desired digits, outputs the amount of all these possible numbers with the minimum and the maximum numbers. The case above should be:
    find_all(10, 3) == [8, 118, 334]

    This section needs to be heavily reworked. Here is a replacement which may better outline the problem:


    Make a list of all numbers n such that:

    • n has num_digs digits
    • the digits of n sum to sum_dig
    • each digit of n is either equal to or larger than the previous digit (when parsing n from left to right)

    find_all will return a list [a, b, c] where:

    • a is length of the list of n s
    • b is the smallest n
    • c is the largest n

    For example: find_all(10, 3) == [8, 118, 334]

    As calculated from the list of n s: [118, 127, 136, 145, 226, 235, 244, 334]

  • EricPoehlsen Avatar

    My first approach worked locally but died with a MemoryError on the test - but a second approach worked :)

  • gabbek Avatar

    Whenever I try to solve any of your katas, @raulbc777 I first facepalm myself - saying "This will be really hard...", but after a while I'm smiling and thinking - this was great! Thank you so much for truly unique experience :D

  • sharni Avatar

    Process was terminated. It took longer than 12000ms to complete

    Around 22 test cases got passed.

  • liyulin Avatar

    only solve the example

    Process was terminated. It took longer than 12000ms to complete

  • smile67 Avatar

    Hi Raul, hope you are well?! See my (JS) solution, it's just a little "5 minutes joke" so don't wonder (sometimes i like such things:-))... Have a nice day;-)!

  • kazk Avatar

    @raulbc777, sorry I didn't get your comment from 2 weeks ago. I wish Codewars also had @user notifications :( Approved with the average 4 kyu :)


    I'd suggest looking into providing Python 3 option.

  • albmaso Avatar

    This comment has been hidden.

  • myjinxin2015 Avatar

    This comment has been hidden.

  • mmalkavian Avatar
    if(sensei == "raulbc777"){
      return "very likely unrepresentable numbers, overflows, underflows, stack overflows, impossible recursions, high stress for codewars' servers..."
    }
    

    :D