6 kyu
Playing with digits
3,724 of 143,429g964
Loading description...
Fundamentals
Mathematics
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.
how to know which input they used in test 10 or any failed test?
See if this paragraph helps.
This comment has been hidden.
Don't post solutions in discourse like that, it's forbidden.
the random tests always expect
-1
in JS and OCaml, possibly other languagesIn C, there's an annoying warning:
I think the
const
should be removed.fixed
This comment has been hidden.
js fork 🤖🤖🤖
mocha/chai
assertionslodash
for randomnessMerged
I don't think of how much k can be, bc idk the max values for n or p, so the code freezes on codewars for veeery big iterations of k
k
seems to be a single digit number, andn
is only up to a few million (7 digits) long (Python version), so if you're getting timeouts, you should reconsider your approach.Groovy Translation
for n = 46288, p = 5 4^5 + 6 ^ 6 + 2 ^ 7 + 8 ^ 8 + 8 ^ 9 = 151042752 --> 46288 * 69594204 but the challenge test says the output should be -1 how is that?
151042752 is not 46288 * 69594204, that's 3221376514752.
151042752 / 46288 = 3262.1081 is not an integer should return -1
Great challenge, the hardest thing was to understand the task
this was pain for a haskell beginner
I feel like I would have spent a lot less time with this if I wasn't a C++ beginner. I had fun, though. The concept is actually kind of simple, you just need to turn the fancy math language into something you can understand.
what the hell was that
I hated this... Thanks! =D
Am I missing something - is this maths problem not unsolvable without placing limits on K, as you can always just look for higher values of K to infinity that meet this equation.
INSTRUCTIONS ARE UNCLEAR! I DO NOT LIKE THIS KATA, REMOVE IT FFROM THE WEBSITE, NOW!!!!
I wish this wasnt so hard to grasp what was wanted to be accomplished. I hated reading this so many times lol.
There is an error in the examples in the description: n = 46288; p = 3 ---> 51 since 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51 but 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 263,592 So k=51 is wrong
It is correct, you can check it for yourself by calculating it using calculator or by hand
8**7 = 2' 097' 152. And this is already more than the amount you mentioned.
a great challenge. Had to re-read a few times to get it, definitely got my brain going!
I had to reread it many times to understand it, but I did it!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Please see this js fork adding random tests
Edit: approved
OCaml and JS have random tests, but they always expect
-1
. C has randomized tests that shuffle pre-computed values. I think generating meaningful inputs for this kata is hard. I tried randomly generatingn
and then trying several values ofp
until either the sum of powers becomes too large orn
divides it, but the latter almost never happens. If someone has an idea for an algorithm they could share it hereInstruction is a bit vague. or maybe just me
The tests assertions are not good, there are some expected results that are wrong, I figured it out when I test it manually with the given values.... not sure if I'm doing something wrong, could you please take a look at them?
Python tests are fine. Not a kata issue. Please next time provide the language and be specific about what you think is wrong, give the input, the expected output and why you think it is wrong.
yeah, I'm so sorry, I just realized that it was my fault, next time I'll provide all the stuff you mention too, thanks
If you are struggling with understanding what
k
stands for it's the result of addition divided by initial number (n
)you saved my day
Thanks a lot!
C fork
thanks !
I have stuck on one of the test and i cannot figure which values it gets when i call for funciton exactly this one "your solution should return -1, but it returned 3263.10819218804 instead." any ideas why I get it, or which values test passes to check my code? Thanks in advance
Did you try printing the input?
well no, will try it now thanks
OP solved it in a cheesy way, closing
In Haskell, this should probably use Nothing rather than -1 as a sentinel value.
I am stuck, I have been trying to figure out the pattern for p. However, it just is not clicking for me. Any advice anyone?
if you figure this out, let me know
This comment has been hidden.
https://memepedia.ru/wp-content/uploads/2021/12/chel-horosh-2.png
This comment has been hidden.
Done.
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting#print-input and use the methods your language of choice uses to print the input.
in my editor everything works correctly in the tests everything works, but then I get timed out, what should I do?
Your solution is too slow. You need to work on performance of your solution.
This comment has been hidden.
You can print n and p.
This comment has been hidden.
closing
All of the Sample cases are working but I'm getting some errors for the other test cases. I don't know what inputs are being given, it only says what integer is being supplied but not the power. Is there a way of seeing this?
Read this: https://docs.codewars.com/training/troubleshooting#print-input
Ah thanks mate
This comment has been hidden.
OP solved it, closing
This comment has been hidden.
For me it is not an issue since "return p if total == n * p else -1" is the condition given by the kata if I am not wrong but maybe I have badly understood your post.
it does not pass the fixed tests, while passing ALL 'random' tests
"expected 3263.10819218804 to equal -1" what is the meaning of this message. all other test passed. please help. javascript used.
The meaning of this message is that there is some test for which your solution should return -1, but it returned
3263.10819218804
instead.thank you for response.how can i know which test return this value?
ok thank you. i got solution and it works.
expected -1 to equal 12933
All tests pass, but there is this error, I don't understand what's the matter, help
For this test:
Test.assertEquals(digPow(10383, 6), 12933);
your code returns
-1
,so not all tests pass, so you'll need to fix your code.
fsharp has also problem
at Microsoft.FSharp.Core.Operators+OperatorIntrinsics.loop@5444-5 (System.Int32 x, System.Int32 n) [0x00025] in <58dd0ce1dff9fae1a7450383e10cdd58>:0 at Microsoft.FSharp.Core.Operators+OperatorIntrinsics.PowInt32 (System.Int32 x, System.Int32 n) [0x00003] in <58dd0ce1dff9fae1a7450383e10cdd58>:0 at Microsoft.FSharp.Collections.ArrayModule.MapIndexed[T,TResult] (Microsoft.FSharp.Core.FSharpFunc
2[T,TResult] mapping, T[] array) [0x0002b] in <58dd0ce1dff9fae1a7450383e10cdd58>:0 at FSI_0001.digPow (System.Int32 n, System.Int32 p) [0x000af] in <0e31dce15f374339aca94f657f4daf5d>:0 at FSI_0001+Tests+suite@15.Invoke (Microsoft.FSharp.Core.Unit _arg1) [0x001c8] in <0e31dce15f374339aca94f657f4daf5d>:0 at Fuchu.Impl+evalTestList@260-1.Invoke (System.Tuple
2[T1,T2] tupledArg) [0x00028] in <56a815db36d21f70a7450383db15a856>:0A little easy for a 6 kyu question. Perhaps it should be 7 kyu.
nah, its an 8kyu for sure
C++ It seems that the linker is unable to find the definition of the DigPow::digPow function, resulting in the "undefined reference" error.
"/tmp/main-7834c7.o: In function
dotest(int, int, int)': main.cpp:(.text+0xa): undefined reference to
DigPow::digPow(int, int)' /tmp/main-7834c7.o: In functiondigPow_Tests::Fixed__Tests()': main.cpp:(.text._ZN12digPow_Tests12Fixed__TestsEv[_ZN12digPow_Tests12Fixed__TestsEv]+0x12): undefined reference to
DigPow::digPow(int, int)' main.cpp:(.text._ZN12digPow_Tests12Fixed__TestsEv[_ZN12digPow_Tests12Fixed__TestsEv]+0x72): undefined reference toDigPow::digPow(int, int)' main.cpp:(.text._ZN12digPow_Tests12Fixed__TestsEv[_ZN12digPow_Tests12Fixed__TestsEv]+0xd2): undefined reference to
DigPow::digPow(int, int)' main.cpp:(.text._ZN12digPow_Tests12Fixed__TestsEv[_ZN12digPow_Tests12Fixed__TestsEv]+0x132): undefined reference to `DigPow::digPow(int, int)' clang: error: linker command failed with exit code 1 (use -v to see invocation)"Not a kata issue but a problem in your code: please review the C++ basics.
This comment has been hidden.
Looking at your solution, there are some things going wrong with your code.
Try calculate the sum for
(695, 2)
on paper and with the code. Compare them both.Not a kata issue.
Actual and expected are swapped in PHP
fixed
Looks like in C++ they are swapped too. Could you check please? Have no problems with my solution in VS, but here I get the expected answer from the different test..
C++ tests are correct
First read the task (a few times!) and missed that
p
is given, thought it was a much harder problem than it was :)missed that too and gave up ahead of time lol
My code is correct. But I'm running out of time. My code passes small test cases. But it fails BIG test cases. How can I fix this problem? Please! If anyone can help me! Thank You 🙏🙏🙏🙏
Using a faster algorithm. Why the second loop?
OP solved it, closing
Hi I'm doing this project in C, locally I get all the cases and the answers correct, yet I get a time out. I assume it's because of my last loop where I try to find k. I haven't figured out how to make it more efficient. If anyone has a hint, I would appreciate it :)
op solved the kata
not sure for C but the logic is: check if your summ divides with no remainder first, if yes then just return summ/n C:
This just doesn't really seem like it's a very beginner friendly kata. When I selected that I was beginning to program, I wasn't expecting to have to do all of this kind of stuff. I wish Codewars had a better way of helping new programmers progress. I understand that I'll be doing a lot of research on how to solve these problems, and I'm fine with that, but a lot of the kata I've been given thus far, including this one, just don't seem like they'd be something a person who is new to programming with python would even know how to approach.
Try doing 8 and 7 kyu katas first. This one isn't too hard imho. Which problem did you have with it? Are you talking about the "Your next challenge" in the home?
Thanks, I'm not exactly sure how it does this stuff - I just do the ones it tells me to do.
This is a bit beyond me, because as I said, I'm very new to python. It doesn't feel very beginner friendly to me, so I'm struggling a bit. I had to have help to solve this one, and a few others. I'm not exactly sure why it would start me off on such high kata/kyu if I told it I'm beginner.
I'm very glad that as a beginner this one isn't difficult for you, but for me it felt very overwhelming, and not very intuitive to approach for a solution.
This kata is ranked as 6 kyu - considerign the fact that the easiest kata are 8 kyu and 7 kyu, the 6 kyu might be not really beginner friendly. When choosing kata to train on, you could focus just on the white ones, and ignore yellow and harder.
Option enum where?
This comment has been hidden.
is there any efficiant way to code this! with time complexity of O(n)!
This comment has been hidden.
Checks fail in Nim for some reason, check(false) is passed as a complete test but then it crashes
The proc "dotest" was at a wrong place. Modified. Your solution passes. Please give it a try! Thanks for your post.
I solve it with SWIFT. All tests passed, but when attempting I received "expected -1 to equal 12933". What does it mean?
Could someone please explain the question in clearer detail for me?
This comment has been hidden.
This comment has been hidden.
I solve it with JS. All tests passed, but when attempting I received "expected -1 to equal 12933". What does it mean?
Your current code works.
expected -1 to equal 1, what does it mean? my solution passes the test, but the task does not
pls help
Hi @blopire - it seems you are working in JavaScript? Please in future state your language because there are many different ones on the site.
Expected -1 to Equal 1 means: there was a test where the correct answer is 1, but you returned -1.
In other words, the syntax is: "Expected {your returned solution} to equal {the correct answer}"
In JavaScript, you can use
console.log()
to display the inputs - so if the arguments to the function aren,p
you can log those to console to see which ones cause bad results for your code (i.e., find which values ofn
andp
you are handling incorrectly).Read: https://docs.codewars.com/training/troubleshooting/#error-messages-and-printing-your-inputoutput if you need more information.
This comment has been hidden.
I solve the problem in visual code. I checked all the digital values that are in the tests
Hey @blopire - sorry I don't use JavaScript myself, so I can't debug the code on my machine; what I meant though about the
console.log()
thing is:console.log(n,p)
just beneath your function definitiondigPow(n, p) { ...
Now, when you press Attempt, you will see in the Codewars console which values of n and p are causing you to fail tests Basically, look through the console for any red/failed tests and note down the values of
n
andp
that you find.Right now we don't know which values cause your code to fail, so it's hard to debug.
I ended up solving the problem. I tried to write the console.log command, but I still did not understand . thanks everyone for the replies. I have made a decision.
This solution sometimes fails a random test.
So what? Which test for example (your issue is not very explicit:-) ? Do you have an explanation? I don't have enough time to look at your solution. All I can say is that 39327 people passed the Python kata (among them B4B, monadius, Unnamed, Voile, etc...). If that were not you I would have considered the issue as resolved!-).
Thank you for hearing me out. Here are three test cases that fail my solution:
The thing is, they also fail solutions from awesome coders like monadius, Blind4Basics, g964, and Unnamed ~ and my code gets the same results as theirs. So, it would follow that the testing suite is producing incorrect expected values.
This comment has been hidden.
Hi @benjaminzwhite ~ to be clear, the three examples I posted were culled from random tests. My code, your code, and the code of all the coders I mentioned all return
25
and9
for the the examples you put in your breakdown. I ran your code against the random test, and it also eventually failed one:So then I ran the actual reference solution against the
Fixed Tests
and found that it failed most of them.This comment has been hidden.
My Python solution is from 8 years ago but was translated anew 3 months ago by @KayleighWasTaken and it seems approved by himself who has left CW!-(
I modified @KayleighWasTaken's reference solution and added in "sample tests" the tests you mentioned. @benjaminzwhite, @rowcased: can you tests your solutions and mark the issue as resolved (if it is...).
It's a pity for CW that some guys with I think a role of "menders" or something like that (given by "mods") can re-translate a kata and approve it themselves!
Hey @g964 - on my side I just tried: my solution, then the top 5 Python solutions, then also searched for a few power users solutions: for all of them I forked and ran
10_000
random tests in the editor.I didn't see any errors for any of the above, so it looks like everyone's solution/approach agrees now.
I will let @rowcased or you reply/handle Issue since it was his observation :+1: Side note: interesting that only ~1/10_000 input values actually require the
// n
step to produce different answer!@benjaminzwhite: thanks for your work! I will wait for @rowcased:++.
I'm less pessimistic about the role of "Mender" than you. Progress can be made on many kata's that have been abandoned by the author or if an author is no longer active on CW. The problem here is the author is still active, so the fork should have been presented as a suggestion, rather than a self-approval.
Maybe I expressed myself badly, the problem is indeed in the self-approval. An extra (and watchful) "eye" is needed... Nevertheless the other problem is that the choice of "menders" and other roles be carefully made: seniority at CW, rank, commitment not to leave CW after a few months, etc...
Thanks to @benjaminzwhite & @g964, I appreciate your attention to this matter!
When calculating the length of a number, it would be a better idea to convert it to a string for manipulation
The task is quite simple, the main thing is to clearly read the description and understand what each of the arguments does.
Excellent cata
Nice Kata
Thanks!
Nice Kata, challenging but satisfying, without any pesky edge cases. Thanks!
This comment has been hidden.
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting
I definitely overthought (or rather underthought) this one - rereading the problem definition, the best solution was substantially simpler than my extremely roundabout attempt.
If in the first test the result can be 1, doesen't that mean none could have output -1 since every number * 1 is the number itself. I don't know if I didn't get something right here from the instructions but I can't figure it out.
You need to work with the digits of the number, if you use 1 for the first digit, then you should use 2 for the second one and so on.
I was wondering about the let's say: 46288 * 51, where do you get 46288 but I realized you need to substract the original number and find 51 in this case but i get it now, cuz before i didn't see that 46288 is the original number. Thanks
Hi, my code passed all the tests except the last one (when i try to attempt the code). wondering if someone was in the same situation! thanks
Seems like you figured out what was wrong as you have submitted a solution.
Commenting on your post so that users, in future, don't question validity of last test.
in rust it should probably return an Option
Is there a name to this math problem?
"code" wars
Update to Scala 3
Also modified the random test generator to actually include random tests.
.
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting#post-discourse
p
is an argument, you're not using it at all..
math wars
Didn't see any problems. Read the assignment carefully. Don't try to complicate.
This comment has been hidden.
You dont have to share your solutions with us, we can see it on Solutions tab!
Also, use the spoiler flag if you're going to post any part of a solution. I've put the spoiler flag on for you here.
I'm so sorry I didn't know that, I'll make sure to use it the next time
who asked?
This comment has been hidden.
as usual, read this: https://docs.codewars.com/training/troubleshooting/
as usual, I have read this before but nothing helped
mate you have to help us help you
saying
my code works perfectly but doesn't work here
doesn't give others anything to work with. you can post a snippet of your code(with spoiler flag) and ask for some specific help. or...you could try an easier kata, since g964's katas are usually quite tricky to understand if you are just starting outWithout your code, it is very difficult to help you, refer to the Troubleshooting guide about how to properly post it here.
This comment has been hidden.
I don't wanna do maths. Skip
As someone whose last math class was before 9/11, I sometimes feel this way, but not this time!
This was clearly explained, with great examples.
Plus, it was an actual coding challenge, not some Math-trick riddle that's useless in real life.
I think there may be an obscure issue with 32-bit math or floats going on here.
When I found that my solution was failing only a very small number of unit tests in the full test suite, I suspected an edge case, and, on a hunch, made only one change: I replaced the multiplication operator (
*
) withMath.imul()
(see https://mdn.io/imul). This passed all the tests.I have verified this behavior occurs both in Node v10.x and in Node v8.1.3, so I don't believe this to be a newer phenomenon, and may suggest issues in other languages beyond JavaScript.
Sorry but I don't see an issue here. I tried several Js solutions and all worked fine (26481 people passed the Js kata out of a total of more than 90000 - "may suggest issues in other languages beyond JavaScript..."). It is up to you to find a code without problem:-)
This comment has been hidden.
Ruby performs an integer division when both operands are integers, JS doesn't. Anyone programming in a language is assumed to know its basic features and must do with it. And this is a 6kyu, not a 7.
🤦 Fair enough. I'm not sure how I missed that. Thank you for that.
90% of my complaint was operating on the idea that this was a 7 kyu kata, so I'm mostly happy now.
I would still suggest that unit tests should derive their own value of
k
instead of relying on a hardcoded value derived outside the language environment being tested, in an attempt to reduce such issues. I don't know for sure if that is what has happened here.This comment has been hidden.
This comment has been hidden.
This is not a suggeston.
p and k are the same value? i'm confused. promt is confusing.
There is no
k
butp
. We don't know which language you're using so it's impossible to know exactly, but in some of them, the logs only displays what you returned and what you should have returned (your_answer should be correct_answer
).It does not compile in Typescript
test.ts:5:35 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'void'.
5 assert.equal(G964.digPow(n, p), expected, "Incorrect answer for n=" + n + ", p=" + p);
OP solved it, closing
src/Solution.cs(19,2): error CS1513: } expected 1^2+9^3=1+729=730/19 = 38.421
answer: -1 The answer given: no -1
Hi, I'm trying to understand what doesn't work in my code, but I can't get it. Actually it works with all the cases, except the biggest cases (until I can see), that is n = 3456789 and p = 5. Any tipp?
Not a suggestion.
if in your solution k is a double, try to check if k is a whole number
This comment has been hidden.
Once you solved a kata you can see all the other solutions submitted.
This comment has been hidden.
COBOL: sample tests don't work. Incorrect PIC type used for 'n'.
Fixed there: https://www.codewars.com/kumite/62168eacbd1aca00496cced9?sel=6217c669dcbccd000f6f90df
Approved.
COBOL translation.
Approved.
I think in the description where you say "such as", you are meaning to say "such that". You may want to change it for clarity.
Modified.
This comment has been hidden.
Tests are green but I cannot submit the solution because 3263 should be -1 and if I run this locally I am getting -1 from 3263. Please fix this
Print the input. See why your code isn't right. Read this: https://docs.codewars.com/training/troubleshooting
Hi, I don't think there is a test for 3263. If you haven't already, print n and p to see the tests as part of the output.
There isn't a test for 3263 but when I want to submit (after passed tests) I am getting that 3263 should be -1, so I'm went back, added one additional test (3263, 1, -1) to the existing one and I see green again but I cannot submit my solution
Again, print the input. 3236 is what your function returns, not the input values (there are 2).
Ahh, that's your point... Damn, now I know how to debug other tests before submitting :) I fixed my solution and now it passed! Many thanks for your help!
Hey, I have the same problem, turns out we just have code that is built different. I got the Inputs and it was: n=46288 , p=5. Which comes out to the sum of sum=46288 and k=3263.10819218804. And if you divide sum / n = k = 3263.10819218804, What you and me got. It is correct, if you mutiply k=3263.10819218804 * n=46288 = sum = 46288. We are right the test is just broke and dosen't allow decimals... which wasn't in the task!!!!!!!! Ahhhhh
Georg_, read the description again, n and k must be integers.
I believe in terms of the problem: k such as : (a ^ p + b ^ (p+1) + c ^(p+2) + d ^ (p+3) + ...) = n * k A few tests are invalid mathimatically. This is because we are expected to work with int & long when certain sets produce decimal place values which meet the criteria. The solution at the moment is to stick with whole numbers when calculating and dismiss fractional calculations. I think maybe either this needs to be explicitly outlined in the problem or fractional tests should be removed.
Pass TEST but fail ATTEMPT. How it possible: n = 46288 result = 51 sum = 2360688 startPower = 3 // Pass during TEST n = 46288 result = 51 sum = 2360688 startPower = 3 // Fail during ATTEMPT expected 51 to equal -1
Why 403 with initial pow 1 expecting -1? 4pow1 + 0pow2 + 3pow3 = 31 31 * 13 = 403
Because there is no positive integer k that makes 31 equal to k * 403. Read the description again.
the question is 403 * k (k>0) you can read the question again
On attempted the kata is wrongly expecting a -1 for 46288 as n and 5 as p, my code works for all other cases but not that one specifically
That test is fine. Fix your code. 45 + 66 + 27 + 88 + 89 = 151042752 and that's not a multiple of 46288.
This comment has been hidden.
Hi, I'm at lost. My code works as expected in VSC but when I test it here, I get an error "Expected 1 got nil". Anybody with an idea as to what I'm not doing properly ?
This is not an issue but a problem with your code. Don't raise an issue unless you identificated for sure a flaw in the kata. About this and other important details, see there: https://docs.codewars.com/training/troubleshooting/
It's hard to help you without knowing your language and without knowing what you're doing. If after trying to debug seriously your code, following advices given in the link I provided above, you still can't find out the problem, you can ask a question and post your code with a spoiler flag.
Hi Akar and thanks for your reply. I am sorry for wrongly raising an issue, I am quite new to this game but lesson is learned and I will definitely be more careful in the future. As usual with coding, a bit more thinking helped me solve my problem and I have passed all my tests although not in the most elegant way apparently, but I'm here to learn ;) Again thank you, have a good day!
This comment has been hidden.
No random tests.
Issue already posted for that reason. See below.
I initially didn't see that the value of p was provided as a paramater, so I ran my code to find any solution while p<1000 and discovered that some of the test examples incorrectly expect a -1 return (or no solution) when I found a whole intager solution to the given n value as the instructions request.
With a given value of
p
they're not incorrectly expecting anything, you solved another problem.oic, you're right 👍
This comment has been hidden.
For solutions, admins are allocated the "Solutions" section, see accurately.
This comment has been hidden.
boost isn't available, but its included by default on the kata when using cpp. Any alternative libraries I could use?
It's not a kata problem. Boost is not included in Codewars C++ packages. See: https://docs.codewars.com/languages/cpp.
but why is it in the default version of the c++ kata
Man, javascript is very legible. Three-liner that actually is super easy to read and understand.
using C# i am getting this error. code work fine on Visual studion on my local machine. i googled it but it seems to be something concerning namespaces but i cant pin it down. any ideas? src/Solution.cs(11,28): error CS0103: The name 'Math' does not exist in the current context
As g964 says in your post below, you are missing a using statement - add
using System;
above everything else in your solution.Math
is short forSystem.Math
in C#, but you need the initial using statement for this to work.Alternatively you could replace
Math
withSystem.Math
everywhere in your solution.it gave me an error while using c# it didnt recognize Math.Pow() solution worked on my local machine just fine
Please before posting issues look at the top of the page: 4975 people passed the C# kata so you could have seen that it's not an issue of the kata but a problem of your code. To use Math.Pow you need "using System;".
How do we determine the value of p ?
i understand that p is the number where the exponent number starts increasing, if p = 1 then 5^p - 5^p+2 - 5^p+3 or (5^1) - (5^2) - (5^3)
This comment has been hidden.
I've just tried my code in c++ and it works. There must be something wrong in your code, but I can't tell without seeing it. You can post your code with a spoiler flag so it can be examined. Please use markdown tags to format it, see: https://docs.codewars.com/references/markdown/#code-block
No need to open another question. Can you please delete the message above and post it here as a reply? And please use format tags as explained on the link I gave you.
This comment has been hidden.
Please use format tags as I told you twice. I gave the link in the first message. It's illegible.
This comment has been hidden.
Yes it's better. Though optimally you can use add
cpp
after the backticks on the first line so that we also have syntactic coloration. But it's ok. Note you can preview your answer and make trials before publishing.Your syntax is not correct. If you declare another function inside the class, you must use the proper form. See: https://www.tutorialspoint.com/cplusplus/cpp_static_members.htm
Though, here it would be easier to declare it outside of the function, at the very beginning of the code (before
class
), this way it'll be handier.Also,
error: unknown type name 'string'; did you mean 'std::string'
is a very classic problem. You need to learn to use documentation online when you face an error. Search for the error in Google and most of time you'll find the solution to your problem. There may be other problems, I didn't check it all.I have tried the code on eclipse before testing it here
the one error with the String I didn't have it for sure since I used the library string + using namespace std it seems I forgot to copy it
and you're telling me (If you declare another function inside the class, you must use the proper form) I don't think this would be the reason of the problem and here (here it would be easier to declare it outside of the function) do you mean outside the class?
but thank you .
You're right, my bad. You removed the
static
afterpublic:
, that may be the cause (in general you should not change the signature of the functions from the initial code). I restaured the original signature of the function and movedpower
out of the class and the basic tests passed.y does the compiler throw an error for ArrayList list = new ArrayList<>(); ?
This comment has been hidden.
A problem with your code is not a kata issue, please read this: https://docs.codewars.com/training/troubleshooting/
Then you haven't passed all the tests. Your if condition is wrong.
This comment has been hidden.
Can you prove this is an issue with the tests and not your own code? The submission tests are broader than the sample tests. It seems more likely that your code isn't handling one of the submission tests properly -- check the provided input by
print
ing it to the console.Sorry, it's not a kata problem but a flaw in your code. Print the input to see what happens.
I cannot figure out how to calculate k.
algebra k = total/n
This comment has been hidden.
Why does it give tis error : error: unresolved reference: pow sum += (listOfNumbers[i].toDouble().pow(p + i))
I am trying to use the "pow" funtion. why does it say unresolved reference: pow?
You have to import it before you can use it.
I think the method 'pow' belongs to the Math class. It's static so you invoke it like this 'Math.pow(someInt,someOtherInt)' And it needs two parameters, no? The Math class lives in java.lang so you don't need to import it. Apologies if you're thinking of a different pow method.
import here? how? I am using kotlin language
Math.pow(x,y) in JAVA. in kotling we do x.pow(y)
nope, you still need to do
import kotlin.math.pow
This comment has been hidden.
I assume it means that somewhere in your code you divide by a variable that has 0 as value.
In your code,
n
is always0
since you have modifed it. You should store a temporary variable forn
beforehand.Hello Community,
When I do the tests I pass them all. When I submit the code I pass most of them except 3. I thought the problem was that the value of n were floats and I adjust the code accordingly. However I keep getting the same errors. When I run the code in my computer with those values, assuming the values are referring to n, my code works just fine.
Any hints?
3263.10819218804 should equal -1 1.464758190332126 should equal -1 9400.896936434361 should equal -1
Could you share your code?
solved it, thanks though.
I'm passing all tests except the three you mentioned. Any tips?
This comment has been hidden.
This comment has been hidden.
You divide everything by
n
and you getk
.k
must be an integer.Chrono79 - Thank you, you really helped me. I did it!
For C (probably others)... the Kata description says nothing about the input except that
n and p will always be given as strictly positive integers.
, but given some largen
and largep
IMO this kind of algorithm could easily overflow just trying to figure the sum. The description should say not to worry about overflow because the input will always be kept to some sane values.I will let you modify the description according to your taste. Personally I do not see the usefulness of it since there is no problem on the subject (more than 73000 people passed the kata).
This comment has been hidden.
Your code returns floats, it's your code's problem, not a kata issue.
The tests are fine.
This comment has been hidden.
I have passed all the test casess except for the 4th test . the output says :-1 should equal 9
Is there any way to know the parameteres passed to the function for this test. It my help me to resolve the issue.
Any inforamtion is much appreceiated. Thanks in advance
You can print 'n' and 'p'
OP solved it, closing
This teaches some valuable lessons. Unfortunately, it seemed to be primarily through frustration. Not the best teaching method. Some more rounded sample tests hinting at the esoteric quirks being highlighted would be a large improvement. Where there is a whip there is a way, but gentle encouragement is a better choice IMHO.
probleme with submitting my code
What kind of problem?
This comment has been hidden.
This comment has been hidden.
Made it in 72 chars. Can some one do it shorter?
This comment has been hidden.
uuhhh I see what you did there. That's pretty cool
I honestly don't understand where the problem is? If I have to learn something and I show the code someone should tell me where the problem is, or I have to waste time hours and hours and not understand anyway what I'm doing wrong... maybe here is too advanced for me
You can post your code here so we could check. See here how: https://docs.codewars.com/training/troubleshooting#post-discourse
You can also try searching for easier kata: Kata Search Page
I am getting all correct answers in terminal but still all cases failed . Can someone help (Using Python)
You'll need to be more specific than that...
Otherwise, we can only provide you links to articles like this one: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Thanks for your help , I was using print instead of return thats y. All cleared now
This comment has been hidden.
This comment has been hidden.
I'm playing around with digits ;) but I always seem to have an error with the line: 'number = Convert.ToInt32(str);', even though other katas and pages show that this is a correct line for c# code to convert text to integer. I believe its the last error I have but I can't seem to solve it. Could anyone help? Thanks! (Error: The name 'Convert' does not exist in the current context)
Convert
is in theSystem
namespace, so you have to defineusing System;
at the top of your solution. Note that you can also useint.Parse(string)
.nice kata!
This comment has been hidden.
⠀⠀⠀⠀⠀⠀⠀⠀
This comment has been hidden.
You don't have to put code even if you are a new new one at CW. It is forbidden without the spoiler tag and it has no interest.
This comment has been hidden.
This comment has been hidden.
Not all are flagged, the ones that are flagged, do include spoilers.
The example which expects -1 should be like this: digPow(92, 1) should return -1 since there is no k such as 9p + 2p+1 equals 92 * k
is the current description ok ?
No, the value of p is set to 1 now in that example, and p could be another value.
but
p
is not a free variable, it's a parameter of the function... i do not understand your point. it isk
that we have to find,p
is a givenwhat am i missing ?
Nevermind then, I thought p was not a given value, it's fine now.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
anyone who have trouble to solve this kata you are not dumb,read the desc again and again. i believe youll fin your AHA moment
error: expected 'in' after for-each pattern for res=0 don't use "for" when trying to pass parameters in Swift, otherwise tests won't work
I don't understand your issue. I am not the Swift translator but I don't see any "for res = 0" in the translation... Maybe there was one in your code? Moreover note that you passed the Swift kata as 478 other people.
well, it was really an error in my code, but still, using "for" or other words in the programming language to pass a parameter into a function isn't the best practice
Named parameters with labels? Though "for" might not be the best choice...
This comment has been hidden.
It will be taken into account. Thanks.
And I was playing with digits And I didn't know what it meant.
I dont know how to resolve the runtime error my code is working fine in my machine but when i test it in the webpage it is showing runtime error btw im using c
IMO when you choose C you are volunteering to debug some more difficult stuff. If I were you, (and I'm no C expert or anywhere remotely close), I would aim to reproduce the situation. This starts with printing out what your function receives as input. It is somewhat likely that you're only interested in the input you received before your code crashed. You'll want to flush your output, because otherwise your output may still be in a buffer when your program crashes and therefore not be written. Then you'd use that input locally. If that runs, then it might be that you are relying on undefined behaviour. It would be a good idea to run it using something like asan or valgrind to check for problems. Before doing anything else, make sure you have turned on all reasonable compiler warnings and that none remain. You may also want to use the same compiler, presumably that's clang. If for whatever reason you're on windows then maybe you're using their special snowflake compiler and that'd be a good idea to toss out. repl.it uses clang, you might be able to use that (idk whether asan is available and usable there, though)
You know, or get good and write perfect code, I guess. I sure don't.
Also, don't underestimate good old printf debugging. You should be able to figure out when and where the crash happens using that. (again, make sure to flush anything you write)
I work on Windows because reasons and first thing I do when looking for a cause of a crash is to copy the code to my Visual Studio and run it in Debug mode. I am yet to find a situation when invalid memory access does not trigger one of runtime checks ;)
Yeah but, I wouldn't want to miss an opportunity to pick on windows.
But that's probably a great option for memory problems. A bit less so when it comes to sticking to standards. Maybe they rely on something being zero'd or maybe there's a non-standard header in there or wrong standard being used to compile. More similar is better.
While I totally understand taking every possible opportunity to pick on
JavaScriptLinuxWindows, I am not sure I follow "not sticking to standards"? Do you mean that VS compiler poorly conforms to current C standard, or that mechanisms for runtime checks are "nonstandard" (whatever would it mean)?VS adds a header of its own doesn't it? To new projects I mean. New coder downloads VS, creates a project. They get a weird header. And then you've got compiler flags which are probably being set to some vsc flavour. And then standards aside, they may behave differently for undefined behaviour.
Ah, that's what you mean. Yes, default project template adds a precompiled header to new projects. You can disable it in "Create project" wizard, or use another template. But you are right, this can get annoying. I got so used to this that I've already forgot about it ;)
BTW many other compilers support precompiled headers too and you can choose to enable them. But they are not added automatically to new source files, because usually you do not use file templates.
This comment has been hidden.
Your first while is an infinite loop. Please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
While I test- it shows "All tests Passed", but when I attempt, it shows error in 5th. All above 4 are shown as passed. Can anyone guide me what's wrong here? (code writen in C)
Not a kata issue. Please look at the top of the page to see how many guys passed the C Kata.
Ya, got it. Problem was in my code -last condition whether k is intiger or not. Thannks!!
请问一下测试用例12933的问题怎么解决,我搞不定! expect12933,but was-1;
what is your p value for testing? I tried on several p value for n = 12933 and keep getting -1. what is the issue?
Failed Test 5, 14, and 15. Each one is expecting -1 to be returned. I got 3263 for Test 5, 1 for Test 14, and 9400 for Test 15. If someone that finished and has the test cases can steer my in the right direction I'd appreciate it!
Your code receives the inputs you're asking for, you could print them.
so simple and genius, didn't think about it.
Syntax-wise and logic-wise, this part is wrong
the range of N is not given, how am I supposed to find out how many digits are there in n?
Only way: calculate it.
calculate it with snprintf for example
How can i solved!
This comment has been hidden.
Beginner's katas are 8 and 7 kyu.
Ok, what does that mean?
Kyu is the ranking system of users as well as the difficulty level for kata in codewars. New users start at 8 kyu and gradually go up as they complete more kata. Kata are tagged with difficulty levels also measured in kyu (the easiests marked 8 kyu), which can help users decide whether a kata is too difficult, too easy or the right level for them. Usually kata of 8 and 7 kyu difficulties are considered beginner level kata, they are relatively easy.
I got an headache reading own code lol
I am horrble at writing "Pythonic" code. Everyone else's solution is much more elegant and short.
Don't feel bad is a good practice see the others solutions. You can try refactor your solution and write the code in a more "Pythonic" way.
I can't believe I solved this, lol.
This comment has been hidden.
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
having same issue. i tried to print n and p in code but it seems it only prints if test is passed
When I first read the question, I thought there was no way this is a 6kyu. Took me a couple of tries before I realise I'm not searching for a pattern and that p is given.
thx i hadnt got tf is p lmao there is no explanation
Same!
I passed 29 test and failed 3.
I don't know what I am doing wrong. It says something like the result should not be -1.
I believe my code is correct on the part that returns -1. I don't know what is wrong.
See if this paragraph helps.
Print the input to see what happens.
Thanks guys...
I already passed the 32 tests after adding the
else: return -1
my bad XD.
why the first test are freaking hard!
I found that there is a mistake in the last two test you put up. dotest(46288, 3, 51); dotest(114, 3, 9); 51 and 9 are not valid results !!
Thanks, Jorge
Both tests are ok, the first one is even explained in the description. Remember to also mention the language you're talking about when reporting an issue.
hi please how can i convert each char in a string into integer ?
Depends on the language... Look into something called "TryParse()"
check google
-1 should equal 12933
This comment has been hidden.
Hwo to find K????
I think you're a genius.
In my compiler (c language) i get the results for all tests: result: 1, expected: 1 result: -1, expected: -1 result: 51, expected: 51 result: 9, expected: 9
I pass the first test, but at atempt: passed: 9, failed: 1?? what the hell is going on... i reviewed my code 10 times, i dont have logic nor sintactic errors.
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Why cant i use Math.Pow in C#? whats the problem
We have no idea.
This comment has been hidden.
A few suggestions:
Which runtime are you using? Mono, C# 7.3, or C# 8.0? Best to use C# 7.3/8.0 rather than Mono, so check this first
Have you got your using statements in there? To use
Math
as you have, you will need anusing System;
statement at the top of your solution.The above suggestion should work, but you can also do a static import (
using static System.Math
) which will allow you to drop theMath.
before calling functions in that classTy, forgot about namespaces!Have a great day!
This comment has been hidden.
Your code only returns -1, it prints other values. Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
You dont have to "print" but to "return".
thank you both for the tips!! i've passed! =)
Nice solid kata.
Time: 758ms Passed: 31 Failed: 1 Exit Code: 1 JavaScript
I don't know what is happening with the last test :(
This comment has been hidden.
I have a solution using C that works when compiling on my computer, yet it's marked as incorrect when submitting it on codewars. Particularly for the tests n = 46288 and p = 3 and n = 114 and p = 3. I have checked on my computer that it returns the correct answers, but the codewars tests signals it returns -1. My solution used the <math.h> library and is recursive, could this have something to do with my code not working on codewars?
If your code is correct, recursive or not, it should work on CW. Note that 1215 people passed the C kata.
Yes, I know! That's why it's so weird that CW doesn't accept it. As I said, I compiled it on my computer and it gives the correct answers, that's why it's so weird. I'll take a closer look at it and if it doesn't work I'll just code a different solution. I'd still like to know why it isn't working, though. I'll write if I find the issue. Update: Found the issue. It had to do with static variables. My code worked for one value at a time but didn't "reset" static variables to work for the next one.
In other Katas, I've had issues with getting CW to recognize recursion. I had to redo my entire solution to not be recursive just so it would work in CW.
Are there not some standards for describing problems?
After reading the problem and pondering for a few minutes, I immediately came to discussion to see if there was any good discussion on articulating the problem more clearly.
My primary issue with the write up is that there are 'leaps' between each of the sections, and it's not clear what the leaps are because of the way the problem is organized.
Basically, I felt dumber for reading the problem. And now that I understand the problem, I didn't have an 'aha epiphany'. I had an epiphany that the problem is poorly constructed.
My solution (JavaScript) worked but it says it took too long and I need to optimize it. I am so new to this I don't know where to start to make it run faster; anyone have a good (beginner-friendly) resource they'd like to recommend?
Read about functional programming, there must be some good posts in the internet, maybe is related with that, and how functions the memory on a computer. Maybe you where using a loop that makes really difficult to process your code. I don´t know how to explain myself, because i´m learling this things too, but i think that your problem goes in that way.
This comment has been hidden.
Hi,in Javascript I think there is problem with the testing because when I press attempt all the tests are good except for one. The number 135. In the log it awaits a -1 but it should expect a 1 because 1^1+3^2+5^3=135 and so 135/135=1 so I have no idea why it is expecting a -1. Also for some reason my code returns a 51 on this exact number. Even tough when I console.log it it shows a 1 so what is happening here?
More 16,000 people solved this kata in Javascript so I think you're wrong somewhere. Please check again.
Solved it! I had the problem in my code.
This comment has been hidden.
This comment has been hidden.
I am having difficulty in solving this problem Passed: 29 Failed: 3 Exit Code: 1
3263 should equal -1 1 should equal -1 9400 should equal -1 I am running the codes in python
When solving katas like this one, I see many people using strings, which generally results in a shorter and maybe more pythonic code. I try to solve the problem mathematically, ie integers stay integers throughout and performing the needed operations on them. I'm more concerned with style rather than performance, and would like to read some opinions and recommendations.
Maybe this kata will show you why sometimes it's better to work with strings than to do it mathematically: https://www.codewars.com/kata/59a2af923203e8220b00008f
This comment has been hidden.
This comment has been hidden.
that is a fucking genius. Thanks man
This comment has been hidden.
OP solved it, closing
This comment has been hidden.
This comment has been hidden.
Time: 1067ms Passed: 2 Failed: 1 Exit Code: 1 Test Results: digPow ShouldPassAllTheTestsProvided Test Passed Test Passed The expression (act) == (exp) is false. Completed in 0.8660ms Log Error. Expected 51 but got -1 Completed in 0.8660ms
I'm having a bit of a problem with my code. I keep getting this error!
UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: FPE on unknown address 0x000000427cdc (pc 0x000000427cdc bp 0x7ffd6868e1d8 sp 0x7ffd6868dd90 T1) ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x427cdb (/workspace/test+0x427cdb) #1 0x42660e (/workspace/test+0x42660e) #2 0x426192 (/workspace/test+0x426192) #3 0x425d4b (/workspace/test+0x425d4b) #4 0x42a085 (/workspace/test+0x42a085) #5 0x42546d (/workspace/test+0x42546d) #6 0x7f3116f71b96 (/lib/x86_64-linux-gnu/libc.so.6+0x21b96) #7 0x4043e9 (/workspace/test+0x4043e9)
UndefinedBehaviorSanitizer can not provide additional info. ==1==ABORTING
I tried several passing solution without any problem so it is not a kata problem. You should try to debug your code with some printing to see where your code is wrong. Maybe you could read https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution.
same thing here... seems to be something related to the pow() method.
Does anyone know how to handle the last test? "12932 should equal 12933" dont really understand where I meesed up in the code...
Doesnt matter. Solved it. Had problem with rounding.
Hi Zodder!
If you can remember, do you mind letting use know what the rounding problem was? I'm having the same issue with my code. Thanks!
I am sorry. I kinda forgot already. But it was about rouding. Can you share your code so I could remember (mark it as spoiler)? :D
This comment has been hidden.
Why would it return anything else, when you have "return -1" in your code?
.
When I test my code, it work perfectly, all the tests were approved, but when I try to attempt my code, then it throws another test I supose, it says "The expression (act) == (exp) is false." the output windows looks like this:
Test Results: digPow ShouldPassAllTheTestsProvided Test Passed Test Passed Test Passed Test Passed The expression (act) == (exp) is false. Completed in 231.5164ms Log Error. Expected -1 but got 69594204
I dont know why
you didn't pass all the tests provided. the tests stop at the one you failed, where the error message says you returned
69594204
when it was expecting you to return-1
but there are only 4 doTests, and then there are no more tests, when I click test, there are no errors, it worked perfectly, but when I click attempt, it says that there is one mistake, that is the one that I give up there, but I dont know where because in the main there is only four doTests, I dont know where is the another one :'((((((((
even when i test my code, in the output window on the bottom says "You have passed all of the tests! :)" but it dont seem like that when i click attempt
You have only passed all the sample tests. There are additional tests at the ATTEMPT stage. Your code must be ready to handle all conditions. The hidden tests usually are more difficlt and test for things not in the sample tests. Then there are also random tests beyond that.
Passed: 29 Failed: 3 Exit Code: 1
3263 should equal -1 1 should equal -1 9400 should equal -1
How to see the full list of tests? I can’t understand what start with which parameters led to the error.
Print the input.
deleted
i have the same problem, i don't understand why 1 should equal to -1. Can anyone help?
This comment has been hidden.
You must have an infinite loop, but it's hard to read your code if you don't use markdown formatting
i fixed it. thanks anyway.
This comment has been hidden.
That's a problem with your code, not a kata issue, print the input, check why it fails. Also, when posting code, use markdown formatting so the code keeps indentation (important in Python)
P.S.: delete the other post while you can.
This comment has been hidden.
This comment has been hidden.
When you post code mark it as "Spoiler" (I did it for you).
You have an infinite loop.
Ohh thanks for marking spoiler for me I checked again and found why my loop was infinite :' thanks a lot
@g94 I have made a PureScript translation. Please take a look.
This comment has been hidden.
Rejected by someone
This comment has been hidden.
See at the top of the page: 5525 guys passed the Java kata so chances are that your code is wrong. If you want to know where you fail, print the input.
I didn't say the kata or the test is wrong, I'm asking what the problem is. I have done tests and it works, that's why I asked. You could have minded your own business if you didn't want to help.
Well, if you wanted to ask a question, use
QUESTION
tag. Issue means something is wrong with KATA itself - usually wrong tests.How could the AUTHOR of kata ignore a raised issue and just mind his own business?!?!
I solved this long ago, so I don't really remember the details, but your solution only fails 1 test, and that's because your check for invalid k seems to be flawed. I can only suggest the use of modulus operator, and you shouldn't use
p
when checking for it.I didn't give much thought before posting as issue, what I meant was "I have an issue with the code, do you know why". Last time I posted somewhere else as question and the post got hidden without an answer so I thought the tag was wrong. Thanks either way.
A suggestion to help clarify the description:
"We are looking for a number, k, that when muliplied by the input, n, is equal to the sum of it's constituent digits, a, b, c, ..., raised to consecutive powers starting at p."
Then add "where a, b, c, d, ... are the digits that make up n" to the end of the "other words" portion.
The current wording does contain all the info needed to solve the problem, but I (and many others judging from the comments) had trouble figuring out what was required initially. I think adding a few choice words like in my suggestion would help clear things up a little.
done
I run my code in a separate IDE and it works. For example, dig_pow(46288, 3) will return 51 in my IDE, but not here. Can someone help?
are you returning or just printing?
Just returning
what does it return here instead of 51? is there any error message?
Shows that it returns -1
is your IDE in Python 2?
Tried in both Python 2 and 3
post your code with proper markdown formatting, (tag as spoiler), maybe can help. just curious why you're using an outside IDE? so: are you sure you copied the tests over to that environment accurately?
Found out what the error was. I needed to delete all items in my list during every call to the function. Thank you for your time!
you are welcome, happy coding
This comment has been hidden.
the same problem with me too.my mistake was that i forgot to set certain variables equal to 0; when declaring global;like sum = 0 etc.
This comment has been hidden.
The log appears above the test result, you're confusing the log of one test with the expected result of another.
Sorry, this is just incorrect composition of my question. I understand that but it doesn't change the fact I do not know how to deal with that errors. I am sure my result is correct. On the other hand, if it was correct, it would not generate errors. Don't know what to do with it anymore...
Check again which tests your code isn't passing:
Add those numbers, divide them by the original number and you won't get 3263, your code is truncating when it shouldn't be.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
You have to return not to print.
This comment has been hidden.
Could you explain how "12, 88, 816 and even 1180344 (and of course, 2360688 itself)" are also solutions of
digPow(46288, 3)
? I think you're not understanding what to do, the solution is unique or doesn't exist (in that case you have to return -1).n
doesn't need a limit, a single value is passed to you (as it isp
), you have to work with that, nothing more.k
is what you have to find.This comment has been hidden.