Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Like the others have said before, is the solution good mathematical work. But in programming bad practice. For small n you can use it, but for greater n it would screem for a stack overflow.
The reason is that you call in each return the function nthfib for two times, which will be saved in the memory till you reach 1. At this point it bubbles back and return the addition from the retun statements.
This mess up the memory and crash your system.
An other solution, like mine, is the linear one where you loop up. With the use of one temporary int I can calculate the n-th fibonacci. The memory it´s also constant, in the inner loop you use constantly three int with each 4 Byte = 12 Byte. This isn´t much.
Now I understand the problem, I didn´t noticed that the number string grows like [1,2,3,...,inf].
Okay, this seems manageable...
I have a few ideas... Thanks for your request and help!
You misunderstood the problem.
The "needle" string is given to you as the argument
str
. The "haystack" string is not given to you as an explicit value, but it is fixed, has a predetermined, well known form: it's a string created by concatenation of all narural numbers. It starts with"12345678910111213"
and continues up to infinity, or, if you prefer, as long as you need to find in it all numbers given to you as inputs.As said above, the
indexOf
will not work well for this problem, because the haystack is very, very, very large. If you want to, you can try to create it withstring.Join("", Enumerable.Range(1, Infinity))
, which, obviously, will not work, because there is not enough memory to build such a large string (you can replace theInfinity
with a sufficiently large numeric value, but it will be still too much to build such string).The whole trick to this difficult task is to not build the haystack, but to exploit its well known structure and find the answer without building the long string.
Okay...so far so good...
But from where I get a new string?
This method is given in c#
public static long findPosition(string str)
{
}
The parameter is a string, not infinit.
In the first test case I should find "456" in "...3456...".
With IndexOf I get 4 for "456", but 3 expect...Why?
"...3456..." as parameter is a fixed string, not an infinit string...
In the next testcase for the given string "...444546..." it should return position 79.
79 for a string with a Length of 12??
This makes no sense in C#...What have I missunderstood?
Greetings
Noha
Did you just create any string you wanted? Well then it's wrong. The string (part of it) is given to you, but you have to expand it yourself. It's numbers from 1 to infinity, joined together in a string. Note that using this method, you will eventually run out of memory.
Good Morning!
Can anyone please explain the main problem?
If I would find an index of a subsequence in a string I would use indexOf in C#.
At the second case he said that I can create my own string if I can´t find this subsequence...Okay, the subsequence I searchd is at the first position, cause I created a string on my own.
Seems I don´t understand the problem...
Greetings
Noha
.
OK. i changed description to say
percentages of the total
...hello ciprian...
okay, as a sum of the input it make sense.
Before I interpreted the input numbers as the percentages, weich was correct for the Test Cases in the Test Phase, but not for the further Tests in the Attempt Tests.
But it should be clear in the description that the input is not the percentage value. it can be missinterpreted.
You need to represent the percentage of each element. For example, if the 6 values are [0, 2, 1, 2, 2, 3], then the percentages would be [0%, 20%, 10%, 20%, 20%, 30%] respectively.
Seems a bit buggy in C#...
For example All3s give {0, 0, 11, 0, 0, 0}, but expect 100% for 11.
RandomBigExamples is also different {198, 176, 175, 155, 144, 152}, but expects 15%,14%,15%,17%,17%,19%}. It cuts the last digit of each percentage.
RandomSmallSampleSize makes another approach too. {5, 0, 2, 1, 0, 2} should be interpreted as {2%,"\n",1%,2%,"\n",5%}, but it expect {20%,"\n",10%,20%,"\n",50%}.
This make no sense...