Errors : histogram
Description:
In a factory a printer prints labels for boxes. The printer uses colors which, for the sake of simplicity, are named with letters from a to z (except letters u
, w
, x
or z
that are for errors).
The colors used by the printer are recorded in a control string. For example a control string would be aaabbbbhaijjjm
meaning that the printer used three times color a, four times color b, one time color h then one time color a... and so on.
Sometimes there are problems: lack of colors, technical malfunction and a control string is produced e.g. uuaaaxbbbbyyhwawiwjjjwwxym
where errors are reported with letters u
, w
, x
or z
.
You have to write a function hist
which given a string will output the errors as a string representing a histogram of the encountered errors.
Format of the output string:
letter (error letters are sorted in alphabetical order) in a field of 2 characters, a white space, number of error for that letter in a field of 6, as many "*" as the number of errors for that letter and "\r" (or "\n" depending on the langauge).
The string has a length greater or equal to one and contains only letters from a
to z
.
Examples
s="uuaaaxbbbbyyhwawiwjjjwwxym"
hist(s) => "u 2 **\rw 5 *****\rx 2 **"
or with dots to see white spaces:
hist(s) => "u..2.....**\rw..5.....*****\rx..2.....**"
s="uuaaaxbbbbyyhwawiwjjjwwxymzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
hist(s) => "u..2.....**\rw..5.....*****\rx..2.....**\rz..31....*******************************"
Notes
- Unfortunately most often Codewars compresses all white spaces into one.
- See other examples in the "Sample tests".
Similar Kata:
Stats:
Created | Oct 28, 2017 |
Published | Oct 28, 2017 |
Warriors Trained | 6950 |
Total Skips | 854 |
Total Code Submissions | 15149 |
Total Times Completed | 2501 |
Shell Completions | 31 |
Ruby Completions | 80 |
Java Completions | 244 |
Python Completions | 715 |
C Completions | 94 |
C# Completions | 208 |
C++ Completions | 213 |
Scala Completions | 43 |
Julia Completions | 13 |
R Completions | 36 |
PowerShell Completions | 25 |
Go Completions | 106 |
JavaScript Completions | 492 |
Nim Completions | 5 |
PHP Completions | 77 |
Rust Completions | 101 |
Clojure Completions | 18 |
Racket Completions | 9 |
TypeScript Completions | 49 |
F# Completions | 17 |
VB Completions | 29 |
Kotlin Completions | 58 |
Groovy Completions | 12 |
Pascal Completions | 5 |
Perl Completions | 13 |
Lua Completions | 27 |
Elm Completions | 5 |
D Completions | 3 |
Total Stars | 91 |
% of votes with a positive feedback rating | 88% of 479 |
Total "Very Satisfied" Votes | 383 |
Total "Somewhat Satisfied" Votes | 78 |
Total "Not Satisfied" Votes | 18 |
Total Rank Assessments | 8 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |