26
2
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.
By 'count in each letter', do you mean how many times a letter appears in the input sentence? – Embodiment of Ignorance – 2019-01-18T03:57:22.293
17Can a letter appear more than 9 times? – Shaggy – 2019-01-18T07:58:42.710
Can we output as an array? e.g.,
["1g","1i","1n","1o","2a","2k","3T"]
or even[["1","g"],["1","i"],["1","n"],["1","o"],["2","a"],["2","k"],["3","T"]]
– Shaggy – 2019-01-18T10:29:47.910"Numbers and special letters will be ignored including whitespace (e.g. 9, 4, @, (, *, etc. are ignored)" - does this mean
[a-z][A-Z]
only? – Jonathan Allan – 2019-01-18T13:36:49.533"Letters with the same repetition will be ordered alphabetically" - usually 'D' sorts before 'a', so here do you explicitly mean "...ignoring case" or would
1D1P1b1e1k1n1o1r2i3s4T5a
be an acceptable output for "Database Partitions Task"? – Jonathan Allan – 2019-01-18T13:56:37.097Why was this put on hold? Maybe the question was initially not very nicely formatted, but it's clear enough to understand and the formatting has been fixed. – ბიმო – 2019-01-18T16:13:49.977
@BMO, I voted to close because shaggy's high voted question, which may make a difference in choosing the strategy. Is irritating to find out after you worked out and posted a solution that is either invalid or overcomplicated. I hope the OP will not take the close personally, after all there are 12 up and 0 downvotes.
– manatwork – 2019-01-18T16:30:45.7873@manatwork: But that's not unclear (note, their answer didn't assume that letters appear less than 10 times), it's just trying to loosen the input restrictions. – ბიმო – 2019-01-18T16:36:58.857
@BMO, neither of the questions I asked would make a difference to my own solution ;) Currently, though, by what's included in the challenge, it's not explicitly clear whether or not there's an upper limit on the number of times any one letter can appear in the input. Personally, I would assume not but others could easily assume otherwise. – Shaggy – 2019-01-18T17:10:56.100
@EmbodimentofIgnorance Yes – asmgx – 2019-01-19T05:09:27.727
@Shaggy Yes, it can appear as many as possible it will be 12e for example – asmgx – 2019-01-19T05:10:05.637
@Shaggy No, the output as the examples above only – asmgx – 2019-01-19T05:11:13.593
@JonathanAllan yes a-z and A-Z only – asmgx – 2019-01-19T05:12:05.600
@JonathanAllan case will be ignored in the order, D is before g so it will be 1D1g – asmgx – 2019-01-19T05:13:02.480
@manatwork nothing personal, i hope the question is clear enough – asmgx – 2019-01-19T05:15:39.340
5make sure to add these clarifications to the actual question body, so answerers don't have to hunt through the comments – Jo King – 2019-01-20T04:04:08.890
May I assume input will always be non-empty after removing non-alpha characters? e.g. input wont be
"123"
,""
ect. – tsh – 2019-01-20T07:32:24.463@tsh if input is all number then output will be empty string – asmgx – 2019-01-20T08:38:05.217
3Comments do not a specification make. You need to update the challenge to
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. – Shaggy – 2019-01-22T19:51:00.6501
Once you've done that then you will then have to test all existing solutions and inform them if they need to make any changes. I've already found quite a number of solutions that fail on point
– Shaggy – 2019-01-22T19:54:17.3471
. Also, in the future you might consider using our Sandbox to try to iron out issues like these before posting a challenge.@Shaggy I test the shortest code, if it pass then it is the answer if not, then I write a comment for them about the failure and then test the next shortest answer. – asmgx – 2019-01-22T21:06:21.013
1@asmgx You still haven't actually added the specs to the question, so it's not their fault that their solution doesn't match them. By community consensus, rules made in comments aren't valid until they are put in the actual question for this reason – Jo King – 2019-01-23T13:16:10.003
Suggested test case:
Looooooooooooooooooooooooooooaaaaaaaaaaaaaaaaaaaaaads Of The Same Letters -> 1d1f1h1m1r2L3s3t4e23a29O
(or any other test case with a letter more than 9 times) – Kevin Cruijssen – 2019-01-23T14:42:48.140I've VTCed this as unclear until all issues raised in the comments have been addressed in the spec. Please ping me when they have and I'll retract my vote (or cast my vote to reopen). – Shaggy – 2019-01-23T15:55:54.057