6 kyu
Plenty of Fish in the Pond
47 of 1,281adrian.eyre
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.
Can anyone explain me:How we get for "111111111111111111112222222222" the length of the fish is 5? I've found it 1111 (2) 2222 (3) 111111111111 (4) 1111222222 (5)
This comment has been hidden.
For example, if your size is
2
and you encounter a fish of size3
, you must wait to be of at least size3
to eat it (if you ever reach size3
). Your solution don't take size into consideration.Your solution re-eats the same fish for each level.
Logical I don't understand how is the right solution 5, I think it' 4.
C#: How can the expected fish size be 13 if the fish size ranges from 0-9?
Can anybody help me?
I have not solved this myself so I can only speculate. I suspect that the input fish are limited to single digit ranges but that your own size can grow as large as the food eaten allows. Perhaps there is a pattern with regards to how much you eat and how big you get? Maybe we should consider ourselves a special fish that can gorow past the limits of all other fish? I realize that I am answering with more questions to a question, sorry about that.
Only the other fishes from the shoal ranges from 0 to 9. You (the growing fish) are not limited in size.
In the description there is a table that describes how a fish grows. But the table ends with fish size 7, so I assumed that growth is limited.
question answered by PetitLu117
I have finished, but I still can't understand the question. It feels like the description is a bit lengthy.
C#: method name should be
PascalCase
(Please refer to implementation of backward compatibility here )The rust initial code is wrong/misleading. The intial code setup has:
but it should be:
fixed and added better assertion messages
Description does not allow a fish to grow beyond size 7, because only for a fish of size 6 it's specified how many fish to eat to grow to size 7. However, nothing is specifief for fishes of size 7, hence it could be infinite for all we know, i.e. impossible to grow. But the tests show that fishes can reach sizes beyond 7.
Adapt the description.
The description has examples on how to achieve the expected outcome! With the information given you can work out how to grow greater than 7 yourself. It is not for me to give you every possible permutation, if that was the case then I may as well solve the kata for you.
Where are those examples in the description? I can't see any for fishes larger than 6. Furthermore, your description is just wrong, examples won't fix that. Others have noted it too.
@adrian.eyre: just add a line with
...
to the table?Yes, please adjust the description. Now, people just have to rewrite the code after the first failed submission. We only learn at that point that growing about size 7 is possible.
If only i knew math. This actually doesnt look hard at first, but can be a bit tricky.
When attempting to submit, I sometimes get expected values higher than maximum size possible (JS) :
Should return '10' - Expected: 10, instead got: 7 Log Testing for '9518416642975095'
Well nowhere it says you can't reach size 10, but, how do you reach size 2 if that's the input? I thought you need at least 4 fishes of size 1 to reach size 2. Did I miss something?
You need 2 fish to reach size 2. The trouble is that the instruction does not provide the threshold for growing to size bigger than 7
Edit : Nevermind I saw there was a pattern in the size threshold
The first line of the table says you need 4. At least that's what I see.
You can work this out from the example values provided
This is posible. The instructions do not state in what order you must eat the fish
Sorry, but I can't see how to reach size 2 there, could you explain that? You start as size 1 and you only can eat fishes as big or smaller than your size, you can eat only two size 1 fishes and that's it, because you need 4 size 1 to reach size 2.
I tried OP's code and it does not handle cases where the fish grows to sizes beyond what is mentionned in the description. the confusion about the input is probably due to the tests suite logging the input to the console instead of making it part of the assertion message. i've fixed that and enabled Node 18+. there is already a suggestion about the lack of clarity of the description (it's not clear that we have to deduce a formula from the table)
Hello, interesting task but I would suggest writing explicitly that in case of overeating ( eating total sum of 14 instead of total sum of 12 on fish size 3), the extra eaten size will be considered for the next size to grow. i.e. amount of fish eaten to be size 4 is not 16 rather is 14 as in the previous step overeating done by 2
How does we treat this string 111111111111111111112222222222 so the size is 5?
This comment has been hidden.
Sorry, Google Translate does not compute, can't help you. Try posting in English.
Please add a
Spoiler
tag when posting code next time.C tests return plenty of warnings:
setup.c:8:22: warning: implicitly declaring library function 'calloc' with type 'void *(unsigned long, unsigned long)' [-Wimplicit-function-declaration] char shoal_copy = calloc(str_len, sizeof(char)); ^ setup.c:8:22: note: include the header <stdlib.h> or explicitly provide a declaration for 'calloc' setup.c:9:3: warning: implicitly declaring library function 'strcpy' with type 'char *(char *, const char *)' [-Wimplicit-function-declaration] strcpy(shoal_copy, shoal); ^ setup.c:9:3: note: include the header <string.h> or explicitly provide a declaration for 'strcpy' setup.c:10:3: warning: implicit declaration of function 'qsort' is invalid in C99 [-Wimplicit-function-declaration] qsort(shoal_copy, str_len, sizeof(char), __preloaded_char_cmp); ^ setup.c:24:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration] free(shoal_copy); ^ etc.
Are you able to fix this please? @WojciechBuczek created the translation and I wouldn't know where to start to fix the issue.
Sorry, I'd like to, but I have no idea... I'm still far from being able to create or manage a kata in C, sure I would mess it up if I tried to fix it. However I've just completed the kata in C, so I guess those warning errors are not that critical.
I believe these are just warning and not errors so should not affect the kata.
C warnings have now been silenced.
Awesome Kata. Thanks again for all your hard work.
Thank you
descriptions table contains fish size only to 6.
test case contains to 9.
we can expect fish size up fomula. but that's cofusing.
I couldn't find the solution for this exercise, so I decided to unlock it to see the solution of the other users. Therefore I could figured why I wasn't able to pass the test suite: the amount of fishes needed to grow it doesn't have to be EXACTLY the same of the chart but it can be more (i.e. to grow to size 3 i can eat 9 fishes (1 size) and not exactly 8 fishes). At least for me it is not so obvious so I suggest to specify it on details.
Congrats to author, all yours exercises help me and stimulate me to improve my coding skills in this phase where I am newbie yet.
Thank you for your suggestion, I've added a comment under the table. I'm glad you enjoyed it and it's helping you become a better coder! :-)
This comment has been hidden.
Since I marked the original post as a "Spoiler", I cannot see it. Worse yet, all the code I wrote is gone from the Kata when I go back to it. I'm new here and do not fully understand much of the processes here. Any help would be appreciated. Considering the spoiler designation, I suppose I won't see his post, nor any of its' comments after I post it.
EDIT: I can now see the post and this reply. Still could use some guidance on this one.
I should have added the actual error message. Replace is definitely a member of Strings. Here is the error and link to the class:
/workspace/vb-test/src/Solution.vb(20) : error BC30456: 'Replace' is not a member of 'Strings'.
https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.strings.replace?view=netframework-4.8#Microsoft_VisualBasic_Strings_Replace_System_String_System_String_System_String_System_Int32_System_Int32_Microsoft_VisualBasic_CompareMethod_
Maybe because it just import System Namespace, my sugestion is, just using 'String.Replace'Method (shoal.Replace(old, new))
I'm testing in VB. In my code give me these errors, but they're can't be correct. Food is 180 and for fish 11 it need 220, so its impossible to be fish 25 ( and i've sorted the string from 0 to 9 ). Testing for '314592418182547723040447879492607488233699817548247311587661201647516859044163023125538599156139716903238827632364817611991660290534702098670085679222110400156853710765281904180699006732420183172736590394011532945774698723509882234410870161189713849703876689423839753580353' Test Failed Expected: 25 But was: 10
Please Fix the test errors.
Please read the instructions carefully as there isn't an issue here.
I've tested your two examples with the other language translations and both pass.
Yeah i've found and issue in my code( i didn't sort the string), but now that i've done the sort from 0 to 9, i'm again in these errors. '314592418182547723040447879492607488233699817548247311587661201647516859044163023125538599156139716903238827632364817611991660290534702098670085679222110400156853710765281904180699006732420183172736590394011532945774698723509882234410870161189713849703876689423839753580353' Expected: 25 But was: 10 Food is 180 and for fish 11 it need 220, so its impossible to be fish 25 . I don't know what i need to do with it, i don't see any more errors in my code. I've passed all the test examples, but when i made an attempt, it crash.
It seems like something weird is going on with a few of the random test cases.
For instances, I received '4677038' as my shoal.
Since our fish starts as size 1, there is nothing to eat. However, the test said it expected size 7 as the final result.
Other examples I saw: '08995899224880' - expected 7 '784181449' - expected 4
Am I missing something or is there an error?
I believe you are mutating the input. I have updated the tests for Javascript to hopefully stop this. If this error continues, please copy your code here and mark as a spoiler :-)
Thanks! After the change, I didn't see any more of the impossible shoals like I listed about, but I still wasn't getting everything right - usually 97 to 99 of the random test cases would be correctly solved.
Found and fixed the bug in my code and everything is running perfectly now :-)
Nice one :-)
This comment has been hidden.
@WojciechBuczek, the Criterion test suite that codewars uses for C and NASM testing has some major drawbacks and limitations regarding output. The cr_assert_* functions' default output is useless for debugging. It prints the underlying C code, not the actual return and expected values. Also, anything sent to stdout gets interwoven with the test suite's output.
To fix the first issue, I use a wrapper function for each test rather than calling the cr_assert_* function directly. This wrapper takes the test input and expected value(s), calls the user function, explicitly does all the return value checking, manages memory where applicable, and finally calls the cr_assert_* with an explicit error message stating what's wrong.
To compensate for the second issue, I only call the cr_assert_* when I know a failure will happen, allowing passes to fall through unreported. Then at the end of each
Test() {}
block I flush stdout and finish withcr_assert(true);
. This last step ensures that passed test blocks will be counted as such.If you want some examples of this approach, then take a look at my C translations of these kata. https://www.codewars.com/kata/odd-even-string-sort/c https://www.codewars.com/kata/smooth-numbers/c https://www.codewars.com/kata/cogs/c
fixed
@WojciechBuczek, your assertion statements in both C & C++ are backwards. The expected value should come second. For example, if the correct result is 4 but the user returns 1, you'll see this in the C++ output.
This is going to cause headaches, damage laptops, enrich drug dealers, and destroy marriages. :-S
A C++ test statement like this
Assert::That(4, Equals(fish("111122223333")));
should be thisAssert::That(fish("111122223333"), Equals(4));
.A C test statement like this
cr_assert_eq(4, fish(shoal_3, strlen(shoal_3)));
should be thiscr_assert_eq(fish(shoal_3, strlen(shoal_3)), 4);
.Thanks for letting me know....I've updated both the C# and C++ translations :-)
@adrian.eyre, the issue still exists for C. See my treatise above. ;-)
Hi @clcraig, sorry about that. I had fixed the two assertion problems for C++ and C before I had read your above suggestion. I have very little knowledge of C (I haven't used it since Uni, which was a very long time ago :-) ) so I will have to ask @WojciechBuczek if he could update. Thanks once again for your input on this Kata :-)
I'd strongly suggest making it clearer that you don't just go through the list of fish once, but just go around eating as many fish as you can. While you don't specify looping through them once, I think a lot of programmers will make that assumption.
Hi @wthit56, thank you for your suggestion.
I would say that specification
6. You can eat the fish in any order you choose to maximize your size.
makes it clear that you can eat the fish in any order.I have added specification
7 You can and only eat each fish once.
to clarify you can only eat the fish once :-)C translation added
Thank you for the translation, approved :-)
Haskell translation
Approved. Thank you for the translation :-)
This comment has been hidden.
Approved thank you for the translation :-)
This one took me a while to puzzle out but it was a good one! I've really enjoyed your katas, they are presented very well and are always interesting. Keep up the good work!
This comment has been hidden.
Hi @skeletoo,
I copied your code and the tests into Visual Studio 2015 and it failed the tests with and without the
Console.Write(a[i]);
so, I'm not sure why it would pass the tests in here.I haven't got an explaination for you, sorry.
Maybe @jhoffner, @kazk, @smile67, @Voile, @SteffenVogel_79, @donaldsebleung or @gabbek could help?
Interesting problem ;-) I copied this to other katas and submit. It can not pass the tests. But in this kata it passed all tests. Perhaps you can report an issue on gitter, let @jhoffner know.
I've added a comment in the main chat :-) thank you for your suggestion :-)
I've separated the core issue out and filed a bug report. Turns out it's a CW platform bug that's independent of languages:
https://github.com/Codewars/codewars.com/issues/922
If we get some good luck @jhoffner should be able to fix this in a few days.
@adrian.eyre i've inserted "Console.Write(a[i]);" just to test if the string is passed correctly to int array, and i had a surprise passing all the tests :D and i don't understand how that works :D
Hi,
I had the same problem than myjinxin2015 (see below). I think you should update the description to make clearer that the order in the string isn't relevant or provide another example with an unordered
shoal
string (the kata is only 6kyu ;) )Cheers,
B4B
I've updated the description to
6. You can eat the fish in any order you choose to maximize your size.
:-)The last example testcase:
Why your fish so fat? ;-)
You don't have to eat the fishes in sequence :P
eat over all that it can eat?
Yes :D
The string represents the list of all fishes around, so you're free to eat any fishes among them.
OK, eat over.
???
Please explain what happens when you eat a fish smaller than your size.
I think the author's mean: eat 1, exp+1 eat 2, exp+2 eat 2222, exp+8
But I have trouble with the last example testcase and 1/5 random tests :(
I think the fish weights have to add up to the required amount in the table. Like leveling up or something...
Yes (I figured that bit out a minute later), but it's nowhere mentioned in the description. It should be clarified.
Hi @Voile
In the Example
fish("111122223333")==4
you would solve this byThe example
fish("111111111111")==3
would be solvedI've added
7. The size of the fish determines how many are needed to gain your next size
in the rules and added an extra example.Sorry I found it harder to explain what I wanted from the kata than to actually code it.
Does this explain it well enough?
I think this resolves it. Please let me know if you think otherwise :-)
It's still confusing:
The size of the fish determines how many are needed to gain your next size
The size of which fish? You, or the fish you're eaten? Besides, it's still not precise how does it scale in respect to fish sizes.
My suggestion:
The bigger fish you eat, the faster you grow. A size 2 fish equals two size 1 fish, size 3 fish equals three size 1 fish, and so on. This chart shows the amount of size 1 fish you have to eat in order to increase your size.
Thank you, I've updated the description with this information :-)
I'm having trouble with passing the last test case. I'm counting through the shaol, and personally, I expect the maximum to be 4 instead of 5.
Hi @clydiscope, please see @myjinxin2015 question and @Voile answer that explains this :-) You don't have to eat the fish in order
6. You can eat a combination of different sized fish.
:-)Thank you for your clarification.
Plenty of Fish in the Pond ready for appoval if any moderators are free please :-)
Nice Kata! I liked the formulation of the problem. Too many ideas for similar katas can grow from this one. Feel free to check my Katas too they are still all on Beta!
Thank you, I'll try and solve them tomorrow as I'll have more time then :-)
Feel free to solve my other two katas that are in beta also Hungy Hippos and Pigs in a Pen :-)
i really like this kata. Sounds easy, but has some interesting concepts you need to understand. Nice one :) !
Thank you, yeah it took me longer to explain what I wanted from the kata than to code it :-)