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.
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
- 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 output
- 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
Input → average → output
Hello, world! →
Code golf →