Every letter in the English alphabet can be represented as an ASCII code. For example, a is 97, and S is 83. As we all know, the formula for averaging two numbers \$x\$ and \$y\$ is \$\frac{x+y}{2}\$. I'm pretty sure you can see where this is going. Your challenge is to average two letters.


Your program must take two letters as input, and output the average of the ASCII values in it. If the average is a decimal, you should truncate it.

  • Input will always be two ASCII letters. You can assume they will always be valid, but the case may vary. Basically, both letters will be in the range 97-122 or 65-90. The second letter will always have a greater ASCII value than the first. If your language has no method of input, you may take input from command line arguments or from a variable.
  • You must output the ASCII character signified by the average of the two numbers. As stated above, it should always be truncated to 0 decimal places. If your language has no method of output, you may store it in a variable. Exit codes and return values are considered valid output methods.

Example I/O

  • Input: A, C
    Output: B
  • Input: a, z
    Output: m
  • Input: d, j
    Output: g
  • Input: B, e
    Output: S
  • Input: Z, a
    Output: ]


This is , so shortest answer in bytes wins!

  • 2
    \$\begingroup\$ Please specify whether, for example, B e is a valid input. \$\endgroup\$ Commented Nov 10, 2019 at 19:53
  • 4
    \$\begingroup\$ Why is the output of the last example U? The value of B is 66 and the value of e is 101, which averages to 83.5, truncated to 83, which corresponds to S \$\endgroup\$ Commented Nov 10, 2019 at 23:05
  • 1
    \$\begingroup\$ If that example is correct, it will invalidate all of the existing answers. \$\endgroup\$
    – user85052
    Commented Nov 11, 2019 at 10:05
  • 1
    \$\begingroup\$ Sorry. I read an ASCII table wrong and got 69 for B, not 66. \$\endgroup\$
    – sugarfi
    Commented Nov 11, 2019 at 14:00
  • \$\begingroup\$ Could I enter for a non-ASCII compliant system? \$\endgroup\$ Commented Nov 25, 2019 at 17:28

93 Answers 93

1 2 3

Ruby, 45 bytes


Attempt This Online!

  • \$\begingroup\$ 32 bytes taking input separated by newlines \$\endgroup\$
    – naffetS
    Commented Apr 9, 2022 at 20:48

J-uby, 22 bytes


Attempt This Online!


:* & :ord | +:+ | ~:/ & 2 | :chr

:* & :ord |                       # Map with .ord, then
            +:+ |                 # sum, then
                  ~:/ & 2 |       # integer divide by two, then
                            :chr  # convert to character

Uiua, 18 bytes


Try It


⍜∩utf # convert both chars to ints, 
      # apply the operation in parentheses, and undo the char to int conversion
     (⌊÷2+) # calculate a floored avg
         + # sum both elements
       ÷2 # divide by two
      ⌊ # floor the result
1 2 3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.