6 kyu

Errors : histogram

31 of 2,501g964

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".
Fundamentals
Strings

Similar Kata:

Stats:

CreatedOct 28, 2017
PublishedOct 28, 2017
Warriors Trained6950
Total Skips854
Total Code Submissions15149
Total Times Completed2501
Shell Completions31
Ruby Completions80
Java Completions244
Python Completions715
C Completions94
C# Completions208
C++ Completions213
Scala Completions43
Julia Completions13
R Completions36
PowerShell Completions25
Go Completions106
JavaScript Completions492
Nim Completions5
PHP Completions77
Rust Completions101
Clojure Completions18
Racket Completions9
TypeScript Completions49
F# Completions17
VB Completions29
Kotlin Completions58
Groovy Completions12
Pascal Completions5
Perl Completions13
Lua Completions27
Elm Completions5
D Completions3
Total Stars91
% of votes with a positive feedback rating88% of 479
Total "Very Satisfied" Votes383
Total "Somewhat Satisfied" Votes78
Total "Not Satisfied" Votes18
Total Rank Assessments8
Average Assessed Rank
6 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • g964 Avatar
  • siebenschlaefer Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • hobovsky Avatar
  • akvptp Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad