Inspired by this

## What is an average character?

Say we have a string golf(). We then take the ASCII value of each separate symbol, so our string is 103 111 108 102 40 41, and calculate the average of those values, rounded to an integer. In our case the average is 505 / 6 = 84.1666... = rounded to 84. That value is printed out as an ASCII character, in our case T.

# Rules

You must take no input and must not read the source code directly, while outputting the average character of its source code. Integers are rounded by function floor(x+0.5). Empty programs are not allowed. This is code-golf, so lowest byte count wins!

• Average Character Calculator (only works for unicode characters input) Jul 19, 2020 at 19:02
• While I like the idea, it would have been beneficial to restrict code to contain at least two different characters, neither of which can be identical to the average.
Jul 19, 2020 at 19:07
• @Adám yeah, for some reason I didn't think of hardcoding the output... Maybe somebody could turn this into an interesting question, as I think its too late to edit this question.
– Dion
Jul 19, 2020 at 19:10
• @Dion You could post in the Sandbox a variant where the scoring works best for longer programs, or where the average/sum plays some role (just spitballing ideas) Jul 19, 2020 at 19:38
• @Dion Empty program would result the average value of round(0 / 0). It is invalid simply due to divided by zero. So I don't think the empty source code should be allowed. If it must be allowed, by using the definition of division, x / y = z is y * z = x, one may argue output any single character should be allowed.
– tsh
Jul 20, 2020 at 6:25

# ///, 1 byte

A


Try it online!

As it is 1 byte, simply outputting the source code gives the average. /// just outputs the source code unchanged if it doesn’t contain any / characters, so almost any ASCII character works in place of A

• +1 Right tool for the job.
Jul 19, 2020 at 19:04
• Could we do a CW of languages which can implicitly output a single character? Retina, Jelly, etc. Jul 19, 2020 at 19:06
• @fireflame241 Looks like Adàm may have Beat you to it Jul 19, 2020 at 19:08
• Also works for Charcoal.
– Neil
Jul 19, 2020 at 21:38
• Also works for Keg/Canvas/Carrot.
– user92069
Jul 20, 2020 at 0:35

'"'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'"""

Note that the average character is $ and does not appear in the source code, which contains only 37 's and 74 "s. # Malbolge, 17 bytes (=<;:9876543210TA  Try it online! Test the code average Explanation: (=<;:9876543210TA ( Copies the value pointed by register d to register d. (d = 0 so it copies the '(' ASCII value) =<;:9876543210 Succesive calls to the crazy operation to update the value in register a until the value stored meets the code average T Prints the value in a A Ends the program  Luckily this time we don't need to cope with Malbolge's code encryption feature. # HQ9+ Family, 1 bytes Q  Believe it or not, there are challenges can be solved by HQ9+ in 2020. • Don’t know whether this counts as indirectly or “directly reading own source code.” But I upvoted immediately for the clever meta-ness and original use of such a ‘done’ language! Jul 21, 2020 at 10:41 • This challenge can also be solved by cat in 2020. Jul 22, 2020 at 12:29 • The fact that you can solve this challenge with HQ9+ and also with cat makes it a particularly lame challenge in 2020. Jul 22, 2020 at 12:30 # Python 2, 8 bytes print"Y"  Try it online! Average Character Verified • Also compatible with Lua Jul 20, 2020 at 5:58 • And with Perl too! Jul 20, 2020 at 9:19 # APL (Dyalog Unicode) and lots of other languages and REPLs, 1 byte 4  Try it online! However, more interesting is: ''''  Which actually evaluates to the single quote. Try it online! # brainfuck, 15 bytes +[+++++>+<]>++.  Try it online! Requires an 8 bit interpreter as it uses modulo 256 arithmetic. Average is 53.4. Outputs 5 which is character 53. # COW, 11 8 bytes BOOM!!  Explosively prints 0 (average 48.375), using the fact that all non-instructions (B, !!, and the two newlines) are no-ops. ### 6 bytes I'm retaining the 8-byte version above because it's my favourite, but here's a 6-byter thanks to @JoKing: OOM!  (Note the code ends with two tabs.) Also prints 0 (average 47.66...). And here's another, with an average of exactly 48: OOM!  # COW, 87 78 bytes MoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMOOMMMMOOmoOMoOmOoMOomooMMMMOomoomoOMoo  No no-ops this time. Prints [ (average 90.54...) by counting up to 91. ### Commented MoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoO push 13 to first memory block MOO begin outer loop MMM copy value to register MOO begin inner loop moO switch to second memory block MoO increment mOo switch to first memory block MOo decrement moo end inner loop MMM paste register value into first memory block MOo decrement moo end outer loop moO switch to second memory block Moo print as ASCII character  • BOOM!! Out of mana! - Don't we know those lines? Jul 22, 2020 at 9:26 # R, 8 bytes cat("B")  or cat('C')  Also, cat(8)  (with 2 null bytes) doesn't work on TIO, but works in RStudio on my Kubuntu machine. # Pyramid Scheme, 29 bytes  ^ / \ /out\ ^----- -  Try it online! This has an average of ~48.137, so this outputs 0. If we're allowed a trailing newline, then we can get 4 bytes ^, -  Try it online! Again, this outputs 0, but by printing the return of the pyramid, which has an extra newline # cat, 1 byte a  If your challenge can be competitively solved with cat, there is probably something wrong with the challenge. • Assuming cat is allowed, isn't this reading its own source code? Jul 21, 2020 at 19:24 • @Calculuswhiz No, cat is just the interpreter. Every interpreter has to read the source code of the program. There's no instruction in this program which reads the source code, only one that outputs the letter a. Jul 21, 2020 at 19:32 # Retina 0.8.2, 1 byte 0  Try it online! Works by counting the number of 0s in the input. This can of course be extended to any arbitrary number of bytes just by repeating the number of 0s, or substituting other characters which happen to have an average byte value of 0, e.g. .2, as long as the result remains a valid regular expression that doesn't match the empty string. Without using a Match (count) stage, I think the minimum possible is 3 bytes: ^ 4  This program outputs 4, whose ASCII code 52 is the average of 94 (for ^) and 10 (for the newline). • If 0 outputs 0, what stops a .2 outputing 0 too? – tsh Jul 20, 2020 at 8:08 • @tsh Yeah, I thought of that myself overnight, almost any two ASCII characters with an average of 0 will work. – Neil Jul 20, 2020 at 9:50 # Perl 5 + -M5.10.0, 67 bytes I know this isn't the shortest, but I think it's what OP was after. $_=q{$_="\$_=q{$_};eval";$-+=ord for/./g;say chr(.5+$-/y///c)};eval  Try it online! # Lost, 1913 11 bytes v<<<< >%(9@  -6 bytes thanks to @JoKing. The average is 57.090..., which will be rounded to 57 (character '9'). ### Explanation: Explanation of the language in general: Lost is a 2D path-walking language. Most 2D path-walking languages start at the top-left position and travel towards the right by default. Lost is unique however, in that both the start position AND starting direction it travels in is completely random. So making the program deterministic, meaning it will have the same output regardless of where it starts or travels, can be quite tricky. A Lost program of 2 rows and 5 characters per row can have 40 possible program flows. It can start on any one of the 10 characters in the program, and it can start traveling up/north, down/south, left/west, or right/east. In Lost you therefore want to lead everything to a starting position, so it'll follow the designed path you want it to. In addition, you'll usually have to clean the stack when it starts somewhere in the middle. Explanation of the program: All arrows will lead the path towards the leading > on the second line. From there the program flow is as follows: • >: travel in an east/right direction • %: Put the safety 'off'. In a Lost program, an @ will terminate the program, but only when the safety is 'off'. When the program starts, the safety is always 'on' by default, otherwise a program flow starting at the exit character @ would immediately terminate without doing anything. The % will turn this safety 'off', so when we now encounter an @ the program will terminate (if the safety is still 'on', the @ will be a no-op instead). • (: Pop the top value, and push it to the scope. This is basically used to make the stack empty if we started somewhere in the middle. • 9: Push a 9 • @: Terminate the program if the safety is 'off' (which it is at this point). After which all the values on the stack will be output implicitly. So it'll output the 9 for the average character of unicode 57. # MATLAB... and MS-DOS and Bash? 7 bytes !echo P  Outputs P. Length verification First post here. I thought this was going to be easy with MATLAB, as you can just enter a single digit number and it will return that as-is. Except that MATLAB prints more than just the number back out... >> 0 ans = 0  Same goes for strings. >> 'a' ans = 'a'  Now I might've just waved my hands and said good enough, but where's the fun in that? :) The only methods I knew of, that can print something to console without the extra ans =  would be to use the fprintf() or disp() functions. 12 Bytes. >> fprintf('T') T  9 Bytes. Note, Disp(0) and other single-digit variations will not work due to average length constraint. >> disp('J') J  These two are valid submissions, but I kept wondering... Can I do better? Then I learned I could send commands to the operating system with the Shell Escape Function. i.e. !COMMAND Except the command is sent to whatever operating system that machine is running on. Since MATLAB is available for both Windows and Unix, whatever command I choose needs to work on both; ensuring that my code runs on all machines. This more or less locked me to the single command; echo. (Kinda anti-climactic, really) A few trials and error with the output character, and I converged to the final answer. 7 Bytes. >> !echo P P  I really hope this isn't breaking any rules here... # MAWP 0.1, 3 bytes 99:  Outputs 9. Works because : and 9 are neighbours in the table, so 9: gives a value thats in between them, so adding another 9 guarantees that the average corresponds to 9 # Hexagony, 3 bytes 0!@  ## Explanation 0 Set current memory edge to 0 ! Output current memory edge as a number @ Terminate the program  # SuperMarioLang, 2 bytes :%  Try it online! A simple answer in SuperMarioLang. The only command that gets executed is : which prints the value of the currently pointed memory position (0) as a number (initially 0). The second command % never gets executed as Mario (the command pointer) falls because there is no floor under him, so the program stops. The average between : and % is 0. Also works in MarioLANG, where % is just interpreted as a comment. # Backhand, 6 bytes "o@7"  Try it online! ## Explanation " 7 Start a quote, then the character 7 o " (backwards) End a quote, output the character @ Stop the program + no-op.  # Python 3, 10 bytes print("N")  Try it online! • either print("O") or print('P') works too Jul 21, 2020 at 11:10 • A more fun idea is print(chr(82)). Apr 13, 2021 at 18:22 # Java (JDK), 4 bytes A->9  Try it online! Outputs the number 9 which as a character is the average character of the code. Defined as a int f(Void v). Note that Void is an accepted argument type for "no input" challenges. If an int isn't an acceptable output for this challenge, the following is most definitely valid, for an extra byte. A->56  Try it online! Outputs 8 which is the average character. Defined as a char f(Void v). I was surprised that no casting to char was required, but it beats v->';' by one byte. • It's an implicit narrowing conversion; any constant integer expression whose value is between 0 and 65535 can be used where a char is expected. – Neil Jul 23, 2020 at 0:13 # Ruby, 6 bytes $><<?8


average is 56.16

$cat mean.rb$><<?8
$ruby mean.rb 8$ python -c "[print(chr(int(0.5 + sum([ord(c) for c in s])/len(s)))) for s in [l.strip() for l in open('mean.rb')]]"
8

• p ?E outputs "E", but I don't think it's acceptable. Jul 21, 2020 at 13:16
• oops, somehow I dropped the leading char when calculating the average. Fixed. Jul 21, 2020 at 17:42
• Your code works fine now. The average is still wrong, though. Jul 21, 2020 at 21:02

# SQLite, 9 bytes

SELECT"@"


Try it online!

# Befunge-93, 5 3 bytes

.@!


Try it online!

.@ prints 0. ! was added so the average is 47.667, which rounds to 48, which is the ASCII code for 0.

# brainfuck, 16 bytes

Outputs 6, the average of the program.

-[>+<-----]>+++.


Try it online!

# JavaScript (Node.js), 5 bytes

()=>3


Try it online!

• That returns 3, but outputs nothing. Jul 20, 2020 at 4:32
• Jul 20, 2020 at 5:20
• The example specifically says printed out. Jul 20, 2020 at 5:26
• @GirkovArpa that would but that only works on a repl environment Jul 21, 2020 at 17:01
• @GirkovArpa the average of _=>3 would be C not 3 Jul 21, 2020 at 17:04

# JavaScript (Browser), 10 bytes

alert('M')


Try it online!

• Aug 6, 2020 at 8:48

# AlphaBeta, 10 bytes

edaaaaaCLz


Try it online!

# 05AB1E, 1 byte

0


Or any other single digit.

Try it online.

# Z80Golf, 4 bytes

00000000: 3e 91 ff 76


Try it online!

This is ld a, 0x91rst 0x38 (putchar) → halt.

It prints a single 0x91 byte, and (0x3e + 0x91 + 0xff + 0x76) / 4 = 0x91.