| Bytes | Lang | Time | Link |
|---|---|---|---|
| 077 | C# | 241028T205801Z | Ezlandin |
| 092 | AWK | 241028T160427Z | xrs |
| 047 | Raku | 241021T133941Z | Mustafa |
| 029 | APL | 241016T180915Z | Aaron |
| 016 | Japt v2.0a0 | 241016T233629Z | Shaggy |
| 038 | Mathematica | 241016T152954Z | polfosol |
| 083 | Java JDK | 241014T121902Z | mastaH |
| 007 | Vyxal 3 | 241014T145111Z | pacman25 |
| 010 | 05AB1E | 241014T090356Z | Kevin Cr |
| 063 | R | 241012T094856Z | pajonk |
| 069 | Ruby | 241013T145705Z | Jordan |
| 104 | Haskell | 241013T131405Z | Antonio |
| 047 | Perl 5 | 241013T114436Z | Kjetil S |
| 061 | Zsh | 241013T095352Z | roblogic |
| 075 | JavaScript Node.js | 241012T093002Z | Arnauld |
| 101 | Racket | 241013T020005Z | mehbark |
| 137 | Go | 241012T151143Z | bigyihsu |
| 047 | Factor | 241013T001802Z | chunes |
| 024 | APL Dyalog Extended | 241012T220355Z | Adá |
| 016 | Uiua | 241012T150327Z | janMakos |
| 070 | C gcc | 241012T131540Z | jdt |
| 082 | Google Sheets | 241012T061404Z | doubleun |
| 067 | jq Rr | 241012T115256Z | pmf |
| 077 | JavaScript Node.js | 241012T033113Z | l4m2 |
| 062 | APL+WIN | 241012T092957Z | Graham |
| 095 | Python 3 | 241012T075717Z | mecaneer |
| 068 | Arturo | 241012T062543Z | chunes |
| 062 | Retina 0.8.2 | 241012T051130Z | Neil |
| 020 | Charcoal | 241012T043518Z | Neil |
| 6125 | Vyxal | 241012T032435Z | lyxal |
C#, 77 bytes
char F(string i)=>(char)i.ToLower().Where(x=>x>96&x<123).Average(x=>x+.5);
Explanation
char F(string i) => (char) // Cast the result to a char
i.ToLower() // Lower-case the chars in the string
.Where(x=> x>96 & x<123) // Ensure the character is valid
.Average(x=> x+0.5); // Average the characters (and add 0.5 to round up)
AWK, 92 bytes
@load "ordchr";BEGIN{FS=X}{gsub(" ",X);for($0=tolower($0);++i<=NF;)x+=ord($i);$0=chr(x/NF)}1
`
@load "ordchr"; # character manipulation module
BEGIN{FS=X} # split every character
{gsub(" ",X); # remove spaces
for($0=tolower($0);++i<=NF;) # make it lowercase
x+=ord($i); # total it up
$0=chr(x/NF)}1 # average and print
Awk's default rounding should do the trick, but ymmv.
Raku, 47 bytes
(.sum/$_).round.chr with .lc.comb(/<:L>/)>>.ord
- Lowercase the input and then "comb" the letters in it, i.e., select those with the Unicode property L
- Now we have a Sequence of characters -- map them to their ordinals with
>>.ord(which is the same as.map(&ord)here but shorter) - Topicalize these Seq of ordinals with
with(givenalso works and more idiomatic sincewithcares about definedness, but it's 1 character shorter :) - Lastly get the mean, round it and query the corresponding character
APL, 32 30 29 chars
⎕UCS⌊(+/÷≢)⎕UCS⎕A(⊣(/⍨)∊)⍥⎕C⍨
Explanation
⎕UCS⌊(+/÷≢)⎕UCS⎕A(⊣(/⍨)∊)⍥⎕C⍨
⎕A ⍨ ⍝ Take the alphabet on the right and input on the left
( )⍥⎕C ⍝ Call `lowercase` on each arg before calling new inner train
(/⍨) ⍝ Explode the
⊢ ⍝ input string (right arg)
∊ ⍝ by elements in the left arg
⎕UCS ⍝ Convert to numbers
( ) ⍝ Find average (choo choo!):
÷ ⍝ divide
+/ ⍝ the sum
≢ ⍝ by the tally (count)
⌊ ⍝ Floor
⎕UCS ⍝ Convert back to letter
Japt v2.0a0, 16 bytes
v f\l
xc ÷UÊ r d
v f\l\nxc ÷UÊ r d :Implicit input of string U
v :Lowercase
f :Match
\l : /[a-z]/g
\n :Reassign to U
x :Sum of
c : Character codes
÷ :Divided by
UÊ : Length of U
r :Round
d :Character at that codepoint
Java (JDK), 91 85 83 bytes
s->(char)(s.toLowerCase().chars().filter(c->c>96&c<123).average().orElseThrow()+.5)
-6 for rounding thanks to jdt
Vyxal 3, 7 bytes
ȦøA∆AøA
Vyxal It Online! why does vyxal 3 not have a round element??? oh well
edit: apparently the letter to number auto-rounds but we still dont have a round element.
05AB1E, 10 bytes
ADIlákÅAòè
Input as a list of characters.
Try it online or verify all test cases.
Explanation:
A # Push the lowercase alphabet
D # Duplicate it
I # Push the input character-list
l # Convert it to lowercase
á # Only keep the letters, removing any other character
k # Get the 0-based index of each letter in the alphabet
ÅA # Take the average of this list
ò # Round it to the nearest integer
è # 0-based index that into the alphabet
# (after which the letter is output implicitly as result)
Minor note: it doesn't matter that 05AB1E uses 0-based indexing instead of 1-based as the challenge description, since it just means the entire average is decreased by exactly 1 after taking the average, saving an > after the k and < before the è.
R, 67 63 bytes
Edit: -4 bytes thanks to @jdt.
\(s)intToUtf8(.5+mean(utf8ToInt(gsub("[^a-z]","",tolower(s)))))
Ruby, 69 bytes
->s{t=n=0.0
s.downcase.scan(/[a-z]/){t+=_1.ord;n+=1}
(t/n).round.chr}
Haskell, 104 bytes
f x|l<-[c#64|c<-toEnum.fromEnum<$>x,let n#l=n+sum[32|l<c,c-l<27],0<0#64#96]=toEnum.round$sum l/sum(1<$l)
Surprisingly Double is an instance of Enum.
Zsh, 61 bytes
set ${(Ls::)1//[^A-Za-z]};for x;$[t+=#x];jot -c 1 $[t/$#.+.5]
Throws lots of errors because $[t+=#x] should be ((t+=#x)) but that's an extra byte.
JavaScript (Node.js), 75 bytes
s=>(B=Buffer)([s.replace(/[a-z]/gi,c=>t+=B(c)[0&n++]|32,t=n=0)&&t/n+.5])+""
Commented
s => // s = input string
(B = Buffer)([ // B = alias for Buffer
s.replace( // replace in s ...
/[a-z]/gi, // ... all letters, case insensitive
c => // for each letter c:
t += B(c)[ // add to t the ASCII code of c
0 & n++ // and increment n
] | 32, // force the code to lower case
t = n = 0 // start with t = 0 and n = 0
) && // end of replace()
t / n + .5 // compute the rounded average t / n
]) // end of Buffer()
+ "" // coerce to a string
Racket, 101 bytes
(λ(s[a(regexp-replace*"[^a-zA-Z]"s"")])(round(/(for/sum([c a])(bitwise-ior 32 c))(bytes-length a))))
Takes input as a byte string and returns an ASCII integer. (Sadly verbose) |32 trick taken from this comment. Rounds .5 to even, which is technically noncompliant, but oh well.
This is my first answer in over two years and my first Racket answer ever, so let me know if there's anything amiss.
Character output (113 bytes):
(λ(s[a(regexp-replace*"[^a-zA-Z]"s"")])(write-byte(round(/(for/sum([c a])(bitwise-ior 32 c)))(bytes-length a))))
Go, 163 137 bytes
import."unicode"
func f(s string)(o rune){for _,r:=range s{if IsLetter(r){o+=r|32-'a'}}
return rune(.5+(float64(o)/float64(len(s))+'a'))}
- -26 by not using
math, and OR-ing with 32 to lowercase it (lowercase letters have bit 5 (0-indexed) set)
Factor, 47 bytes
[ >lower 97 ..= 122 within mean round 1string ]
APL (Dyalog Extended), 24 bytes
(⌊⎕A⊃⍨∘⌊.5++⌿÷≢)27~⍨⎕A⍳⌈
⌈ uppercase
⎕A⍳ one-based indices in uppercase Alphabet (not found → 27)
27~⍨ remove 27s
(…) apply the following tacit function to that:
≢ the tally (length)
÷ divides
+⌿ the sum
.5+ added to one half
∘⌊ rounded down, then…
⎕A⊃⍨ pick that element from the uppercase Alphabet
⌊ lowercase
Uiua, 16 bytes
+@a⁅÷⧻⟜/+-@A▽⊸±⌵
Explanation
+@a⁅÷⧻⟜/+-@A▽⊸±⌵
⌵ # To uppercase
▽⊸± # Keep alphabetic
-@A # convert to alphabetic position (A: 0, B: 1, ..)
÷⧻⟜/+ # mean
+@a⁅ # round, convert to lowercase letter
C (gcc), 70 bytes
c,t;f(int*s){for(t=c=0;*s;s++)isalpha(*s)?t+=*s|32,c++:0;c=1.*t/c+.5;}
Google Sheets, 82 bytes 102 bytes
=char(0.5+average(sort(code(split(regexreplace(lower(A1),"([a-z])|.","$19"),9)))))
Put the text string in cell A1 and the formula in B1.
Uses sort() as an array enabler only. Signals undefined with 9 and error with #VALUE!.

The char() function always rounds down, hence 0.5.
JavaScript (Node.js), 78 77 bytes
x=>([...x,w=n=0].map(c=>w+=(d=parseInt(c,36))>9&&++n&&d)|w/n+.5).toString(36)
APL+WIN, 62 bytes
Prompts for string. Fails on domain error if the string does not contain any valid characters.
n[⌊.5+(÷⍴l)×+/l←(((n←⎕av[17+⍳26])⍳s)~27),(⎕av[65+⍳26]⍳s←⎕)~27]
Python 3, 98 96 95 bytes
lambda s:chr(round(sum(ord(c)-96 for c in s.lower()if c.isalpha())/sum(map(str.isalpha,s)))+96)
Retina 0.8.2, 62 bytes
T`Llp`ll_
^(.)\1+$
$1
T`@l`l@`^.
T`l@`@l`.$
}O`.
+r`.(.+).?
$1
Try it online! Link includes test cases. Explanation:
T`Llp`ll_
Lowercase letters and discard anything else.
^(.)\1+$
$1
If all the letters are the same, then just keep one.
T`@l`l@`^.
Increment the first letter.
T`l@`@l`.$
Decrement the last letter.
O`.
Sort the letters (back) into order.
}`
Repeat until the buffer stabilises, which happens either when there is one letter or the buffer only contains copies of two consecutive letters.
+r`.(.+).?
$1
Keep only the middle letter.
Charcoal, 20 bytes
≔Φ↧S№βιθ℅⁺·⁵∕ΣEθ℅ιLθ
Try it online! Link is to verbose version of code. Explanation:
≔Φ↧S№βιθ
Get the letters of the input and lowercase them.
℅⁺·⁵∕ΣEθ℅ιLθ
Take the average, rounded.
Vyxal, 49 bitsv2, 6.125 bytes
ǍøAṁṙøA
Bitstring:
1101010010111100011000100000010011100010000101010
Very literal implementation of the question.
Explained
ǍøAṁṙøA
Ǎ # Remove characters from the input that aren't letters
øA # Get the 1-based alphabet index of each letter
ṁ # Average those indices
ṙ # Round to the nearest integer
øA # And convert that back to a letter using the result as a 1-based index
💎
Created with the help of Luminespire.