0

Matching numbers?

So the attached code works properly as coded but I was wondering if there was a way to match a and b across different loops. For example, entering 7 and 64 will loop much longer than necessary and should reveal a match at 16 but because the amount of loop calculations varies between the two numbers, the matches are a couple steps off beat. Any suggestions? https://code.sololearn.com/cROiVfiW5vpP/?ref=app

9th Jul 2018, 3:55 PM
Michael
Michael - avatar
2 ответов
+ 2
Do you have some link or document that documents the algorithm or rules? Why 16 and not 1, 2, 4, or 8 that your program currently list for both numbers?
9th Jul 2018, 6:02 PM
John Wells
John Wells - avatar
+ 2
If you maintain a sorted list of all numbers generated, until a duplicate is seen, for both numbers, you could find 16 as the highest match between them.
9th Jul 2018, 6:05 PM
John Wells
John Wells - avatar