6 kyu
Paperboy 2
66 of 110TroyMaeder
Loading description...
Algorithms
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.
python new test frameworks
Examples in the description are JavaScript-specific.
Tests where a single paperboy can deliver everything should be added in JavaScript. Such cases are generated randomly in Python, and having at least one fixed test would be good too.
Initial solution is wrong in Python.
Cool but tricky...
Python random tests:
The expected answer is correct. See the last line of the descriptions ;-):
I don't really understand the meaning of that sentence. But my solution is the same as in JS, you JS solution returns 47 too. If it's not correct than it's and issue in JS.
If the time only allows one to deliver paper to 47.5 houses, it's counted as 47 papers and not 47.5.
This comment has been hidden.
Okay, let's fix some more blatant problem first.
The random tests in JS are testing against reference solution itself ;-)
@fenring76, this code passes in JS, so it's still a spoiler. Even almost correct code is usually a spoiler.
Fixed Python tests. I thought you were talking about JS version, but turns out it was about Python version ;-)
(I also added Python 3 compatibility)
Voile, thanks.
Unnamed, yeah, but my first reason was the important reason. It's unreasonable not to let a user see his own post just because he hasn't solved the kata. It's hard to have a conversation sometimes if one can't refer to his own posts. I'd really like the ability to label a section of a post as a spoiler, to be honest, but even then if I am the poster, I should be able to see the post after the fact.
You can see a spoilered post if you reply to that post, as long as you don't close the page.
Also, of course, you can just make 2 posts and separate spoilers from non-spoilers.
Your fixes tests is a nightmare to debug.
Why can't you run the user solution once perform one test at a time? Running them all at once and then sorting the results to do comparison is messy.
Edited ;-)
Nice Kata!
I think your rounding logic is correct, but I think it will still confuse (too) many people.
I would suggest you:
Also your description asks for an object with a method, whereas the code template suggests a function
Python and Ruby translations submitted; note that I opted to follow the rounding criteria chosen by the original author, so if you have problems with that, try to read the previous discussion to get some tip :)
From reading the previous discussion, I can see that there is some indecision about rounding. This rounding error caused my implementation to fail ONLY the 'City Line' test.
I believe your refrence implementation is introducing rounding errors. I believe a single Math.ceil rounding on the entire calculation is in order. You have chosen to round down on an arbitrary grouping.
In situations like this it is understood that the number of papers delivered per time interval is an average and therefore it isn't valid to argue that a paper delivery person cannot deliver a fraction of a paper.
I wanted to leave it to the user to get around this problem but I think it's causing a little too much confusion so I have added this line to the description.
NOTE: REMEMBER THAT A PAPERBOY CAN ONLY DROP WHOLE PAPERS AND NOT FRACTIONS OF PAPERS
;-)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I know your means, and I solved it now, thanks~~
No problem at all : )
The code that should get written isn't really idiomatic JavaScript:
Why not
After all, you ask for a function, not for an object that has a method. Either fix your description or your tests.
I totally agree with your comment. Would you please be kind enough to take another look at my description and let me know if it clearer now. Thanks
While it's still non-idiomatic JS, it's better, BUT your examples are misleading:
route1
does not contain a string.// route1.paperboysNeeded() should return …
would be better.How about the following?
hi bkaes, i think ive resolved the issue although let me know if theres anything else. thanks
The 5th fixed test is definitely faulty since I passed all the tests (fixed and random) except that one. I had to brute force my way through that particular test case to pass all the tests.
Please fix it ASAP. Thank you very much :)
Cheers, donaldsebleung
This comment has been hidden.
The Math.ceil is there in place for that exact reason. If it's 6.0000000001 then evidentaly it's seven paper boys that are needed, not six.
No, you still don't understand the issue. The
.000000000001
is only there because of the way Javascript (and computers in general) handles floating point values. In real life calculations you can easily see that the.00000000001
doesn't (and in fact shouldn't) exist. Therefore it should be 6 paperboys in total (i.e.4
extra paperboys), not 7.Just try the maths out on a piece of paper and you'll see.
This comment has been hidden.
This comment has been hidden.
I think the problem here is, when performing division, if the result is not a whole number (i.e. integer), you should always leave the result as an exact fraction as to not lose any accuracy in your calculations.
Anyway, thank you for taking your time to solve the problem on paper. :) Issue resolved.
Are you sure the maths in all the test cases for this Kata is correct?
I coded a solution that passed all the example tests but failed on the 5th fixed test in your actual test fixture. Details are as follows:
According to my program, only 4 extra paperboys are needed because:
50 * 6 === 300
houses is 45.45 / 300
, or rather,0.15
.0.15
minutes per house by 400 houses and we get60
minutes (i.e.1
hour) which meets thedeliveryTimeInHours
exactly.However, that particular test case says that 5 extra paperboys are needed for the task (i.e.
7
total). Why is that?Brute-forcing that particular test case while passing all the other test cases with the working formula and solution proves that particular test case faulty.