| Bytes | Lang | Time | Link |
|---|---|---|---|
| 082 | AWK | 250825T193515Z | xrs |
| 015 | Uiua | 231021T191044Z | chunes |
| 063 | Zsh | 221110T175550Z | roblogic |
| 004 | Nekomata | 230720T100914Z | alephalp |
| 002 | Thunno 2 G | 230720T090822Z | The Thon |
| 018 | Octave | 230428T191139Z | Hunaphu |
| 022 | Arturo | 221109T065356Z | chunes |
| 094 | Lua | 230429T191942Z | bluswimm |
| 009 | Stax | 230227T160741Z | emirps |
| 014 | CJam | 230221T145428Z | emirps |
| 035 | ><> | 221220T000727Z | Jo King |
| 4440 | ><> | 221108T142550Z | Emigna |
| 070 | Python 3 | 221219T120624Z | U13-Forw |
| 030 | Juby | 221115T204442Z | Jordan |
| 027 | Raku | 221114T172938Z | hkdtam |
| 120 | C++ gcc | 221110T010143Z | huanglx |
| 125 | TSQL | 221108T144605Z | t-clause |
| 031 | MATLAB | 221108T133617Z | robbie c |
| 081 | C clang | 221105T154955Z | jdt |
| 073 | PHP 8.x | 221105T161345Z | Ismael M |
| nan | ><> | 221105T180314Z | mousetai |
| 009 | Japt h | 221105T184625Z | Shaggy |
| 108 | Go | 221107T144813Z | bigyihsu |
| 012 | BQN | 221108T182939Z | DLosc |
| 013 | APLDyalog Unicode | 221108T165143Z | Aiden Ch |
| 018 | J | 221108T154424Z | south |
| 056 | Java 8 | 221107T100809Z | Kevin Cr |
| 004 | MathGolf | 221107T094021Z | Kevin Cr |
| 070 | Excel ms365 | 221107T074823Z | JvdV |
| 034 | Julia | 221106T090819Z | Kirill L |
| 011 | K ngn/k | 221105T143754Z | oeuf |
| 056 | Knight v2 | 221106T022317Z | Aiden Ch |
| 068 | Wren | 221106T014942Z | chunes |
| 012 | Pip | 221106T011732Z | Aiden Ch |
| 004 | 05AB1E | 221105T141801Z | The Thon |
| 004 | Jelly | 221105T205333Z | naffetS |
| nan | Fig | 221105T203139Z | naffetS |
| 003 | Vyxal G | 221105T202548Z | naffetS |
| 029 | Mathematica | 221105T202325Z | hakr14 |
| 007 | Pyth | 221105T202101Z | hakr14 |
| 038 | R | 221105T200451Z | pajonk |
| 038 | sclin | 221105T180256Z | Mama Fun |
| 024 | Factor | 221105T154830Z | chunes |
| nan | Sequences | 221105T135411Z | The Thon |
| 816 | Nibbles | 221105T143833Z | Dominic |
| 048 | Ruby | 221105T142844Z | touka |
| 058 | JavaScript Node.js | 221105T140346Z | Arnauld |
| 046 | Python | 221105T135155Z | The Thon |
| 015 | Charcoal | 221105T140248Z | Neil |
| 006 | Husk | 221105T140115Z | Dominic |
AWK, 82 bytes
@load"ordchr"
{for(t=i=0;i++<NF;)t+=ord($i);s[++j]=t/--i}END{asort(s);print s[NR]}
Uiua, 15 bytes
/↥∵(÷⊃⧻/+-@\0⊔)
/↥∵(÷⊃⧻/+-@\0⊔)
∵( ) # map over input
⊔ # unbox a string
-@\0 # subtract null character
÷⊃⧻/+ # mean
/↥ # max
Zsh, 63 bytes
for w;c=&&for a (${(s::)w})((c+=#a,o=1.*c/$#w,m=o>m?o:m))
<<<$m
for w; implicitly iterates over the arguments ($@).
for a (${(s::)w}) iterates over each letter in word w.
c accumulates the ascii sum
o is the average ord for w
m is the maximum o found
Edit: Saved 6 bytes by chaining 3 math expressions in the parentheses((,,))!
Thunno 2 G, 2 bytes
€m
Take the mean of €ach string in the (implicit) input list (this automatically converts to codepoints). Then, take the Greatest item.
Lua, 94 bytes
I tried two approaches here, both of which ended up having the same byte count.
List of Arguments
m=0 for i=1,#arg do n=0s=arg[i]s:gsub('.',load'n=s.byte(...)+n')m=math.max(m,n/#s)end print(m)
Space Delimited String
m=0(...):gsub('%S+',load'n=0s=...s:gsub(".",load"n=s.byte(...)+n")m=math.max(m,n/#s)')print(m)
Stax, 10 9 bytes
é)u6║"⌂w╙
This is a PackedStax program, which unpacks to the following:
{:V}kTlE:_
Explanation (unpacked)
{ }k # map the following over all the values in the input
:V # get the mean of the array
T # Get the maximum of this map
l # The output is a fraction, so it must be listified
E # Explode this list onto the stack
:_ # Float division
CJam, 19 14 bytes
{:d_:+\,/}%$W=
A function which takes an input as an array. Link includes test cases.
Explanation
{:d_:+\,/}%$W= # function which takes an array as input
{ }% # for each value in the input array...
:d # short map `:` the operator `d` to convert into an array of `d`oubles
_:+ # duplicate and sum
\ # swap
, # get the length of the array
/ # divide, giving the average
$ # perform a $ort on the resulting array
W= # and get index `W` (shorthand for `-1`), which is the last value of the sort, or the max
><>, 36 35 bytes
000\&l3-,:{:@)?$&0(?n1[!
"(?\+:i:"!
Words are separated by spaces (or characters less than space like newline). This uses the length of the stack rather than a counter to get the length of the word.
><>, 65 45 44 40 bytes
000i:"!"(?v+$1+$20.
$~$0(?n00.>@$,:{:@(?
Takes input as a space separated string.
Python 3, 71 70 bytes
lambda l:max(map(lambda s:mean(map(ord,s)),l))
from statistics import*
J-uby, 43 38 36 30 bytes
-5 bytes thanks to Steffan
Originally based on TKirishima's Ruby answer.
:*&:/%[:bytes|:sum,:+@|Q]|:max
Explanation
:* & :/ % [ :bytes | :sum, :+@ | Q ] | :max
:* & # Map with...
:bytes | :sum # Sum of bytes
:/ % [ , ] # Divided by
:+@ | Q # Length converted to float
| :max # Get max
C++ (gcc), 166 120 bytes
-46 thanks to the combined efforts of @ceilingcat and @jdt.
#import<bits/stdc++.h>
auto f(auto a,float*r){*r=0;for(char*t:a){int u=0,s=0;for(;*t;u+=*t++)s++;*r=fmax(*r,(0.+u)/s);}}
Original Answer:
Attempting to apply general-purpose programming to code golf doesn't seem to work out well.
#import<bits/stdc++.h>
auto g(char*a){int t=0,s=0;for(a--;*++a;s++,t+=*a);return(0.0+t)/s;}auto f(std::list<char*>a){float m=0;for(char*t:a)m=m>g(t)?m:g(t);return m;}
Ungolfed:
// Gets the average ord value of a string
auto g(char* a) {
int t=0, s=0; // Running total and size
for (a--;*++a;s++,t+=*a); // Loop until a equals 0 and add a onto the running total
return (0.0+t) / s; // Cast to float by adding 0.0 and divide the total by the size.
}
// "Main" function
auto f(std::list<char*> a) {
float m = 0; // Maximum value
for (char* t : a) { // Loop through all the strings in the list
m = m>g(t)?m:g(t); // If m is greater than the output from the function, return m. Otherwise, return the output of the function
}
return m; // m is the final result that we want
}
T-SQL, 125 bytes
WITH C as(SELECT len(x)m,0b,*FROM @
UNION ALL SELECT m-1,b+ascii(right(x,m)),x
FROM C WHERE
m>0)SELECT max(b*1./len(x))FROM c
MATLAB, 39 31 bytes
@(s)max(cellfun(@(x)mean(x),s))
Matlab unfortunately doesn't convert strings ("") directly to ASCII values using the double function, and if converted to char type then a string array will be padded with spaces to make a proper matrix. As a result, the input is a cellstr type, which needs to be looped over using the cellfun function with an anonymous function that takes the average of the unicode values of the strings (''). The output is then the maximum of those values.
edit: -8 bytes thanks to Guiseppe
C (clang), 87 86 84 81 bytes.
v;*p;f(**t,float*r){for(*r=0;p=*t;*r=fmax(*r,v*1./(p-*t++)))for(v=0;*p;)v+=*p++;}
PHP 8.x, 75 73 bytes
Creates an anonymous function that returns the expect values, hopefully.
fn($x)=>max(array_map(fn($z)=>array_sum(unpack('C*',$z))/strlen($z),$x));
-2 bytes thanks to Sʨɠɠan.
How does it work?
This uses the unpack('C*', ...) function to convert all characters into an unsigned char (0-255).
This assumes all characters are part of the ASCII table.
Then it calculates the average using array_sum([...])/strlen([...]).
The function array_sum() takes an array and returns the sum of all elements, and strlen() returns the length of the string.
The function max() takes the array with the averages and returns the highest value from it.
Anonymous functions implicitly return values.
Example usage
You need to assign this to a variable, or call with call_user_func() or call_user_func_array():
<?php
$fn = fn($x)=>max(array_map(fn($z)=>array_sum(unpack('C*',$z))/strlen($z),$x));
// Should output: float(110.4)
var_dump($fn(['hello', 'world', 'bye']));
You can try this here (with test examples): https://onlinephp.io/c/2a424
><>, 80 51 48 bytes
0>0001.
$i:"!"(?v+$1+
(@:{:,$&/
v?(0&~$?/.02
\n;
Requires a extra space at the end of the input. Also assumes no 2 spaces in a row. (no 0 length words). Anything with ORD of 32 or lower is considered white-space.
Explanation
Top row: Push 3 0s on to the stack. The first is the current best ORD, the second is the length of the current word, and the last is the sum of the ord values of the current word. 01. is a jump to the next row.
The second row sums a word. If a character is less than "!" (char value 33) go down. Otherwise sum the word and increment the length. `$1+
In the third row, we fist push the last value to the register & . We use this to later check if this was the end of the string. Then we divide by the length to get the new ORD value. Then we use the :{:@ trick to copy the stack if it has only 2 elements (which is always the case) from the stack and compare them. If the new one is better we swap the stack with $. In either case we delete the top item.
Lastly, we take the value of the register and check if it is negative, &0(?. If so, we print the maximum ord and exit. If not, we jump back to 00. To get the correct direction we use the 00!.| trick.
Japt -h, 9 bytes
Takes input as an array of character arrays.
®xc /ZlÃñ
®xc /ZlÃñ :Implicit input of 2D array of characters
® :Map each sub-array Z
x : Reduce by addition of
c : Codepoints
/ : Divide by
Zl : Length of Z
à :End map
ñ :Sort
:Implicit output of last element
Go, 132 108 bytes
func f(S[]string)(m int){for a,s:=range S{a=0
for _,r:=range s{a+=int(r)}
if a=a*10/len(s);a>m{m=a}}
return}
- -24 bytes by @Sʨɠɠan: return as an int, multiplied by 10
BQN, 13 12 bytes
-1 byte inspired by Aiden Chow's APL answer
⌈´+´∘-⟜@¨÷≠¨
Anonymous tacit function; takes a list of strings and returns a float. Try it at BQN online!
Explanation
⌈´+´∘-⟜@¨÷≠¨
≠¨ Length of each string
÷ Divide the following by the above:
+´∘ Sum of
-⟜@ Subtract null character from (each character in)
¨ Each string
⌈ Get the maximum of the resulting list of averages
APL(Dyalog Unicode), 14 13 bytes SBCS
-1 bytes thanks to Adám
⌈/+⌿∘⎕UCS¨÷≢¨
A tacit function which finds the maximum ord. Originally wrote a dfn, but I tried random stuff to convert it to tacit and it somehow worked out.
⌈/+⌿∘⎕UCS¨÷≢¨
¨ ⍝ for each element in the input...
⎕UCS ⍝ convert the characters to their ascii values...
+⌿∘ ⍝ and sum the resulting ascii values...
÷ ⍝ divided by...
≢¨ ⍝ the length of each element...
⌈/ ⍝ and take the maximum of that
J, 18 bytes
[:>./(1#.3&u:%#)&>
Accepts list of boxed strings
[:>./(1#.3&u:%#)&>
[: NB. cap, [: f g y -> f (g y)
&> NB. for each input item, result will be unboxed
( ) NB. monadic fork
# NB. length
3&u: NB. convert input to list of char codes
% NB. vectorized division
1#. NB. sum the result to compute average
>./ NB. max item
Java 8, 81 79 56 bytes
a->a.mapToDouble(s->s.chars().average().orElse(0)).max()
Input as a Stream<String> and output as an OptionalDouble.
Explanation:
a-> // Method with String-Stream parameter & OptionalDouble return-type
a.map // Map over the input-Stream
ToDouble(s-> // and convert them to a Stream of Doubles
s.chars() // Convert the String to an IntStream of its codepoint integers
.average() // Then take the average of that IntStream (as OptionalDouble)
.orElse(0)) // And convert the OptionalDouble to double
// (`.orElse(0)` is shorter than `.getAsDouble()`)
.max() // After the map: leave the maximum (again as OptionalDouble)
MathGolf, 4 bytes
$m▓╙
Input as a list of lists of characters.
Explanation:
$ # Get the codepoint of each inner-most character of the (implicit) input-list
m # Map over each list of integers:
▓ # Pop and push the average of the list
╙ # After the map: pop and push the maximum
# (after which the entire stack is output implicitly as result)
Excel (ms365), 70 bytes
Formula in F1:
=MAX(MAP(A1:C1,LAMBDA(a,SUM(CODE(MID(a,SEQUENCE(LEN(a)),1)))/LEN(a))))
K (ngn/k), 18 11 bytes
|/{+/x%#x}'
Massive -7 bytes golf thanks to Steffan!
Damn everyone is answering quick. Anyways here's my solution. Takes input as a list of strings.
Explanation:
|/{+/x%#x}' Main function. Takes implicit input
' For each string in the input...
{ } Execute a function that...
+/x Takes sum of every character in the string
% And divide it by
#x The length of the string
|/ Get the maximum value
Knight (v2), 56 bytes
;=mF;W=pP;=s!=i~1;W>Lp=i+1i=s+*10A Gp iTs&<m=t/sLp=m tOm
Because Knight doesn't support floating point values, it outputs the maximum average ord multiplied by \$10\$, as allowed by the rules:
It may be rounded to any number (\$\ge1\$) of decimal places. If your language does not support floating points, you may output the average multiplied by 10.
05AB1E, 10 9 4 bytes
ÇÅAà
-5 thanks to Sʨɠɠan
Explained:
ÇÅAà # Implicit input as a list
# Implicit map over the input:
Ç # Get the ord of each character
ÅA # Get the average of the ords
à # Get the maximum value
Fig, \$6\log_{256}(96)\approx\$ 4.939 bytes
]KemMC
]KemMC
C - Charcodes
emM - Mean of each
K - Sort
] - Last
Pyth, 7 bytes
eSm.OCM
Explanation:
eSm.OCM | Full program
eSm.OCMdQ | with implicit variables
----------+-------------------------------
m Q | For each word in the input,
CMd | Get the ord of each character
.O | Get the average
eS | Get the max
R, 38 bytes
\(x)max(sapply(Map(utf8ToInt,x),mean))
Map(utf8ToInt,x) # for every string in the input, store the vector of its codepoints in a list
sapply( ,mean) # apply mean to each of the list elements and return a vector
\(x)max( ) # take max
sclin, 38 bytes
"dup S>c0\+ fold rev len /"map0\| fold
Try it here! This might be a good case for adding sum/prod/min/max functions to sclin, the fold construct is alright but it could be better.
For testing purposes:
["hello" "world" "bye"] ; 30N>d n>o
"dup S>c0\+ fold rev len /"map0\| fold
Explanation
Prettified code:
( dup S>c 0 \+ fold rev len / ) map 0 \| fold
Assuming input list xs.
(...) mapmap over xs...dup S>cget codepoints0 \+ foldsumrev len /divide by length (i.e. average)
0 \| foldmaximum
Sequences, \$9 \log_{256}(96) \approx 7.41\$ bytes
[$v$aH]gM
Explanation
[$v$aH]gM // Implicit list of string input
[ ] // Loop through the input list:
$v$ // Get a list of ords of each character
aH // Get the average and append to `g`
g // Push the list `g`
M // Get the maximum value
// Implicit output
Nibbles, 8 bytes (16 nibbles)
`/.$/*+.$o$10,$]
Nibbles works only in integers, so this returns the maximum average ord multiplied by 10 (and rounded-down to a whole number).
`/.$/*+.$o$10,$]
.$ # map over each input string
.$ # map over each character
o$ # getting it's ord
+ # sum them all
* 10 # multiply by 10
/ # and divide by
,$ # the length of the string
`/ # finally, fold over the list
] # getting the max of each pair
Ruby, 48 bytes
->l{l.map{_1.chars.sum(&:ord)/_1.size.to_f}.max}
As the division of two integers in ruby gives an integer, and what was expected was a float, it's long :/
And .fdiv is one byte longer
JavaScript (Node.js), 58 bytes
a=>Math.max(...a.map(s=>eval(Buffer(s).join`+`)/s.length))
Python, 46 bytes
lambda l:max(sum(map(ord,s))/len(s)for s in l)
Unfortunately, the only built-in mean function Python has is in the statistics module, and that's too expensive to import.
Charcoal, 15 bytes
WS⊞υ∕ΣEι℅κLιI⌈υ
Try it online! Link is to verbose version of code. Takes input as a list of newline-terminated strings. Explanation:
WS
Repeat until the end of the list is reached...
⊞υ∕ΣEι℅κLι
... take the ordinals of the characters in the string, and divide their sum by the string's length.
I⌈υ
Output the maximum average.
Husk, 6 bytes
▲moAmc
Outputs the highest average ord value as an exact fraction.
▲moAmc
mo # map 2 functions over each element of input
mc # get ord values of each character
A # get the average of those
▲ # output the maximum.



