-
Notifications
You must be signed in to change notification settings - Fork 7
1088. Confusing Number II #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| char first = s.charAt(0); | ||
| int res = count(first) * (int) (Math.pow(5, s.length() - 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is being done here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findTotal is to calculate the total count of the numbers which can be generated using those five numbers: 0, 1, 6, 8, 9.
It is why we use 5 to calculate the permutation.
As the "s" is a limit for us, we have to calculate numbers less than "s".
In order to do that: count(first) returns the numbers less than the parameter (first) from this set: 0, 1, 6, 8, 9.
findTotal is recursive as we should do the calculation for each digit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When considering a number like 9999, we ignore the permutations that start with 9. But, when we calculate the next digits, we are actually calculating the number of permutations that start with 9. Pretty clear now.
Co-authored-by: ErdemT09 <63192680+ErdemT09@users.noreply.github.com>
Co-authored-by: ErdemT09 <63192680+ErdemT09@users.noreply.github.com>
ErdemT09
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good method of problem solving to reduce a problem to another one. I like how that's being done here.
Approved.
Vielen Dank für die Codeüberprüfung und für deine wertvolle Zusammenarbeit. Ich rufe bewusst eine Methode in einer anderen Klasse auf, um ein Beispiel für unsere Idee des "Lego-Bausteine" zu geben. |

Resolves: #228
As we understand here: #156, if a number is generated using the numbers: 0, 1, 6, 8, 9 and :
if it does
not equalitself when it is rotated 180 degrees, it is aconfusing number.If it
equalsitself when it is rotated 180 degrees, it is astrobogrammatic number.Therefore:
It means, we can use the code here #323, and just subtract its output from the total count of all numbers generated using 0, 1, 6, 8, 9.