g | x | w | all
Bytes Lang Time Link
023Bespoke250804T095754ZJosiah W
016Thunno 2230610T164145ZThe Thon
009Julia220224T140847ZMarcMush
191Plumber210615T172823ZAaroneou
005Zsh210530T173243Zpxeger
001Vyxal210530T172217Zwasif
001///200719T190235Zcaird co
002Excel210530T135500ZAxuary
004MATLAB/Octave210530T133430Zelementi
001Vyxal210529T221933Zemanresu
002Sandwich210415T142103Zkarx
004Lenguage210413T180518Zl4m2
005Rexx Regina210414T095327Zcnamejj
003vim210413T234420ZRay
004Grok210413T192005ZAaroneou
004Ruby210413T181754Zhistocra
002Vim210413T175637ZAaroneou
008Factor210326T161521Zwasif
006MAWP v1.1200806T075958ZRazetime
001Keg200808T120208Zlyxal
0031+ with NOP200808T105521ZTwilight
005Rust200731T224048ZTehPers
002bitch200728T140026ZDingus
002Pyth200726T171807ZViraxor
001PowerShell200726T141504Zstackpro
003PowerShell200725T124049Zmazzy
010Scala200722T222106Zuser
006Ruby200721T050013ZAShelly
018C200722T202309ZAShelly
059ArnoldC200722T100700ZCharlie
007MATLAB... and MSDOS and Bash?200722T045012Zmimocha
008COW200721T082308ZDingus
015C gcc200722T012456ZS.S. Ann
053Ada GNAT200721T230640ZLambdaBe
004><>200721T215909ZSE - sto
001cat200721T190455ZStack Ex
013Whitespace200721T173446ZEthan Ch
001PHP200721T150617ZThe rand
004Java JDK200720T172011ZOlivier
010Python 3200720T190600ZDion
007Batch200720T161024ZNeil
004Z80Golf200720T155452Zlynn
011Python 3200720T142217ZMLavrent
006Backhand200720T005841Zuser9206
002SuperMarioLang200720T132027ZCharlie
011Lost200720T093206ZKevin Cr
010SimpleTemplate200720T105320ZIsmael M
023Rust200720T113016ZVi.
017Malbolge200720T112713ZCharlie
067Perl 5 + M5.10.0200720T112332ZDom Hast
001Retina 0.8.2200719T214131ZNeil
029Pyramid Scheme200720T090917ZJo King
00105AB1E200720T091406ZKevin Cr
008R200719T224517ZRobin Ry
008TSQL200720T070413ZRazvan S
001HQ9+ Family200720T061705Ztsh
02299200720T060247ZPkmnQ
010AlphaBeta200720T052636ZPkmnQ
010JavaScript Browser200719T215258ZMatthew
005JavaScript Node.js200720T031601ZMukundan
016JavaScript Node.js200720T030837ZGirkovAr
008naz200720T023829Zsporebal
003Hexagony200720T021159ZMukundan
0017200720T014321ZPizgenal
016brainfuck200720T001553Zuser9206
015brainfuck200720T001654ZLevel Ri
008Io200720T001232Zuser9206
003Gol><>200720T001011ZBubbler
006Bash200719T223929ZAbigail
003Befunge93200719T223411ZAbigail
111Unreadable200719T225022ZRobin Ry
009SQLite200719T224721ZAbigail
015AWK200719T224456ZAbigail
006perl Mfeature=say200719T222802ZAbigail
003MAWP 0.1200719T191906ZDion
001APL Dyalog Unicode and lots of other languages and REPLs200719T190642ZAdá
008Python 2200719T190152Zfireflam

Bespoke, 23 bytes

avg~was~a`o`i~return~it

Outputs o.

Fun fact: o is tied with (space) as the shortest printable to push in Bespoke.

Thunno 2, 16 bytes

"DṘs+ĊmĊ"DṘs+ĊmĊ

Attempt This Online!

Explanation

"DṘs+ĊmĊ"DṘs+ĊmĊ  # Full program
"DṘs+ĊmĊ"         # String literal
         DṘ       # Duplicate and push the representation
           s+     # Prepend this to the original string
             Ċ    # Convert to charcodes (using Thunno 2 encoding)
              m   # Take the mean of this list
               Ċ  # Convert it back to a character (using Thunno 2 encoding)
             

Alternative (but boring) answers:

Julia, 9 bytes

print(:W)

Try it online!

also works with

:d|>print Try it online!

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 \.

Zsh, 5 bytes

<<< 5

Try it online!

Vyxal, 1 byte

7

Try it Online!

Somehow the average of this program turns out to be the luckiest number in universe

///, 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

Excel, 2 bytes

51

For once, there isn't some overly long Excel function to get in the way.

MATLAB/Octave, 4 bytes

''''

Try it online!
Outputs single ' character. And basically it's the way to write that as an immidiate value - the outer apostrofes are to indicate the value is char array so we're left with '' which is escape code for a single apostrofe.

Vyxal, 1 byte

0

Try it Online!

Any digit works.

Or, if you think that doesn't count,

\\

Try it Online!

\ is a single-character string.

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.

Lenguage, 4 bytes

����

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

brainfuck, 14 bytes

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

Try it online!

Forcefix average

Rexx (Regina), 5 bytes

SAY C

Try it online!

vim, 3 bytes

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

<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)

Grok, 4 bytes

I[Wq

Characters are 73 91 87 113. Average is 91, which is [.

Ruby, 4 bytes


p 3

Try it online!

Adding a leading newline to lower the average from capital-letter land to digit land.

Vim, 2 bytes

ii

Try it online!

Factor, 8 bytes

"Y"print

Try it online!

This actually works...................

MAWP v1.1, 6 bytes

33W/:.

I tried a different approach from Dion's answer.

Try it!, Verify

Keg, 1 byte

e

Try it online!

Haha. I'm not gonna be late to the party!

1+ (with NOP), 3 bytes

'1:

Try it online! Verify!

1+ (without NOP), 4 bytes

11+:

Try it online! Verify!

Rust, 5 bytes

||'R'

Try it online, Verify

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

bitch, 2 bytes

/1

Try it online! or verify the average.

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.

Pyth, 2 bytes

"!

ASCII value of " is 34, and ASCII value of ! is 33.

(33 + 34) / 2 = 33.5 = 33

Try it online!

PowerShell, 1 byte

0

Try it online!

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

PowerShell, 3 bytes

+$A

Try it online!

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

Scala, 10 bytes

print("N")

Online demo

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

C - 18 chars

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

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.

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...

COW, 11 8 bytes

BOOM!!


Try it online! or verify the average.

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

Try it online! or verify the average.

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

C (gcc), 15 bytes

A(){return 84;}

Average is T. Returns ASCII code.

Try it online!

Ada (GNAT), 53 bytes

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

Try it online!

Why not?

><>, 4 bytes

" o;

Try it online!

Outputs ; using a looping string literal.

cat, 1 byte

a

If your challenge can be competitively solved with cat, there is probably something wrong with the challenge.

Whitespace, 13 bytes

Outputs Data Link Escape (0x16)

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

PHP, 1 byte

A

Try it online!

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

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.

Python 3, 10 bytes

print("N")

Try it online!

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.

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.

Python 3, 11 bytes

print('K')#

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

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.

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.

Lost, 19 13 11 bytes

v<<<<
>%(9@

-6 bytes thanks to @JoKing.

The average is 57.090..., which will be rounded to 57 (character '9').

Try it online or verify that it's deterministic.

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:

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 try both versions on: http://sandbox.onlinephpfunctions.com/code/36449dad6c5de136ae489bcbeaddd97a6a7124bc

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

Rust, 23 bytes

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

Used modified Perl answer's script.

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.

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!

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).

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

05AB1E, 1 byte

0

Or any other single digit.

Try it online.

R, 8 bytes

cat("B")

Try it online! or Check average

or

cat('C')

Try it online! or Check average

Also,

cat(8)

(with 2 null bytes) doesn't work on TIO, but works in RStudio on my Kubuntu machine.

Try it online! or Check average.

T-SQL, 8 bytes

PRINT'D'

DB Fiddle

HQ9+ Family, 1 bytes

Q

Believe it or not, there are challenges can be solved by HQ9+ in 2020.

99, 22 bytes

99 99 9
99 99 9
9 99
9m

Try it online!

AlphaBeta, 10 bytes

edaaaaaCLz

Try it online!

JavaScript (Browser), 10 bytes

alert('M')

Try it online!

JavaScript (Node.js), 5 bytes

()=>3

Try it online!

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' }
}

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

Hexagony, 3 bytes

0!@

Try it online! or Check the average character

Explanation

0     Set current memory edge to 0
 !    Output current memory edge as a number
  @   Terminate the program

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.

brainfuck, 16 bytes

Outputs 6, the average of the program.

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

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.

Io, 8 bytes

I feel that this is too boring to find...

"Y"print

Try it online!

Gol><>, 3 bytes

`TH

Try it online! and Check the average character.

`T   Escape the char T and push its charcode to stack
  H  Print all values on the stack and halt

Found by making the template `<any char>H and repeating the average calculator until it converges.

Bash, 6 bytes

echo Y

Try it online!

echo Z

works as well.

Just like my Perl solution, this was found using a brute force search.

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.

Unreadable, 111 bytes

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

Try it online! or Check average

Note that the average character is $ and does not appear in the source code, which contains only 37 's and 74 "s.

SQLite, 9 bytes

SELECT"@"

Try it online!

AWK, 15 bytes

BEGIN{print"X"}

Try it online!

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!

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

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!

Python 2, 8 bytes

print"Y"

Try it online!

Average Character Verified