><> (Fish), 5653 50 46 bytes
i:0(l'~')?v:fg1+$fpv0
v?\~1+a\~'!':fg(0:i<]r+1r[
.\{:o} 1\~rvol-d11
)^?;a1.\o:'~'<;?('!'l~oa
There is already a slightly shorter ><> answerFinally beat the current fish answer. Note the link pre-populates the stack to make it faster but this one is mine and I'm proudunnecessary for the correctness of itthe program.
><> (Fish), 53 50 bytes
Each element of the stack stores how often the nth character appears in the input.
l'~')?v0
v?(0:i<]r+1r[
~
r
>:?vao~l'!'(?;
/ \1-lo
Try it The top row pushes ord('~')
0s to the stack.
This version actually completes beforeThe second row reads the endinput. Use [r1+r]
to get the nth element of the universestack, which is niceadd 1 to it, then put it back into place. Uses
The left (red) half of the third row reverses the stack insteadso the higher valued items are on the top. Now we know that the length of the stack is the character code of the count the top element represents. This allows very convenient printing.
The left (grey) half of the bottom row checks if the count of the nth character is 0. If so go to store how often each number appearsthe right half of the third row.
The right (blue) half of the bottom row prints a line break ao
. Then pops the top of the stack. If we now have less than ord('!')
items on the stack only spaces remain and we exit (since we shouldn't print spaces)
The right half of the third row runs if there is more than one occurrence of the top character. If so, we subtract one occurrence, then print the length of the stack as a character.