# The River II

#25

Anyone else having an issue with optimization in python3?
Passes all test cases quickly with no errors and no hard-coding, yet only showing 91% completion...
I'm failing the "yes please" test.

#26

Keep in mind: you don't need to find the earliest starting point of the meeting rivers, you just need to check if a river exists. So consider starting with r1 and then try to find one single smaller number that leads to r1 and you are done...

#27

I am literally way to ashamed to admit how much time i had to spend on this one..
If you are stuck like i was just PLEASE read the description from the beginning to the END and realize how simple the solution might be. My final code takes like four lines and runs in seconds. Cheers

#28

Trying brute force seems, effective for small cases, but kind of stupidā¦
Before coming here I had figure out that you juste need to go one step backwards to be able to give an answer ( you just have to say YES or NO , no how many river meet this number)
But for the life of me Iām not smart enough in Math to figure out how the hell you do that, if thatās even possibleā¦

#29

Of course you are.
Given K, thereās another river meeting K, if for [1ā¦K-1] you can find X such as (X + sum digits of X) == K.
Now, you can find a lower bound for the numbers you need to check.

#30

Hello guys,

I am stuck on this one for too longā¦I need some help.
The āBIGā and the āRandom Largeā tests failā¦

āGiven K, thereās another river meeting K, if for [1ā¦K-1] you can find X such as (X + sum digits of X) == K.
Now, you can find a lower bound for the numbers you need to check.ā

This is what I do. Also, I found a lower bound, but it is not enough to pass the 2 tests: [1ā¦K - (Kn+1)].

I had another idea : during the loop, store all the numbers of every river in a tab, and remove the duplicates. if K is in the tab, I do not need to get the river and I can go to the next iteration.
But this takes more time than my first solution

So I am stuck, any (other) clue would be nice. Thank you in advance guys

#31

Naive method i used:
the maximum number of steps any river advances is (length_of_number)*9. obviously. e.g. 99 will advance 18 steps, whereas 100 will advance only to 101.
so the biggest step any number below your checking number is:
amount_of_checks: ((first_digit-1)+(length_of_number-1))*9

now you only have to check this amount of numbers.

iterate over each of them, and see whether the very next step leads them to your number. if so, youāre done. if not, next.

HTH

#32

Thank you guys, these clues helped me a lot

#33

Hi, thanks to the comment about log10 I was able to validate the exercice with 100%, before I was using the same logic but didnāt really know where to stop to still have a high probability of a valid answer
Does anybody have a source/explaination about why the step between 2 numbers in the river has to be lower than 9 * log10(input) ?

#34

Whatās the step length for 15?
Whatās the step length for 999?
Whatās the step length for 12361?

What is the step length for abcdefgh, where [aā¦h] are single digits?
How many digits are this?
What is the log(10) of abcdefgh?

HTH

#35

Not sure how itās possible, my solution is about 35 lines of codeā¦

#36

Hi, you should check what result your solution will give if there are more than 2 rivers possible