Skip to content

Conversation

@altay9
Copy link
Collaborator

@altay9 altay9 commented Jun 15, 2021

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 equal itself when it is rotated 180 degrees, it is a confusing number.

  • If it equals itself when it is rotated 180 degrees, it is a strobogrammatic number.

Therefore:

(Total numbers) - (strobogrammatic numbers) = (confusing numbers)

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.

@ErdemT09
Copy link
Collaborator

ErdemT09 commented Jun 15, 2021

image
I don't understand how it's so efficient despite its use of strings and such.

@ErdemT09 ErdemT09 closed this Jun 15, 2021
@ErdemT09 ErdemT09 reopened this Jun 15, 2021
Comment on lines 23 to 24
char first = s.charAt(0);
int res = count(first) * (int) (Math.pow(5, s.length() - 1));
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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>
Copy link
Collaborator

@ErdemT09 ErdemT09 left a 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.

@altay9
Copy link
Collaborator Author

altay9 commented Jun 16, 2021

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.

@altay9 altay9 merged commit b72f507 into master Jun 16, 2021
@altay9 altay9 deleted the ConfusingNumberII branch June 16, 2021 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1088. Confusing Number II

3 participants