6 kyu
Bonuses
662 of 1,432g964
Loading description...
Fundamentals
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.
better assertion messages for C
approved by someone
I don't know about the other languages, but the rounding part of the kata in Lua feels somewhat 'random', the expectation should be mentioned in the Kata.
The kata includes only integers so you shouldn't need floats hence no rounding is needed and no expectation has to be mentionned. If you are using floats it is your problem:-) Cheers.
This comment has been hidden.
Nice kata, thank you. I don't think John is acting as fairly as possible though :) In real life the duration of the period, i.e. how many worked days, should also be considered. For instance if C was absent 12 days over a year they should still get a similar amount as A, not 1.5x.
Right but CW is not real life:-)
This is so true on multiple levels, e.g. production code != coding puzzles :)
This comment has been hidden.
Why are you posting solutions in the discourse?
This comment has been hidden.
No problems with coding, it's just math)
This comment has been hidden.
This comment has been hidden.
You can sit here all day. And still dont know the answer... This is a guessing for me. Trying possible ways with calc, i think i give up. xD I know it's very simple math probably, but still without formula, almost impossible. Mby im just stupid.
Attention, in the comments of the code, solutions from @ kiri11-mi1 contain obscene expressions in Russian.
I think it was a cry from the heart
This is a maths puzzle and should be marked as such, or the appropriate calculus provided
[deleted]
So tests actually don't pass. See https://docs.codewars.com/training/troubleshooting/.
My first 6kyu kata. Thank you!
Nice kata! My first solution was too slow and I had to optimise it.
Updated Dart translation (Dart 2.14).
Approved, thanks
.
Super fun to solve! I struggled a lot on finding the method to get to the numbers, maybe you should make it to 2 decimal points because we are dealing with money after all?
Too late to change the requirements...
hard to solve this random test case
This kata is not about the "fair" distribution of the bonus among employees. What about employees without absences? This kata must have tag "Mathematics".
The logic seems doesn't make sense since it cannot support when employee have 0 days of absence. and because it use Math.round there will be possibility 2 or more employee will have ratio with x.5 that cause the sum result is higher than the input
This comment has been hidden.
"There are only integers, no floats". For Perl you give us a hint on using "BigInt". Is there a similar data type for Raku, or should "Int" suffice?
This comment has been hidden.
Hey I am a little stuck here and was wondering if someone could give me a hint. I have a solution that works for the first test but not the big ones. But I am also using float in my code.I guess thats the problem. Am I right that the solution does not need float variables in the code? So I need to find an algorithm that does not neet that?
You can do it without floats.
perhaps you should use Fraction
This is more of a math problem than a coding problem. Turns out I didn't know the math. I guessed and looked up systems of equations, which isn't it. Finally by typing in this particular problem I found a question on the mathematics stackOverflow for this specific kata, and found a formula that worked. This is a programming site, not a math site. IMO the directions should include exactly what mathematics principles to use. I didn't know enough math to know that I didn't know enough math to solve this when I read the directions, which is kind of a self-defeating problem. I couldn't have known to avoid this problem, because I don't know enough to solve the problem. Anyway, I'll write the name of the mathematics principle in a reply to this comment, as well as a link to the stackoverflow question where I found it, for anyone who was in a similar situation to me.
This comment has been hidden.
This comment has been hidden.
Is it possible an employee to have 0 days of absence?
I give myself the answer: No, it is not :)
This comment has been hidden.
With math you are moving in the good direction. As for implantation, you know that you have problems with larger numbers and still do multiplication. Just look at "numerator = 2757240" in the description example, thats crazy. Try to work out math further to by pass this, so that you would not have such a larger number at one point of time.
Thanks, I eventually forfeited unfortunately.
I just didnt seem to find any solution to those high numbers. At first I tried simplifying the fractions, but that however still did not work. What I got was time overflow.
.
needs some good math skills😅
Can someone tell me why I would be pass close to 99% of the final attempts. Fails are always large numbers and a couple thousand dollars off certain values. Sounds like a rounding issue, but I am not rounding prematurely.
Can you tag this kata as
Puzzle
to prevent players to begin another guess the formula kata?Do you mean to avoid players wasting their time?
Not all the time: some players like puzzles, others don't like guessing.
This tag is merely a way to filter katas.
I know tags but for me a puzzle is a problem designed to test ingenuity or knowledge; it is not "guessing". Here there is nothing to "guess":-)
With many comments on how many people struggle to find sharing algorithm, without clear instructions in the description and with a vast amount of other fair sharing functions, this kata sums up to find a specific mystery function - which you can surely assimilate to something to guess.
Moreover without discussing what a puzzle is, Puzzles tag is pretty much standard on CW to indicate which kata doesn't give you complete instructions and requires you to make an educated "guess" to solve it.
And yet, I find myself trying to guess the hopefully-least-tedious way to generate
21450
because25*858 = 22*975
, or to guess the most relevant web search terms.Any solution of mine that includes // (python integer division) simply doesn't work on codewars throws out timeout. Using other solutions throws int overflows. Everything works fine on the locale.
The most difficult thing is to understand the counting algorithm, but the randomo check does not work correctly. there are numbers for which an integer answer will not work, and if you get a more accurate result, then the built-in еуые will uncorrect
Still working trying to figure out the algorithm! LOL I know its something simple that I'm missing. Someone point me in the correct direction, No answer's just a hint.
I slightly modified the description with a small hint.
Thank you
I think the wording could be improved. The instuctions mention that absense is for the last year, and that the solution should be "fair". If a colleague had taken one day off in a year, and you had taken two days off... meaning you had worked (depending on how many days per year you score it, but doesn't really matter) about 99% of the time they worked... but your bonus share according to the algoritm you have used would be way way less. (Shan't give the exact number... as it's kind of a spoiler to this "guess the math from the tests" kata)... but it's definitely not "fair". I think at minimum the mention of a year should be removed...
Description slightly modified. I hope it is a bit more explicit.
I am continuously failing random test cases Please help.
Mention which language you're having problems with; show input, actual and expected value for a test you're failing; and post your code, properly marked up and spoilered.
Please help us help you.
This comment has been hidden.
@JuniorSM other than the fact that you're using floating points, you're also truncating them(ceil and floor). Don't do that as that brings imprecision.
I think when I approved this there was a note for avoiding floating point errors, perhaps that's got removed now.
This comment has been hidden.
The only difficulty of this kata was for me to find the mathematical function you use to share the pie. But why using that function and not another : for example if I take the square or the log of your function , it seems to work too, indeed with another repartition of bonuses. So my code was linked to the test cases you gave , and I found that a bit strange Did I miss sthg ?
Description slightly modified. I hope it is a bit more explicit.
But big result. That makes the difference. Thks.
PS : hope not too easy now... Édit : Post PS: not interested to work in your company with such rules ( mainly because of poor interest to have zéro day off :-) )
I would tag this puzzle instead of fundamentals tho.
I tried but it seems impossible to modify the tag, sorry!
Haskell translation
This comment has been hidden.
You should not be comparing worked days. You should only be comparing absent days.
( Yes, the math breaks if anyone has
0
absence days. )C Translation kumited!
:)
lol, the python solution in crystal absolutely does not work
@g964
(my apologies for the absurdly gargantuan previous post)
if you may recall, my python solution failed only on the first attempt... while working on the C translation I thought I would re-try finding a random case that would fail my solution, and I did. :(
input
a
is labled asdaysoff
inputb
is labled assurplus
wrong answer my solution gave is labled
my_fail
correct answer is labled asbonuses
(yeah, I shouldn't have used the function name...)I also now realize there must be a preferred way to deliver this data, so anyone is welcome to school me on that, and thanks in advance...
anyway, hope this helps your kata?
is this actually an issue? And I'm working on Reason right now, it looks like I'll have to change the tests - the numbers seem too big for it...
if it's not an issue, I'm fine with that. but I imagine my solution should somehow be invalidated... because it doesn't work with the current state of the random tests! this type of thing has come up before, and I was told the situation was not a valid issue, but I would say there's at least something here to consider. I don't just go around posting issues for no reason. it's not for me to decide at this point.
I might consider it a suggestion, but I'm fine with it. PS: Well, that was a long time working on a C translation. :hushed: well I paused for several weeks too :stuck_out_tongue:
I stopped at 95% done, encountering some really awesome
type
considerations that I want to get exactly right before publishing... and now I want to get to the bottom of why my python solution is INVALID, heh.Well... Your data is so huge! Since you still have it in your computer I propose that 1) you verify that the sum of your "my_fail" is equal to your "bonuses" 2) if the two sums are equal try to find the elements that are different (maybe it will permit to see why they are different) 3) try your solution without rounding and see how the quotients are; is the rounding always in the same direction?
My feeling is that the problem comes from the rounding but all solutions that passed (except 2 or 3) used "round" and they didn't report a problem so it is not easy to conclude. The problem is only with integers hence the solution (and it is easy with Python) should only use integers. Remember: when you proposed a C translation I said to you and to Stefan153 to try not to use floats (see my solution) and to verify the sum of your resulting array. Floats necessarily introduce some imprecion, all the more when the given array is huge and for a very small numbers of cases.
My conclusion is that the tests can't surely detect failures in solutions because the inputs that cause failures are very rare. I tried your solution lots of times and I had no failing... Thanks for your post but I am not sure it is an issue:-)
Maybe add it as a separate fixed test? (After the random tests?) Edge cases are often the same for more than 1 solution.
A bit too long in the test isn't it? But first result: the sum of "my_fail" is not equal to the total bonus hence rowcased's solution failed. I would prefer to find a shorter edge case... Any idea?
PS:
@g964, the matter here is a seperate consideration of the translation I began, where I am following your advice about floats. However, this is simply about my python solution (and others). This test data came directly from your random test generator, not something I came up with. I can run my set-up again to produce more random variations of this very kind that will also fail my solution. BUT I WON'T POST THEM LIKE I DID LOL!!
@Unnamed, that's what I was thinking ~ and if this (or a smaller version of it) is added to the final tests, invalid solutions will fail, and that's all I was really going for.
So, I hereby remove myself from closing the issue; so as to allow g964 alone to decide how to handle the information I've provided at this point.
By the way, not going to name names, but of the 13 python submissions that are visible, two (
2
) other submissions besides mine also fail this test.Does that include my CoffeeScript solution? That one fails the check for the sum equalling the total bonus.
I understand your position. I would like to find such edge cases with smaller inputs (I don't think I can give a such long input and output in a kata)! Do you have at least one much smaller and we will put it in the tests!
@Steffan153: maybe I don't understand your post just above but if you are talking about your translations the check has to be made in all your translations...-( Have you seen my post below?
Well, I can't do them all at once! I just tried it in CS first and it didn't work... one at a time.
Well, my CS solution is from a Python solution ;-)
I never said you should do them at once!-)) Take all the time you need!
I translated your Python solution to CoffeeScript, and came to the beginning again. One basic test failed. All the actual values are one less than they're supposed to be. Huh? The exact same code. I'm not sure what to do... I've put this in a fork for now.
Good start! I dismissed my solution as it failed its 1st attempt. So I began by translating g964's entire python solution into C. Have you been running the
absurdly gargantuan
test I found through your various translations?@Steffan153: does your Dart solution pass @rowcased's big test?
Neither do I!
@rowcased: I didn't try your big test (except of course in Python since it comes from there) but I have not yet added it in the tests. I am afraid the lines are not long enough to hold it...
hey I need it again.. rowcased deleted it
Well, we wanna get this fixed, so should we delete the test for now? i can do something else later.
what is the smart way to get it to you?
also: in the meantime, i've written a basic algo to find a smaller one. it is currently grinding away. I'll let you know what I find.
do you have a github account?
You can go to https://gitter.im/Codewars/codewars.com and open private channels.
(PM me at https://gitter.im/Steffan153)
alright, well. when I run a my "fail-finder" algo with the length of
days_off
at20000
I get the desired fail within one thousand runs. but if I lower the threshhold to a (barely reasonable) length of2000
, I get no hits whatsoever even after running it over half a million times.@Steffan153 ~ I found an array at length 2,500! check the "repository" (where I left you the gargantuan one)
@rowcased yes. check gitter.
@g964 thanks for updating the kata! my solution is invalidated and the issue is closed
@Steffan153 thanks for the help
Thanks for the help!
This comment has been hidden.
That is absolutely ridiculous? What language? I had to scroll down for a LONG time to get to the end of this... remember: the inputs can be huge!
I just tried to remove it
but you beat me to it SORRY EVERYONE
@Steffan153: read my answer to @rowcased above. I am afraid that you have to check in your reference solutions (Crystal, CoffeeScript and Dart) if the sum of your resulting array is equal to the given total bonus, if not pass that test OR use the same way I used in my Python solution: only integers, no floats.
Aaaand in CoffeeScript, it fails 9 tests. :(
Looks like I need a better solution!
I told you (in my first post when you proposed to translate) to try not to use floats and to check that the sum of your resulting array is equal to the total bonus... but facing your good will (yes, yes) and my possibly not clear post I wrongly said in a following post not to worry! Do you have a failing test shorter than the one of rowcased?-)
The shortest array failing is 4931 elements long :-( I will not post that!
Also, Chai won't let me see the whole array.
I will go try this in another language.. maybe Dart, and give the results.
EDIT: Dart will not fail! :) Dart is awesome at speed, I guess it's good at accuracy too. ;-) Published.
This comment has been hidden.
Seems good in length. I will look at it and tell you.
Yeah. Seems Crystal is the worst... We definitely need a better solution for it.
There is a problem with your total bonus of
2139381204
. Following my function "compose", from your array "Absencedays", the total bonus should be a multiple of27220012621
which is not the case. No wonder that your test fails. I think your Crystal "compose" function is not correct (don't use floats:-). For now to test your translations we only have rowcased' array...Too bad we can't use most recent versions of Crystal.... oh well.
Rewrote
composearray
, it's exactly the same as other languages... but it still fails on really small inputs. :/I wonder if it's because we can't use integer division (it's only available in later versions)?
If you're talking about the failure message, set
chai.config.truncateThreshold = 0;
before tests.@kazk: if we delete translations that are not absolutely correct will we be able to publish translations in other languages (Java for example or C#) or do I have to delete the whole kata and how? Maybe it is enough to "Un-Publish" the flawed translations?
I know that, but then it does "Max Buffer Reached".
Well, I've heard it can make problems, so if you delete a language, then weird things can happen... Hopefully we can just get it fixed fast. Dart seems okay thouh. :)
Removing a language can cause unexpected and weird issues especially if there's already solutions associated with it. Codewars doesn't handle removing documents well in general :(
Oh, I didn't realize it's CoffeeScript. It uses the original cw-2 JavaScript test framework and the output is extremely (and unnecessarily) verbose and using that with
chai
makes it even more verbose. It hasn't been touched in about 2 years since there's not much interest.Yeah. I started with cw-2, but it was way too verbose, so I switched to chai.
@kazk: Thanks! Is it possible to un-publish translations (without weird issues!) instead of deleting?
@g964 No, once the translation is accepted, its contents get copied into the kata and is maintained there. So there's no independent translation that can be unpublished unfortunately.
Then what is the use of the "Un-Publish" button?
It should just put the translation into
draft
state, but it shouldn't affect the kata because it's already copied when the translation is approved.But I have a feeling that it's invalid to change the state from
approved
todraft
so the button might not do anything and it's just there unconditionally for any published Kumite. Similar to how translation approve button is always there even if you can't approve yet. These are usually just overlooked or a quick workaround for issues around cache invalidation.Anyways, Codewars is full of WTFs and even I have many questions as I wasn't involved when it was originally developed. Software archaeology is what I'm doing :p
OK, we will see. I just proposed to Steffan153 on private channel a JS translation that he could use if he wants to review his CS translation. The Dart one seems to work. Crystal translation is in standby. I'm sorry to waste the Software archaeologist's time and once more I thank you for your work.
@Steffan153, just so you know ~ I didn't edit the comment of the gargantuan array... after it had been replied to, I couldn't. (I'd say that was almost for sure kazk whom did that)
Can't translate to Reason, apparently because of too total bonus (numbers overflowing OCaml's limit?). (here is the kumite) Apparently we'll have to change the tests a bit for Reason...
If the backend were OCaml, how would you have used
JS.Array
then?..I thought Reason compiles to OCaml, and then to JS...
Wow! Dart is incredibly fast - 3.7 seconds for those huge inputs! :+1: And CoffeeScript with half the Dart size gives 9 seconds... :( Dart translation
hi, is something wrong with this translaion? I also have an elm translation for "Drying Potatoes".
Nothing wrong I suppose but for now I had no time to look at them.
This comment has been hidden.
Do you have a better rule?
I agree with Unnamed on that ...
Given the
N
the number of worked days in the year, andd[i]
the days missed for workeri
, I would give workeri
s * (N-d[i]) / sum(N-d[j] for j in d)
I think that would be fair, but then the kata would become trivial.
Anyway, it was a great kata, fun to solve.
No way. If I worked an extra day over someone, I want more money.
I didn't solve it, but I can translate it. Which languages do you want (I can do coffeescript, crystal, elixir, dart, javascript, julia, php, ruby, reason, and typescript)? ;p
For the moment you can take coffeescript, crystal, ocaml and dart but maybe it will be better to wait until the kata has been approved?
Sorry to bother you but in your translation try not to use floats and verify that the sum of your resulting array is equal to the total bonus...
Finally got the first translation done! Coffeescript translation Note that I had to refactor the code a bit and reduce the array sizes to prevent it from timing out.
Sorry, impossible to approve: merge conflict...
I re-published the previous translation (Python) but it is still impossible to approve: "merge conflicts ..."-( Maybe you could try to fork your translation and I will approve the fork. I am always lost with these "merge conflicts"!
https://www.codewars.com/kumite/5d6962c7d55b260020f8979e?sel=5d86100bfc9e6e002bcf994c
Approved!
Did you remember that in one of my previous post?-)
...
I'm not quite sure what you mean by "not to use floats"... and with the verifying, did you actually do that in Python? I translated it directly from Python. Also, which array are you talking about?
Don't worry. Python can use integer division and I think you can't; I also thought you can test the sum of your resulting array to verify it is equal to the total bonus... Forget about all that. Thanks for your work!
CoffeeScript can, with
//
... anyways, I'll work on Dart and Crystal now.hi g964, just a heads up: my code failed ONLY first time I
submit
on one (1
) very large random test. the exact code then passed repeatedly (attempting to study the reason) ...so not sure why it failed that one time.Thanks for the info! Maybe a temporary CW problem?
no idea. I assumed it was something "edgy" I'd missed. anyway, you're welcome. would you like a C translation for this kata?
OK, you can go for a C translation. Thanks!
Sorry to bother you but in your translation try not to use floats and verify that the sum of your resulting array is equal to the total bonus...
got it, will do
This comment has been hidden.
Fixed I think. Thanks!
;-)
Don't you modify your vote?-)
@g964 The downvote was probably from ZED...
OK, thanks! But did you forget yours?-)
You can't vote on something you forfeited on...
Why did you forfeit?:-(