7 kyu
Target Date
420 of 3,257g964
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.
Confusing at first but pretty good!
Tricky one as usual, but really good one!
No offence, but when I see the kata of this author I just skip...
Is that true: a0=3878 a=4977 p=6 Expected: equal to "2020-02-07" Actual: "2020-02-06"
C fork
Thanks again !
python new test framework + improved random tests
.
say what you want but details are terrible.
Im super lost with this one. In the example of dateNbDays(100, 101, 0.98) i get an answer of 368 days instead of 366 days. I can not figure out the problem. In my understanding in 360 days the interest is going to be 0.98 so in total after 360 days there is going to be 100.98 in the bank. On day 361 from 100.98 i will start counting interst of 0.98/360(per day). Which makes 100.98*(0.98/36000)= 0.0027489/day of interest. So after 366 days I get 100.9964934, after 367 I get 100.9992423 and only after 368 days I get 101.0019912. Please let me know where my logic is bad as I can not see it. Thank you!
So as many I figured it out that it was not a yearly compound but it was daily compound. Every days interest has to be added before calculating another days interest. Then it all adds up.
Description is wrong;
p
is NOTp percent divided by 360 per day
, but an amount that needs to be divided by 360x100 per day.Banks give a rate in percent for a year of 360 days. Moreover what is the difference between "p percent divided by 360 per day" and "an amount that needs to be divided by 360x100 per day"? I don't see there any issue. No offense.
Is this daily compound interest or annual?
Daily. Every day you get p/360 percent to the amount in your account. Yes, in a calendar year of 365 days you will accumulate more than p.
parameter $p in powershell solution should not be of type int
That doesn't matter; in Powershell it is given as an int in all tests.
The satisfaction rating said a lot. Not worth your time.
You could have mentioned compound interest in instructions!!!
This comment has been hidden.
OK. Approved.
This comment has been hidden.
Great.Thanks!
Thanks!
I have a big request for all kata creators. Please, make up the description of the tasks so that their interpretation would not be painful. We are gathered here to solve mathematical, algorithmic and programming problems, and not solve dictionary puzzles.
Why does this not have time/date tag?
Is date/time a tag? Moreover "date" is in the title.
Yes,
Dates/Time
is the exact spelling. Tags help exercising specific task fields.C++ version generates warnings.
Hopefully fixed.
It's misleading to say "a constant interest rate of p% > 0 per year": as already pointed out, with a daily rate of p%/360 you'd get (p%/360)^360 yearly rate (for a year of 360 days). Please take this out, just say "interest rate of p%/360 per day". As it stands, the terrible description of the kata makes for a miserable experience solving it.
The formula to take into consideration is given:
If p% is the rate for a year take the rate for a day to be p divided by 36000 ; banks consider that there are 360 days in a year.
Nevertheless I will simplify the description. Sorry for your "miserable experience solving it".
This comment has been hidden.
OK. Thanks!
For those confused, when the kata description says that "The bank considers that there are 360 days in a year", it means that every 360 days you recieve the full interest. This means that you will have had the full yearly interest rate on the 26th of December, and that you actually recieve MORE THAN the interest rate over the course of a 365 day calendar year. No days are skipped and all the months are the same length as they are in the Gregorian Calendar.
I've forked the Rust translation in order to update it to Rust 1.49 and updated
rand::Rng::gen_range
to its new signature that takes astd::ops::Range
.Approved.
For everyone who are suffering to solve this kata.
Maybe it should be specified that p/36000 is NOT the right way of going from an annual interest to a daily interest. That indeed, it is a simplification to make the kata easier.
This comment has been hidden.
I just get this when trying to submit or run sample tests
Even submitting a simple function
(defn date-nb-days [a0 a p] 0)
Results in below:
Exception in thread "main" java.io.FileNotFoundException: Could not locate dateamount/core__init.class or dateamount/core.clj on at clojure.lang.Compiler.load(Compiler.java:7391) at clojure.lang.Compiler.loadFile(Compiler.java:7317) at clojure.main$load_script.invokeStatic(main.clj:275) at clojure.main$script_opt.invokeStatic(main.clj:335) at clojure.main$script_opt.invoke(main.clj:330) at clojure.main$main.invokeStatic(main.clj:421) at clojure.main$main.doInvoke(main.clj:384) at clojure.lang.RestFn.invoke(RestFn.java:408) at clojure.lang.Var.invoke(Var.java:379) at clojure.lang.AFn.applyToHelper(AFn.java:154) at clojure.lang.Var.applyTo(Var.java:700) at clojure.main.main(main.java:37) Caused by: java.io.FileNotFoundException: Could not locate dateamount/core__init.class or dateamount/core.clj on classpath. at clojure.lang.RT.load(RT.java:456) at clojure.lang.RT.load(RT.java:419) at clojure.core$load$fn__5677.invoke(core.clj:5893) at clojure.core$load.invokeStatic(core.clj:5892) at clojure.core$load.doInvoke(core.clj:5876) at clojure.lang.RestFn.invoke(RestFn.java:408) at clojure.core$load_one.invokeStatic(core.clj:5697) at clojure.core$load_one.invoke(core.clj:5692) at clojure.core$load_lib$fn__5626.invoke(core.clj:5737) at clojure.core$load_lib.invokeStatic(core.clj:5736) at clojure.core$load_lib.doInvoke(core.clj:5717) at clojure.lang.RestFn.applyTo(RestFn.java:142) at clojure.core$apply.invokeStatic(core.clj:648) at clojure.core$load_libs.invokeStatic(core.clj:5774) at clojure.core$load_libs.doInvoke(core.clj:5758) at clojure.lang.RestFn.applyTo(RestFn.java:137) at clojure.core$apply.invokeStatic(core.clj:648) at clojure.core$require.invokeStatic(core.clj:5796) at clojure.core$require.doInvoke(core.clj:5796) at clojure.lang.RestFn.invoke(RestFn.java:421) at dateamount.core_test$eval4$loading__5569__auto____5.invoke(test.clj:8) at dateamount.core_test$eval4.invokeStatic(test.clj:8) at dateamount.core_test$eval4.invoke(test.clj:8) at clojure.lang.Compiler.eval(Compiler.java:6927) at clojure.lang.Compiler.eval(Compiler.java:6916) at clojure.lang.Compiler.load(Compiler.java:7379) ... 11 moreclasspath., compiling:(/home/codewarrior/./test.clj:8:1)
Before your function you must have:
to have the "mamespace".
Please update to Julia 1.0.
.
If p% is the rate for a year the rate for a day is p divided by 36000 since banks consider that there are 360 days in a year.
Shouldn't this be
p divided by 360
? Dividing the rate by 36000 will give you the percentage rate for every 100th of every day rather than every day alone.I see your point, but 2 percent is not really 2. 2 percent is actually written as 0.02.. so you need to divide 2 by 100 to get 0.02 as a result you need to do the following interest per day in decimal = (360 * 100) = 36000
By the merit you offered, using the instructions:
rate for a day is p divided by 36000
rate for a day is .02 / 36000
That is incorrect.Let us instead say:
rate for a day is p divided by 360
rate for a day is .02 / 360
That is correct.Your point supports mine. Much appreciated.
This comment has been hidden.
In my opinion "p" argument should be float type as an integer makes no sense in this context.
This comment has been hidden.
Please stop with variables like a1, p, x, p0...
It does not make sense, it's not readable and fosters bad practices for beginners.
Why just don't say that p/36000 is rate per day? Please, whoever solve this kata, don't think of p as of yearly interest rate!
leap years?
It was really difficult for me to understand this kata. I had been thinking about it for three days. I understood only when I read the comments. Thank you for kata and for hints.
I am attempting this kata and is very confused by a few things
Great Kata, introducing me gently to a couple of new concepts - simple maths means the focus is on correctly using and formatting the date!
The rate is paid daily and added to initial capital.
And this is not clear from the description - should be added to it.
Did you notice this in the description:
Just to point out that there is an error in your definition: the daily interest rate is the 360th root of p / 100 rather than p / 36000 as stated in the problem description.
Applying p / 36000 for 360 days doesn't yield the annual interest rate of p%.
This bank doesn't consider compound interest: its definition is the one given above.
This comment has been hidden.
The only way to make the test cases work is to consider compound interest on a daily basis, with the artificial daily rate p/360. No bank works like this in practice, so this kata needs A LOT more description.
2/7/2019 To anyone trying to solve this kata, the comments above are what you need. Essentially use "compound interest on a daily basis, with the artificial daily rate p/360". This would have been a good kata if this had been adequately explained.
Just to clear: 360 banking days doesn't mean that the same must be used at the end date calculations? I mean the dates must be "real", including leapyear consitions etc? Because I got right days quantity, but not right end date, calculated with:
p.s. dateNbDays(100.0, 101.0, 0.98) means 01/07/2017 with 360 days calendar, and not 01/01/2017 as in sample test.
Maybe you should adapt your code, be sure that there is no error in the test. Cheers!
still there is a question - how many days must be considered in a year for end date (not interest) calculations - 360 or 365/366? p.s. I do understand it should be as in a real life, but have doubt that interest is calculated within 360 days and end date must be added from 365/366 days/year.
As in real life. Use
date
functions of your language.Yes, it is banks:-)
[Clojure] Run tests: ok Submit: java.lang.RuntimeException: Unable to resolve symbol: ft in this context, compiling:(null:24:30) whole stacktrace https://gist.github.com/anonymous/82dbad1be4b80a4141cab11ea2dbe847
OK, a bad spelling in the random tests but for the time being CW doesn't let me re-publish the Clojure tests. So I added that line in the preloaded section:
(def ft (java.text.SimpleDateFormat. "yyyy-MM-dd"))
. It should work. Could you try? Thanks for your post!Thank you.
it was unclear if the percent should update previous..
This bank is a good one:-)
once again...
from 2016-01-01 to 2035-01-01 = 19 years, right? from 2016-01-01 to 2036-01-01 = 20 years, right? from 2016-01-01 to 2035-12-26 < 20 years, right? years | sum | interest 00 | 100,000 | 0,000 01 | 102,000 | 2,000 02 | 104,040 | 2,040 03 | 106,121 | 2,081 04 | 108,243 | 2,122 05 | 110,408 | 2,165 06 | 112,616 | 2,208 07 | 114,869 | 2,252 08 | 117,166 | 2,297 09 | 119,509 | 2,343 10 | 121,899 | 2,390 11 | 124,337 | 2,438 12 | 126,824 | 2,487 13 | 129,361 | 2,536 14 | 131,948 | 2,587 15 | 134,587 | 2,639 16 | 137,279 | 2,692 17 | 140,024 | 2,746 18 | 142,825 | 2,800 19 | 145,681 | 2,856 20 | 148,595 | 2,914 21 | 151,567 | 2,972
to get 150 it needs more than 20 years can someone pls explain whats wrong with my calculation?
Hello, I'm confused... and can't find my fault - please help!
As an example you give "date_nb_days(100, 101, 0.98) --> "2017-01-01" (366 days)". After a year: 100 -> 100,98 (100 * 1,0098 or 100 + 100 * 0,98 / 100 ) and 360 days. InterestsPerDay now: 100,98 * 0,98 / 36000 = 0,0027489. days / sum 361 / 100,9827489 362 / 100,9854978 363 / 100,9882467 364 / 100,9909956 365 / 100,9937445 366 / 100,9964934 367 / 100,9992423 368 / 101,0019912
other try: 0,02 / 0,0027489 = 7,2756375277383680745025282840409
Can you please explain, how you came to 366 days?
so until that you compound annually
and then daily...
Try to compound always the same way.
So by banks logic "in a year" means in 360 days...and it means that 6 more days are coming to finish a calendar year.
when I compound only daily, it's the same result: interestsPerDay = 100 * 0,0098 / 360 = 0,00272222222222222222222222222222 days = 1 / 0,00272222222222222222222222222222 = 367,34693877551020408163265306152 why is the answer 366 days?
linlux's calculation, i.e. "interestsPerDay = 100 * 0,0098 / 360 = 0,00272222222222222222222222222222" is not correct because interest per day is not a constant.
I think it may be helpful if you re-word the description, because it implies that the amount a0 is deposited every year. I would suggest that you phrase it as "You have an amount of money a0 > 0 and you deposit it on the 1st of January 2016, with an annual interest rate of p% > 0" This should help clear up the ambiguity in the first sentence. The reader can discern the intended meaning currently, but only because the date includes the year and thus an annual deposit wouldn't make sense. Also, you should add "compounded annually" or "compounded daily" to the end of that first sentence. Banks traditionally tell customers the interest rate in the form of the APY, which is annual, but the real interest rate is continuously compounded. So, it may be easier if you explicitly state how often it is compounded, because our banking conventions have separated the compounding frequency from the advertised "annual" rate.
If daily rate is p/36000 than how can we get a right amount in 366 days with a daily added rate? (read "360 is not equal to 366").
How is the interest added -daily, monthly, quarterly or yearly?
Hint: ignore the calendar year concept.
[Python] Run Tests: all OK Submit: all ok until 100 Random tests and got this, TypeError: descriptor 'date' requires a 'datetime.datetime' object but received a 'int'
Seems a syntax issue?
I tried a few different solutions and all worked fine. Verify your code and see if you import what is needed.
Furthermore, before posting an issue see the other comments (e.g @tchar, just below).
thanks. Will verify my code again.
P.S. @tchar's comments are hidden before I could find a solution.
@tchar said: "Solved by using: from datetime import date,"
This comment has been hidden.
Please which language? I don't understand very well your problem:-(
The 360 days are there only to calculate interest because banks act like this; otherwise they use like everybody else calendar dates...
What do you propose for the description?
As for the "import" it is up to the Codewarrior to import what he needs, no?
This comment has been hidden.
In the Notes, you should probably clarify that the daily percentage p/36000 also includes the conversion p/100 for converting the interest from a percentage to a multiplier.
You also have a typo under Task, there's an extra "d" in "(or dateNbDdays...)".
Typo corrected.
I hope that everybody knows that 36000 is 360 * 100 :-) Thanks for the feedback!
The title should be more descriptive.
What do you propose? It seems that is more a suggestion than an issue:-)
Sorry, I didn't actually mean to open an issue, CodeWars did that for me. How about "Calculating target date for compound interest"?
Thanks for your good idea! But 1) I like short title and 2) This kata is more about date (hence "When?") than about compound interest which are already well covered by other katas. If you agree with that I will try "Target Date".
Sure, it's your kata. Sounds good to me!
How about adding the 'date and time' tag?
Date is in the title!
For Java I'd recommend to use the Java 8
java.time.LocalDate
(https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html) and notjava.util.Calendar
or evenjava.util.Date
.Why that? There are no historical dates.
What do you mean by no historical dates? Well at least for this Kata LocalDate makes things way easier (you can solve it in a single line).
I guess Calendar has its uses but most of the time I'd say LocalDate will do just fine. Basically I wanted to point out, that with Java 8 LocalDate has been introduced so people who look things up don't just copy old StackOverflow answers where this wasn't the case.
Thanks!