4 kyu
How many numbers III?
2,235 of 4,514raulbc777
Loading description...
Fundamentals
Data Structures
Algorithms
Mathematics
Logic
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.
Отличное Ката, я в восторге, было сложно, но интересно решать данную задачу. Автору огромное спасибо.
OCaml translation
Approved!
Scala translation
Aporoved!
JS update
Approved by someone (not me)
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.
That does look like an absolute mess yes xD
My first guess is that they're being json-stringified then compared. Note that the 8 is not quoted and 118 and 334 are in the expected value. So while, yes, that is an absolute mess, if you match the types it may nonetheless be functional.
As natan said, it looks confusing, but what it's saying is that it expected
[number, string, string]
to be returned, but your function returned[number, number, number]
You are right! I am blind! Thank you!
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!
This is an issue with your code. In your code,
arr
is a global variable, so when the code runs the second test, there are still values from the first test inarr
. You must not have been running more than one test locally, otherwise you'd see the same behavior in visual stuido.good kata
Swift translation
Approved by someone.
Great kata, 2 days to complete it and have to learn more about recursive.
I didn't like it and I wish bad morning to the author
Maybe reconsider frivolent outward expressions of manifesting bad will towards strangers that have meant you no harm?
I've been frustrated and tried to do an "insulting" joke. I think i've gone a litte too far with that
Or maybe you're too sensitive idk
For anyone that's having trouble with this one, research how to use backtracking and recursion! :)
JS (
mocha
+chai
) should be enabledassert.deepEqual
should be usedThe output should be BigInt instead of String for
min
andmax
(invalidating solutions for the sake of consistency is much better than bad output type)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
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)
Description should be language-agnostic
should be
return an empty **array / list**
Very challenging and nice kata, compliments.
python new test framework is required. updated in this fork
Approved!
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!
Thats redundant since 0 would never be greater than it's predecessor digit. And since 0 can not be the first digit, as 0's in front don't modify the actual value of a number, any 0 to the right would never satisfy the incrementing condition.
A clarification would still be appreciated. For example, in test case find_all(35, 6), 107999 would be valid even though there is a zero after the one. Zeros that are not the first digit do count in the value of the number.
107999 would not be valid because 0 is smaller than 1, therefore the digits in
107999
are not in increasing order. This is not an issue.the Julia solution setup has a typo: Find_all(sumdig, digs) should be lowercase find_all(sumdig, digs)
This was fun, thanks!!
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?
the digits of the number should be in increasing order from left to right
@idriss-ivan23 not in "increasing", but in "not decreasing" order, there is a slight difference
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
Hi there! The 8 is the count of how many numbers meet the criteria while 118 is the lower bound of the eight numbers and 334 is the upper bound. In other words, if you find all the numbers and put them in an array
A = [118, 127, 136, 145, 226, 235, 244, 334]
, then the answer is[length(A), min(A), max(A)]
Thanks a lot for your fast reply
and thanks for your work on answering questions and issues
Have a good one
warm regards too
Hello friends, my code is correct but it took so much time to execute. Any tips for me, please?
Hey @Mouadkouibaa and welcome to Codewars!
As you can see, this is ranked as a 4 kyu which means it is intended to be a bit challenging; if you are timing out it either means you have an infinite loop somewhere ( check this troubleshooting page for advice with that issue ) or your algorithm is not performant enough.
The best advice would be to practice your skills on 6 kyu, 5 kyu katas, learn from them how to solve these kind of challenges and then return to the more difficult katas later.
I'm sure I don't have an infinite loop and As you can see, I passed All the tests successfully.
Timed Out Passed: 10 Failed: ? Exit Code: 1
Test Results: Basic Tests Simple Cases
Test Passed: Value == '[8, '118', '334']'
Test Passed: Value == '[1, '999', '999']'
Test Passed: Value == '[]'
Test Passed: Value == '[123, '116999', '566666']'
Completed in 589ms Completed in 592ms Random Tests More Challenging Cases
Testing for sum digits = 24 and amount of digits = 6
Test Passed: Value == '[116, '111399', '444444']'
Completed in 1ms
Testing for sum digits = 28 and amount of digits = 5
Test Passed: Value == '[66, '11899', '55666']'
Testing for sum digits = 27 and amount of digits = 5
Test Passed: Value == '[70, '11799', '55566']'
Testing for sum digits = 29 and amount of digits = 6
Test Passed: Value == '[147, '111899', '455555']'
Completed in 1ms
Testing for sum digits = 27 and amount of digits = 7
Test Passed: Value == '[197, '1111599', '3444444']'
Testing for sum digits = 29 and amount of digits = 5
Test Passed: Value == '[63, '11999', '56666']'
Execution Timed Out (12000 ms)
In that case it's probably the performance of your algorithm then - I can't see your current solution, but note that in the Description it says that:
"In random tests (...) Amount of digits between 2 and 17"
Does your approach loops over all numbers from
1
toN_max
? Because if yes, with 17 digits the value ofN_max
will be10**17 - 1
which is a huge number!Looking at your results it seems your code can handle tests with ...5,6,7 digits but is timing out with 8,9... digits.
This comment has been hidden.
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.
Indeed seems to have an error in C++: my solutions passes the TEST fine, but have a compilation error when "attempting" =>
Hi @raulbc777 : fixed the bug in C++ (I guess) => didn't check the random or review the entire code. I let you do that.
BTW... the C++ prototype (uint64_t, etc...) is 120% weird !!!
Thanks a lot @eurydice5717. Many people observed that the C++ version was not working. I don't manage this language. It was my fault to approve this translation.
Is it solvable right now in C++;?
This comment has been hidden.
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.
This version in C++ was recently approved and I checked author´s translation is inactive. I'll ask for an user that manages well with this language. Sorry for that.
Thanks for your effort :)
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
, foundi32
| help: you can convert ani32
to au8
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
, foundi32
| help: you can convert ani32
to au8
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
, foundi32
| help: you can convert ani32
to au8
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
, foundi32
| help: you can convert ani32
to au8
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
, foundi32
| help: you can convert ani32
to au8
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
, foundi32
| help: you can convert ani32
to au8
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 compilechallenge
due to 6 previous errorsNOTE: Line numbers in error messages can be incorrect due to concatenation.
This error is caused by your code, your code doesn't respect the original signature which is
fn find_all(sum_dig: u8, digs: u8) -> Option<(usize, u64, u64)>
. The testing function in attempt tests contains explicit types, so it cannot pass.Thanks for your very quick reply, you're absolutely right. Works now :-)
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.
which language?
C++
Same problem here.
Me too
This was fixed at some point.
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 theResult = ...
"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 singletest.it()
statement before a test, and never one after the test it belongs to. Also, if I'm not mistaking, everytest.it()
should call at least onetest.assert
function.This was fixed at some point, the python tests look good now.
@BobtheLantern well now you made me look. they are calling the solution from outside it though.
This comment has been hidden.
Not a kata suggestion (= suggestion of improvement of the kata). Also, you must not post hints on Discourse page; users are expected to solve the katas by themselves.
You are right... but even then it didn't work XD. Timed out.
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: []
What's the expected time complexity of the algorithm?
Go translation.
Thanks :)
Rust translation
Approved!
This comment has been hidden.
This comment has been hidden.
though 109 is not a solution here as the digits are not in sequentially increasing order, i.e. 1 > 0?
1<=0<=9 not in sequentially increasing order, 1<=1<=8 in sequentially increasing order
This comment has been hidden.
Your code has an issue, not the kata. Random tests are random. Read the documentation to debug your code (see left panel).
The same value was passed in more than one instance, and it only failed in the "More Challenging Cases" Also the left panel doesn't leave much more information, i only know that, because i console.log(n,k) And i saw the left panel
Don't raise issues because your code doesn' work and you want points. That's not an issue. You say the kata has a problem because your code passes everything except the "more challenging cases". My code passes them, as hundreds of other people, so what? You can ask a question, but please provide clear information, logs, code, etc. Raising an issue saying you desserve your points is just childish and pointless. Please read carefully the documentation: https://docs.codewars.com/training/troubleshooting/
Your code doesn't pass the sample tests, it returns [] everywhere...
i was just joking about the points but still The problem itself could have specified that he wanted an exceptional good way of doing it beforehand, wouldn't have make me waste my time Thank you for your patiance, i've changed my code since btw, when i raised the issue i genuinely thought there was an issue.
This is a 4kyu so it is expectable to be somewhat hard. If you don't want to waste your time, maybe you should stick with white katas.
This comment has been hidden.
I have a question. How do i submit my code for the question? This is my first time
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..
Since I can't see your solution, I'm going to guess with most common things:
This comment has been hidden.
Sometimes it just says "Not too large random tests Test Execution Timed Out" and no details of which tests failed. I get an overall feeling that 4 kyu katas are a bunch of sh.t excuse my french...
C#: tests done well, time to, but catch ArgumentOutOfRangeException. https://prnt.sc/1qfo1xj
C++ translation. Please, review and approve.
Approved by someone
This comment has been hidden.
which language ?
This is an old issue, I wasn't able to find any empty it blocks in any of the translations, I'm guessing it's been fixed.
This comment has been hidden.
This comment has been hidden.
The user's already completed the kata.
This comment has been hidden.
This comment has been hidden.
I think my code needs some help...
It takes 4717ms to complete...
the sample tests.
haha
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)
if you are programming this kata with JS i think it has a problem
Basic Tests execution time of my code is 30ms Only the "More Challanging Cases" do not pass It wouldn't be a problem if the same params for the "More Challanging Cases" haven't been passed to the others tests that have passed The mod don't even bother looking for it and direct removed my issue report :/
Can this problem be solved somehow? I got the same result, only the "More Challengins Cases" will fail after timeout.
Amazing and original Kata!
Thanks to the author @raulbc777
How Haskell solutions pass the tests in time if virtually all of them are just plain bruteforce?
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?
Different language version (e.g. Python 3.6 vs Python 3.8) or your machine being faster (timeout limit on codewars 12 seconds).
This comment has been hidden.
Nice kata with non-trivial algorithm! If you don't use brute force, of course.
This comment has been hidden.
This comment has been hidden.
No, and this exact case is explained in the kata description. You forgot this constraint:
expected: java.util.Arrays$ArrayList<[8, 118, 334]> but was: java.util.ArrayList<[8, 118, 334]>
i get this , what i am doing wrong?
Pretty weird. I couldn't reproduce this. Paste here the return line of your code and/or the line where you define your output data structure (with spoiler flag if needed)
This comment has been hidden.
markdowns, plz. Your code is totally unreadable/wrong, right now.
This comment has been hidden.
Markdowns! x/
Anyway, I'll do a bet, then: you didn't type your
result
list, while you're inserting ints inside it. No wonder...wait... wut??
Don't ever change the signature of a provided method in java. Doing so, you're braking the contract given by the author/translator (myself, for instance), so don't be surprised that you get weird stuff like this, after.
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.
This comment has been hidden.
That's the same for JS My basic tests passes with 32ms and i still don't pass in the "More Challanging Cases" even tho those cases received the same parameter of another test that has passed -.-
This comment has been hidden.
This hint helped me quite a lot :-) Thanks
I think this clue is already considered a spoiler AHHAHAHAH
This comment has been hidden.
Because "their digits are in increasing order (the numbers may have two or more equal contiguous digits)" And '1 < 0 < 9' And '9 < 0 < 1' are false~
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.
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.
Are you generating all possible numbers and then checking each one to see if the digits are increasing or not? I did that first, and it works for a low number of digits, but takes expoentially longer with larger numbers of digits. There's a better way of approaching the problem.
No, they mean that doing nothing but returning an empty list will time out. Which I've observed as well :/
This comment has been hidden.
Your code times out because it's terribly inefficient. You need to come up with some better idea than iterating through all possible values in the range. For example, for n=18, your approach iterates over 1 trillion (european trillion) of values.
When I run full test suite in C#, I get following output in console:
It seems formatting of output messages is messed up.
The log output has been improved.
This comment has been hidden.
Hello, i have Execution Timed Out (16000 ms) in 'How many numbers III?' every time. Tests on my laptop performed in 12ms. Help, please
12ms, it's only the sample tests. The full test suite goes way higher about the inputs. So you need to completely change your approach.
If you expect to receive any kind of useful help you need to provide more information about the problem. First off, provide the language you're using. Also, be aware that the full tests are typically going to be more comprehensive than the sample tests.
This comment has been hidden.
@KickStick, when you post code or any kind of spoiler, be sure to tag it with the
Spoiler
flag. If optimizing your existing code does not solve your timing issues, you may need to come up with an entirely different approach.I think the problem is a lot of additional tests
this is the naive approach. You need something more efficient
This is a 4kyu kata, which is expectedly going to be more difficult than the white and yellow katas you're used to.
I just tried to execute ready-made solutions in other languages and got the same error. The runtime of a simple test in "non-naive" approaches is more than a dozen times. I solved the problem long enough with my mentor. Indicate the weak point of my approach or something like that please
This comment has been hidden.
It was a google translator. I already understood this and solved the problem, thanks
Why is the number 109 not counted as valid sum of 10, why only 118? The kata description does not make sense.
Because 0 isn't >= 1, so 109 isn't an 'increasing number'
Ok
Haskell translation
( Please approve Crystal, below, first. I've done some description updates. Crystal-specific examples are included. )
Crystal has a merge conflict too, so that needs resolved first.
Crystal translation submitted
This comment has been hidden.
Holy Moses! It was staring right in my face. Excellent Kata, @raulbc777 !
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...
This comment has been hidden.
65-13 in under 16 seconds (main counter only until sumDigits/numDigits) and still ...
@raulbc777 , you'll be the death of me... :)
This comment has been hidden.
This comment has been hidden.
Not an issue, a question. Closing (Issue == dysfunctionning kata / Question == "My code cannot pass the tests but...").
For your problem, try to think about useless thing you're computing. Things that you currently believe you actually need but "it's a lie!" ;)
If you time out, that means you don't use the correct approach.
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.
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...
This comment has been hidden.
Hi Seger. I may understand the frustration when we spend some time in a kata and our solution isn't fast enough to pass. But as you can see, up to this moment, 54 people solved this challenge in the Java version. There are many "terrible exercises" like this one, from 5 kyu level and above, waiting for you. There may be a great opportunity for you to sharpen up your skills. Have a good day.
I just solved it, and was certainly never taught anything like this, nor had I stumbled across anything like it. Granted, my solution seems much different than everyone else's, but you don't really need to know any math at all to solve this.
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?
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.
Hi @joshua082390. I'll message to the translation author. Thanks for the feedback.
Nice kata, thanks!
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.
Actually, the problem was rather that it expected a List of Integers instead of a list of Longs. ;)
Corrected.
My solution is slow! Is there any particular algorithm that I need to study to make it fast?
This comment has been hidden.
This comment has been hidden.
I think you didn't look at the fork... Mine is just 50 time faster than the reference solution in python........... :p
But this JS solution exists! ;-)
which is perfectly, absolutely slow... (Note: JS tests seems less demanding than in pyhton: there is not the third batch of random tests with the huge numbers)
'did some investigations: the java compiling takes already around 5,5-6s on its own, without any test... :/
Approved ;-)
thx!
This comment has been hidden.
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 likeresults[1]
instead ofresults.min
. Arrays should be for lists of uniform type, where ops likemap
,filter
, etc. make sense. Objects are far better for records / dictionaries of heterogenous types and meaning.Or think of it as a 3-tuple.
Looking back on this comment, I wish I could edit it. "Really dislike" and "asinine" are much more curt than I actually feel about this style point. I do like records for heterogenous results but it's not such a big deal as to have warranted my original comment.
This comment has been hidden.
Should be fixed
Any tips/hints for optimizing the algorithm? Currently passing the sample tests okay, but timing out on the attempt. Thanks!
This comment has been hidden.
This comment has been hidden.
Oh i get it now. Thanks for you reply i appreciate that! :-)
This comment has been hidden.
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
Thanks for the suggestion. I've modified the description. I hope that it's clearer for you. Thanks. Your suggestions are welcome.
This comment has been hidden.
The description for this kata is not gramatically sound and does a poor job of communicating the problem. Specifically:
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:
find_all will return a list [a, b, c] where:
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]
Thanks for your time solving this kata and for your feedback. I've modified the description. I hope that it's clearer for you. Your suggestions are welcome.
Totally agree with you @brendanvos Your description is definitely clearer and should be adopted as the official one. I totally missed this part «each digit of n is either equal to or larger than the previous digit (when parsing n from left to right)». Thank you!
My first approach worked locally but died with a MemoryError on the test - but a second approach worked :)
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
Thanks for your time solving it. Your solution upvoted (+1)
I like how you used a generator. An opportunity to improve!
Process was terminated. It took longer than 12000ms to complete
Around 22 test cases got passed.
only solve the example
Process was terminated. It took longer than 12000ms to complete
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;-)!
Thanks for that! :) Coming back for holidays. I like your solution. (+1)
@raulbc777, sorry I didn't get your comment from 2 weeks ago. I wish Codewars also had
@user
notifications :( Approved with the average4 kyu
:)I'd suggest looking into providing Python 3 option.
Thanks kazk for your approval.
I was able to make this available in Python 3.4 and 3.6 too :)
This comment has been hidden.
Glad you liked it! :)
This comment has been hidden.
You might be a beginner in Python but not in the algorithms. :)
:D
Keep on trying. At the moment two people solved it. It's a bit more difficult than others. :)
Finding maximum and minimum can be done, but counting all of them... :-\
That's normally not the way (...deal with 10^14 numbers) to solve Rauls katas:-)... And if it works for python, which is "very slow";-), there's always a "trick" (better formula/algorithm:-)) to solve it on a better way:-)... So don't try a stupid loop for all these numbers without using some conditions for these
sum restricted, contiguous
15 digits;-)...This comment has been hidden.
This comment has been hidden.
;-)