Given an input sentence consisting of one or more words [a-z]+
and zero or more spaces , output an ASCII-art histogram (bar graph) of the letter distribution of the input sentence.
The histogram must be laid out horizontally, i.e. with the letter key along the bottom in alphabetical order from left to right, with a Y-axis labeled 1-
and every 5 units. The Y-axis must be the smallest multiple of five that is at least as tall as the tallest bar, and must be right-aligned. The X-axis is labeled with the input letters, with no gaps between. For example, input a bb dd
should have label abd
and not ab d
, skipping the c
. The bars themselves can be made of any consistent ASCII character -- I'll be using X
here in my examples.
test example
5-
X
X X
1-XXXXXXXX
aelmpstx
Since there are three e
, two t
, and one of almsx
.
More examples:
the quick brown fox jumped over the lazy dogs
5-
X X
X X
XX X X X XX
1-XXXXXXXXXXXXXXXXXXXXXXXXXX
abcdefghijklmnopqrstuvwxyz
now is the time for all good men to come to the aid of their country
10-
X
X
X X
X X X
5- X X X
X X X X
X XX XXXX X
XXXXX XXXXXXX X
1-XXXXXXXXXXXXXXXXXX
acdefghilmnorstuwy
a bb ccc dddddddddddd
15-
X
X
10- X
X
X
X
X
5- X
X
XX
XXX
1-XXXX
abcd
a bb ccccc
5- X
X
X
XX
1-XXX
abc
I/O and Rules
- Input can be taken in any reasonable format and by any convenient method. This also means you can take input in all-uppercase, if that makes more sense for your code.
- Leading/trailing newlines or other whitespace are optional, provided that the characters line up appropriately.
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- Output can be to the console, returned as a list of strings, returned as a single string, etc.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.