Doctor Who - The Gift puzzle discussion

Is the Doctor’s algorithm truly that fair as the Ood wanted? It appears that those Ood who have low amount of budget must pay it all, and those who are rich pay only a part of it. And more importantly, the more poor Ood participate, the less those who are rich actually contribute.

I wonder if it could be more realistic and fair if the Ood went with percentages (ex., the cost of the gift is 50% of the sum of their budgets => they all have to pay 50%), or even better, using some progressive contribution formulas similar of those used for equity taxation?

3 Likes

Hello, I have an issue with the last big random test and I need some help to debug this please.
The console tells me that the expected output is 70 but it found 69. My last contributor is already giving 70, so it means that a previous contributor should give 70 ?

Sans titre

I am on Python, thanks in advance for your help ! :slight_smile:

Maybe you have rounding issues. Suggest you to pull out the input numbers and expected output numbers to take a closer look e.g. in an Excel spreadsheet.

1 Like

Indeed, it was a simple rounding issue, problem solved !

Thank you very much :slight_smile:

2 Likes

Everything checks out, except “Big random”; anyone who can see, where the logic breaks apart? :confused:

1 Like

Does any of the previous discussion in this thread help you?

Hi everybody,
could someone helps for issue on “Big Random” . i have quite similar issue than louack, so i look on rounding potential issue. after change that create example 3 + big random as issue so.
in first case only 69 instead of 70 and in second case for big random lot 70 but seems too much.
that really seems as rounding sensitivity but not clear.

2 Likes

Some people say it is the easiest codingame medium but for me it is not true.

I usualy do a medium in 30min/1hour. But on this one… holy moly i’ve been stuck for 8 hours on the last test…

3 Likes

Same case, all the tests passed except the last one “Big random”, I’m using Java and I have no issues with rounding, the assertions breaks at the index 529 of the output list where they expect 55 but I gave them 159. I’m still blocked, perhaps my solution logic is wrong, but it did pass the other tests and any case I’m trying.

Hi All, I’m solving the puzzle using Java and I passed all the tests but I failed the last one “Big random”. I tried to debug the output but it’s so long and tedious. I’m suspecting that I have a flaw in my reasoning or a bug in the test.
I checked that I have no problems with rounding because in Java int division returns integers no floating points numbers.
Can any one point the error in my solution that I’ll describe below ?
Suppose we have this use case

3
100
100
10
100

so wee need to distribute 100 on 3 participants,

1- compute the initial distribution and impact amount on the fly as we read the input, an keep the rest
in this case each one is supposed to give 33 but we keep 1 as initial rest

100 → 33 remains 67
10 → 33 remains -23
100 → 33 remains 67

1 as rest to distribute later

2- order the contributions by budget ascending

10 → 33 remains -23
100 → 33 remains 67
100 → 33 remains 67

1 as rest to distribute later

3- start reading from the lowest budget, if it’s overspent, fix it by spending all the available and distribute the exceeding amount over the others
in this case we need to spend 10 and distribute 23 (11 on each), the remaining 1 will be added to the rest

10 → 10 remains 0
100 → 44 remains 56
100 → 44 remains 56

2 as rest accumulated to distribute

4- distribute the rest starting from the highest budget down

10 → 10 remains 0
100 → 45 remains 55
100 → 45 remains 55

5- stop when we reach the latest budget else go to step 3

is this correct as approach to solve the puzzle ?

Maybe you can try using a spreadsheet to help you. Copy the input, your output and the expected output to the spreadsheet, and analyse/debug from there.

Naturally participants with the highest budgets contribute more, so it helps by sorting the budgets right at the beginning, instead of after the initial distribution. If you follow this approach, the cost allocated won’t jump from 55 to 159.

1 Like

Thanks for the response, actually I figured out that my logic was wrong and complicated, I solved the puzzle with the new method in less than 15 minutes.

I created a code that worked part of the time, and then a while latter changed it but that did not work as well. Is there any way I can get my original code back.

If you have submitted the code before, it can be found in the history. Otherwise, you will lose the original code if you change it subsequently.

That worked thanks.

I had to lookup a solution to understand what was desired, because my algorithm initially wasn’t ‘greedy’ (yet more fair to everyone that had money to contribute). I now assume ‘greedy’ means that the ‘want’ of the algorithm changes dynamically for each case executed.

1 Like

Your reply helpt me a lot and hasn’t been spoiling the experience yet, thanks a lot for that!

1 Like

yes, and I also think we have to sort