6 kyu
Financing Plan on Planet XY140Z-n
869 of 4,888g964
Loading description...
Mathematics
Algorithms
View
Career Accelerator
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.
JS Node 18. should be enabled
Terrible description, after spending 20 minutes, I still didn’t understand what the author meant. What should happen in week 7? Zero? Again? It seems like it’s customary to use international units on the site, but the author starts the week on Sunday... Another Kata “Copy the formula from the Internet”
python new test frame work
Approved
This comment has been hidden.
C#: method name should be
PascalCase
(Please refer to implementation of backward compatibility here )Can someone explain how was the 1 liner solution formula calculated? I submitted my looped solution & I'm still not understanding the takeaway message here.
This comment has been hidden.
I've decided this task correctly. I see correct answer in compiler. But when i'm trying to test it here it shows me error "n := 365" Expected: "24513765" But was: "140732687806485" but in compiler i see correct answer. Why its happening. Help pls
COBOL translation updated to new test suite.
Done.
COBOL translation
Approved, thanks.
Another "find the right formula"? What does it have to do with programming?
I'm really noob at math, but this problem is like Number Pattern
I respectfully disagree that it's another 'find the formula problem'. The author explicitly noted that we try to solve it without using a loop. Obviously, we can solve it with a loop but we need to try to come up with another algorithm. This is about optimization and, believe me, it matters. A couple of days back I had an interview for a developers role where they asked me questions about algorithms and optimization.
This comment has been hidden.
Hello, you have an error in tests! to correct the error, it is necessary to perform n + 1 (examples do not match the description of the pattern). Or the conditions of Kata are not clear enough!
Sorry, no errors in the tests. Before posting issues look at the top of the page: 578 people (out of 3779) passed the Python kata.
Hello,
I have solved the Kata using recursion, but for some reason it doesn't pass the test even though it passes the test on Go playground and local development, could you check if it works properly?
What do you want to be checked? I saw that you passed the kata... Furthermore asking for something is not an issue, sorry!
Sorry, I think I am a little confused. Why is there so many blanks in this table? I feel like it doesn't make sense. What happens to all the money from the previous week? I am thinking, like if n == 3, you end the week with 3, but you don't start the next week with 3 but looking at w0 to w1 We ends with 3, but Su should start with 3 but going by the chart I start with 1. This is why I am a little lost on how the solutions came up with their solutions. Thank you
You should read the description and try to understand the table. If you begin by thinking that makes no sense you will never complete the task. Maybe take a sheet of paper, copy there the table and verify by hand the first given example.
That is not really what I am confused with. I am not sure if the table is a representation of the planet XY140Z-n or just a regular day. I thought that it is just a normal planet, which is why I was confused because I though it was for planet XY140Z-n. Sorry if i didn't make that clear enough. If there is a name for this type of question where I can do some research of my own it would be appreciated. For example in a previous Kata, there were linked-list questions, so I was able to look that up to further understand how it worked. Thank you
This comment has been hidden.
I suppose you fixed both issues. Thanks!
julia:
Very nice kata!
Thanks!
TypeScript 3.3 fails because types are not specified for variables in the fixture.
To update to 3.3 the kata has to be re-written... Feel free to update it...since you seem to have enough time:-)
Added types and replaced a class with static method wrapper with a function. This will invalidate existing solutions, but it's better than continuing to force unidiomatic solution.
If anyone is interested in helping to improve TypeScript support, see the list of TypeScript kata to update.
@kazk: Thanks!
There're no performance requirements in C, JavaScript, CoffeeScript, C++, C#, Go, Java, TypeScript (at least) at all.
Why do you want performance requirements?
Because the description literally says "try to avoid nested loops"?
And if you decide to remove the "performance requirement", then you'll have to update languages which time out with
O(n^2)
solutions like PHP.If I correctly understand you, I should have the same number of random tests in all languages?
Please, remove
O(n^2)
reference solution in Python and Ruby (at least). If you want to test the time complexity, increase the input range, but don't waste 85-90% of the allowed time to "take it away" from the user.Done.
This comment has been hidden.
post your code with a spoiler flag, plz.
Re-raised as a more meaningful issue.
Also, it turns out that you can pass the JavaScript tests with a
O(n^2)
solution, so the issue is definitely on your side.I can't even submit any solution. No matter what I do, it times out. Even when I told it to just return n, it still timed out. Is anyone experiencing this problem?
Same here. I also try just "return n", but the result was "timeout". In mine code is only one formula ( without any loops )
With R: I tried it with a single for loop, stored all the series of numbers in a list, then summed at the end. This always timed out. But then I realized, I did not need to save anything as I went, so instead used an integer and added to it as the loops went through. Using an integer to store the sum instead of a list got it down to 2200 ms.
I agree with everyone else, the description is not very clear.
This comment has been hidden.
Read the description N times, still couldn't get it. Looked at example, remembered doing something related at school. Blindly implemented mathematical solution and solved the problem.
Programming is != Mathematics, lecturers and teachers usually fails to understand this, it looks like similar problems are coming up to the surface in Codewars as well.
Absolutely agreed. The description is very uncomprehensible, it was a big time waste.
Then you do a bit of math above the examples, rule out a few incorrect ideas and you go test the idea that seems correct. After a minute of coding, done.
I don't even feel much satisfaction or gratification after this, I can just say this Kata is an utter garbage and an overrated waste of time.
Ok so after re-reading the description 5 more times, I think what the poster intends to convey is that 'n' is a variable that represents both the number of days and the number of weeks. Therefore the function only takes one argument. So n=99 would indicate saving for a 100 weeks with each week having 100 days...
holy wow ! how would one understand that from the description!
@Author can we please amend?
I have no idea from reading the description if the function I'm supposed to write accepts the number of weeks or the number of days in the week as the argument. Confusingly, they are both referred to as 'n' in the description, and the example showing how the function is to be used does not say what n is supposed to be.
Good kata. Try to figure out the pattern and get a formula.
But if there could be more specifications such as the detailed calculating process of finance(5), this kata will be better!
Does anyone have trouble getting this one to pass the final "Attempt" test? I keep getting SIGKILLs, but it passes the provided test in 1200 ms. I even ran the code locally and it takes at most 600 ms.
If it takes 1.2s just to run the sample tests, you'll run out of time for the random tests easily. (There are 25 random tests, and your time limit is 12s.)
If you read the descriptions carefully:
This is seriously confusing, why do you skip days while starting to save?
Edit: Also what? The 5 should return 156, which is 168-12 rather than 105.
same question
because you cannot simply subtract 12 to get the result for 5. You should subtract all the values of week 6. Yeah, I agree question is a bit strange.
This comment has been hidden.
First, Think about how many elements are in the triangle. First line of triangle has only 1 element, and second line has two, three.. until n+1. So, total counts of elements is the sum of 1+2+3+...+(n-1)+n+n+1. this can be solved by S = 1 + 2 + ... + n + n+1 S = n+1 + n + ... + 2 + 1 Add Two equations seperately(left plus left, right plus right) Then, it goes like this 2S = (n+2) + (n+2) + ... + (n+2) + (n+2) Then 2S = (n+2)* (n+1) and S = (n+2) * (n+1) / 2 After this, look at the triangle again. you will see the triangle has a special property. for example,
x x x 6 x x 4 5 x 2 3 4 0 1 2 3
sum of symmetric elements in the triangle become n. So, the above triangle can be rewritten like this
x x x 3 x x 3 3 x 3 3 3 3 3 3 3
Now, you already know how many n the triangle has. So the result becomes like n * S = n * (n+1) * (n+2) /2
This comment has been hidden.
This comment has been hidden.
Edit:
Puh quite tough. Found a more efficient way to generate the table with the saving values but still the Attempt always times out. This isn't a challenge for juniors, one needs to know quite a lot about clojure, in order to squeeze every last bit of performance out of it.
Hm when using pmap all tests pass on codewars but it still says it fails due to timeout, though the output says something else:
Sample test:
Always hitting the time limit with Clojure :/. And it looks like codewars doesn't like pmap. Locally in the REPL i can cut the time almost in half by using pmap. While using pmap it actually fails way more often on codewars, than with a normal map Oo.
Where savings returns a lazy seq of lists. With each list representing a week and the saving amount for each weekday.
Note that the performance of
apply
in the outermost form is the same as withreduce
. Though the anonymousreduce
fn in the innermost helps to improve performance a lot.No reason to post an issue!
This comment has been hidden.
Once again: Great kata! :-) To do it without nested loops is easier than to do with them. ;-)
Thanks!
Hi Steffen, Hope all is well. I am seriusly stock here, wondering if you can help with a couple of pointers.
Thanks!
@cnunez02: I suppose, the author of this kata (the great g964) would be better to help you with this kata, if you have problems. Maybe post your code (mark as spoiler) and tell him/us the concrete problems. :-)
This problem is very difficult to understand, I still don't understand what the question is. E.g. ".. after I save 12"... 12 what? days? weeks? units of money? Ah! It's after the saturday where I saved 12 units. Difficult to catch. Then there is a table of days with missing values... is it zero? And finally, what's the point of mentioning the planet? Just to number the weeks?
Sorry. I didn't catch the question. If It will be 168 while n=6, why it is 105 while n=5? On the W6 it got 12 so why 105? Why not 156?
This comment has been hidden.
Thank you. Your comment helped me understand how to solve the question.
I get the following error running my PHP solution: http://imgur.com/a/uMYng
It appears to be a memory issue or stack overflow, maybe? Granted, I solved it recursively so a "large" number could blow up the whole thing. Messing with the tests, the Codwars runner appears to handle N up to 199.
Do the submission tests use N = 200 or higher?
I think (I am pretty sure...) it is not an issue of the kata hence post it simply as a "Question" (see labels below the posts). Besides that I can't see your entire screeshot at imgur... It must be a stack overflow if you dit it recursively. N could be
5000
as you can see in the examples. Good luck!Thanks for pushing me to find a non-iterative solution! Fun stuff.
This comment has been hidden.
I think you should get rid of the "Su Mo Tu We Th Fr Sa" heading on the table, replacing them with something like Day 1, Day 2, etc. or calling them Zerosday, Onesday, Twosday, Threesday...Nsday, or really anything other than the traditional names for days of the week. It might also be a good idea to show the table for something other than n=6. By continuing to use the familiar 7-day week, it increases the chances of overlooking the instruction about the days being numbered 0 to n, and misunderstanding how the saving plan extends to values of n greater (and perhaps less) than 6.
I completely agree. This is undoubtedly a good kata but oh boy is the description confusing.
In C# all the 4 visible tests are passing and it runs fine in Visual Studio too, but when I click "Submit" I get the following error message:
Compilation succeeded - 1 warning(s)
{"stdout":"","stderr":"/tmp/csharp116429-21-ibjr83/fixture.cs(8,8): warning CS0414: The private field `FinanceTests.randomGenerator' is assigned but its value is never used\n","wallTime":0} Unknown error
This seems to be some type of bug that exists in the FinanceTests class that I cannot see. Could you please look into it? Thanks
With the previous version of C# at Codewars it passed but the new version is very strict... I suppressed the unused line, should work now.
hey:) the c# implementation sucks... The tests are written for int, and they fail if ulong is used. The tests after submint requre ulong....
hey:-( The tests didn't fail as far as I know; almost 40 people passed them without any problem and I just tried them with ulong: no problem!-)
Does someone solved it in ruby? I alway run into a timeout (6000ms).
Yes almost 20 solved it in Ruby.
This comment has been hidden.
I'm not really sure how to rank this one. Everyone has voted 7 kyu, because programmatically its not difficult, but its more along the lines of a puzzle and is certainly harder than most 7 kyu in terms of needing to undertand the solution. The author intended for it to be a 5 kyu. I just don't know what to do here. Would love to hear what others think.
Programmatically it's not difficult: maybe 7 kyu, mathematically it needs some work: maybe 5kyu. Tag it as "Puzzle", "Maths" and rank it 6 kyu:-)
The code needed for the solution needs a few lines of code, I agree. But there is a constraint of runtime, therefore two nested loops can't be used. It needs only a very well known formula of the sum of consecutive terms and how to apply it correctly. In my opinion this kata is in a 6 kyu level.
Please fogive me. I still don't get it, what about week 7, do you save anything on Sunday of W7? How to yield 252?
The table is for Week 0 to Week 6. Extend it in the two directions.
Thanks for your answer. So there would be a new column with 8 rows appending to the example table, the number from bottom to the top are 7 to 13 (8 numbers totally), so the total should be 168 + 80 = 248, why it's 252?
Don't forget to put something on the diagonal. Take a sheet of paper and draw the table. From 7 to 13 (7 8 9 10 11 12 13) I count only 7 numbers and not 8!:-)
ah, my bad, thank you for your answer. Both you and your Kata are my good mentors, highly appreciated.
Thank for your feedback, it was my pleasure!
in haskell the parameter is the number of the days+1
I must have said that in planet X the days are numbered from 0 to n, in the table they are numbered from 0 to 6 and finance(6) = 168, which is the sum of the total of the savings in the table. I modified the description, hopefully it should work, now. Thanks for the feedback, good point!