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 '20 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 '20 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 '20 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 '20 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 '20 at 6:25

## Batch, 7 bytes

@echo U

I used the average character calculator to calculate the average of @echo (with trailing space) and just appended the result, as that won't change the average.

# ArnoldC, 59 bytes

IT'S SHOWTIME
TALK TO THE HAND "A"
YOU HAVE BEEN TERMINATED

Try it online!

Test the average

Mandatory answer in ArnoldC. New line characters have been added to the average as a single character of value 10.

• Sorry, I misunderstood what you meant by 'New line characters have been added to the average as a single character'. But with "B" and two newlines the average I get is 65.4237288, which rounds down to 65 (A). Jul 22 '20 at 11:42
• @Dingus you're totally right, I don't know Python and I messed up the code of the average calculator trying to adapt it. ^__^U Jul 22 '20 at 11:59
• I had similar problems myself with newlines not being counted properly by that Python code. Here is another way to do it. Jul 22 '20 at 12:05

# PowerShell, 1 byte

0

Try it online!

This will work with every single digit. It just gets echoed.

# Vim, 2 bytes

ii

Try it online!

• This is a V submission. a Vim submission would require an esc at the end. Apr 15 at 14:28
• @Razetime Why would an esc be required? Even though Vim is still in Insert mode, the intended text has still been outputted. esc would just be moving it out of insert mode and into normal mode, but as far as I can tell, there is no requirement for a Vim submission to end in normal mode, or that it can't end in insert mode. Apr 15 at 14:46
• I'm not sure, but it's the same reason why 2i2i is a V quine rather than a vim quine Apr 15 at 15:43
• I think a consensus on this would be good. Apr 15 at 16:46
• 2i2I does not double the input until <esc> is pressed, that's why it's required there. This answer should be fine
– Leo
Apr 15 at 22:03

# vim, 3 bytes

Four versions; one for each of the "insert on the same line" commands: A, a, i, and I:

• A.<ESC>
• a><ESC>
• iB<ESC>
• I2<ESC>

<ESC> is 0x1b.

(We can shave off a byte if we're willing to terminate while still in insert mode.)

Try it online! (For the A.<ESC> variant)

# Lenguage, 4 bytes

����

Is this the first time where a lenguage program is totally written?

# brainfuck, 14 bytes

+[+++++>+<]>.�

Try it online!

Forcefix average

• Apr 14 at 4:00
• @Bubbler en.wikipedia.org/wiki/ASCII says ASCII is 0-127
– l4m2
Apr 14 at 18:12
• Please provide a hexdump for programs containing unprintables. I can tell that your Lenguage program is made entirely out of null bytes, but please specify next time, as they show up as �. Apr 14 at 22:39
• @Makonede Do &#0; in every browser show ?
– l4m2
Apr 15 at 1:50
• Pretty sure yeah. I don't think it's browser-dependent though, as searching it shows that it is shown as the real U+FFFD. Apr 15 at 2:06

# Sandwich, 2 bytes

pp

Sandwich is comprised of opcodes. The first letter of each line is the opcode, and the rest of the line is the arguments.

The opcode for this code is p, which means print. The arguments are also p, which is passed to the opcode.

The result of this code is that it prints out p, AKA ASCII 112.

Since the code is 2 bytes long, simply using the same two characters will give the average of the entire code segment.

# Plumber, 191 bytes

[]
]
]
...88 more ']'...
]
]
][[=

Try it online!

Drops a packet down, which is incremented up to 92 and printed. 92 is the ASCII value for \.

# perl -Mfeature=say, 6 bytes

say"P"

Try it online!

I wrote a small program to find the program above:

#!/opt/perl/bin/perl

use 5.028;

use strict;
use warnings;
no  warnings 'syntax';

use experimental 'signatures';
use experimental 'lexical_subs';

for my $c (32 .. 127) { my$char = chr $c; my$s = qq [say"$char"]; my$score = 0;
$score += ord$_ for split // => $s;$score = int (.5 + $score / length ($s));
if ($score ==$c) {
say $s; } } __END__ Try it online! # AWK, 15 bytes BEGIN{print"X"} Try it online! # Bash, 6 bytes echo Y Try it online! echo Z Just like my Perl solution, this was found using a brute force search. # 7, 1 byte 3 Try it online! After the code cycles, 3 tries to output itself. However, 3 is an unnamed command, so it can't be directly outputted. Instead, it gets turned into 73, which is outputted. 7 specifies the output format as "the same as the input", so the 3 after it prints 3. A more interesting solution: # 7, 3 bytes (8 characters) 01116743 Try it online! This outputs 3 as a number. # naz, 8 bytes 8a9m7a1o Short and sweet. Verify the average character here. Explanation 8a9m7a # Set the register to a value of 79 1o # Output once # JavaScript (Node.js), 16 bytes console.log('U') Here's how I brute-forced the solution: const average = str => String.fromCharCode([...str] .reduce((total, char) => (total += char .charCodeAt(0)) || total, 0) / str.length); for (let i = 0; i < 2 ** 16; i++) { const char = String.fromCharCode(i); const avg = average(console.log('${char}'));
char == avg && console.log({ code: i, char, avg });
// { i: 85, char: 'U', avg: 'U' }
}

99 99 9
99 99 9
9 99
9m

Try it online!

PRINT'D'

DB Fiddle

# Rust, 23 bytes

fn main(){print!("Q");}

# SimpleTemplate, 10 bytes

This is a simple code that outputs the average character itself:

{@echo"X"}

The average was calculated previously using JavaScript:

var code = '{@echo"X"}';

var sum = code.split('').reduce((a,_)=>a+_.charCodeAt(0), 0);

document.body.innerHTML += String.fromCharCode(sum/code.length);

To get the right character, I just used a random one, until I got one where the result was the same (in this case, "X").

The rules don't specify that the character can't be pre-calculated before. They only specify that you can't read the source code or that you can't take any input.

## SimpleTemplate, 1 byte

Just simply outputs the character average:

1

This generates a PHP echo (example below):

echo (<<<'DATA6229934543895a3c69912b6e6658160198d45280523b34711abdc124745'
1
DATA6229934543895a3c69912b6e6658160198d45280523b34711abdc124745
);

You can change the line 1048 to test the desired code.

# Python 3, 11 bytes

print('K')#

The average value is 75.09, which rounds to 75 - K.

• – Dion
Jul 21 '20 at 5:06

# PHP, 1 byte

A

Try it online!

This will just output itself. Works with almost all of the printable ASCII characters.

# Whitespace, 13 bytes

I can't figure out how to put raw whitespace into a code block, so here you go:

[space][space][space][tab][space][tab][tab][space][lf]
[tab][lf]
[space][space]

Try it online

Explanation:

[space][space][space]           Push a number onto the stack
[tab][space][tab][tab][space]   Have that number be 22 (0x16)
[lf]                            End instruction
[tab][lf][space][space]         Output character from stack

procedure GNAT.IO.F is begin Put("M"); end GNAT.IO.F;

Try it online!

Why not?

# C (gcc), 15 bytes

A(){return 84;}

Average is T. Returns ASCII code.

Try it online!

• 13 bytes Jul 22 '20 at 3:38

# C - 18 chars

main(){puts("S");}

print("N")

Online demo

# PowerShell, 3 bytes

+\$A

Try it online!

(43+36+65)/3 == 144/3 == 48 == ASCII('0')

# bitch, 2 bytes

/1

Following up my COW answer with one in bitch . . . read nothing into that. Outputs 0 (average 48 exactly). / outputs the accumulator value (initialised to zero); 1 is a no-op here.

# Rust, 5 bytes

||'R'

Straightforward solution, just a closure that implements Fn() -> char.

'1:

11+:

# MAWP v1.1, 6 bytes

33W/:.

I tried a different approach from Dion's answer.