You have been employed by a data analysis company, and have been appointed the task of finding the average character of a string of characters. However, this company has limited funding for code storage, so your code must be as small as possible.
Task
Write a program or function that takes one string of characters as input, and outputs the average character of that string.
Calculation of average
The average character of a string is the sum of the ASCII values of the individual characters divided by the total number of characters, then converted back to an ASCII character.
For example, the string cat
consists of the sequence 99 97 116
of ASCII values. These values summed equals 312, which then divided by 3 gives an average of 104. 104 represents the ASCII character h
. The average character of the string cat
is therefore h
.
Rules
- You can assume the input string will only contain printable ASCII characters
- If the average of the string's ASCII values is floating point, it should be rounded to the nearest integer and then converted to the equivalent ASCII character (eg. an average of 66.4 would output
B
, and an average of 66.5 would outputC
) - Input can be from STDIN (or language equivalent), or as a function parameter
- Output must be to STDOUT (or language equivalent), or as a return result if your program is a function
- Standard loopholes are not allowed
- This is code-golf, so shortest code in bytes wins
Examples
Input → average → output
Hello, world!
→ 89.3076923076923
→ Y
Code golf
→ 92.77777777777777
→ ]
8112015
→ 50.57142857142857
→ 3