It is very hard to remember my password, so I came up with a way to generate a password.
The way I generate my password is from a word or a sentence, following these steps:
Start from left to right
Find the count of each letter
Put letter with its count in an order
Letters with higher repetition will be in the end
Letters with the same repetition will be ordered alphabetically
Numbers and special letters will be ignored including whitespace (e.g. 9, 4, @, (, *, etc. are ignored)
Group letters ignoring case. In the output, use the case of the last occurrence in the input
- The count of the letter can be any number e.g. 5H17M345K
- If input is all numbers or special letters then output will be empty string e.g. Input "12$*34^!" then output ""
- when order for the same occurrence alphabetically case does not matter e.g. 1a1B1c
Example:
Input: Kitkat Tango
(2k / 1i / 3T / 2a / 1n / 1g / 1o)
Output: 1g1i1n1o2a2k3T
Another example:
Input: Database Partitions Task
(1D / 5a / 4T / 1b / 3s / 1e / 1P / 1r / 2i / 1o / 1n / 3s / 1k)
Output: 1b1D1e1k1n1o1P1r2i3s4T5a
Note: the letters with 1 repeat are in the beginning ordered alphabetically then the letters with more reps
This is code-golf, the shortest code wins.
1.
add at least 1 test case that includes more than 9 occurrences of one or more letters,2.
specify that output must be a string (although I'd strongly recommend against being that strict; it adds nothing to the challenge),3.
specify that we must be able to handle inputs containing no letters, and,4.
clarify whether or not we need to handle an empty string as input. \$\endgroup\$1
. Also, in the future you might consider using our Sandbox to try to iron out issues like these before posting a challenge. \$\endgroup\$