| Bytes | Lang | Time | Link |
|---|---|---|---|
| 023 | Bespoke | 250804T095754Z | Josiah W |
| 016 | Thunno 2 | 230610T164145Z | The Thon |
| 009 | Julia | 220224T140847Z | MarcMush |
| 191 | Plumber | 210615T172823Z | Aaroneou |
| 005 | Zsh | 210530T173243Z | pxeger |
| 001 | Vyxal | 210530T172217Z | wasif |
| 001 | /// | 200719T190235Z | caird co |
| 002 | Excel | 210530T135500Z | Axuary |
| 004 | MATLAB/Octave | 210530T133430Z | elementi |
| 001 | Vyxal | 210529T221933Z | emanresu |
| 002 | Sandwich | 210415T142103Z | karx |
| 004 | Lenguage | 210413T180518Z | l4m2 |
| 005 | Rexx Regina | 210414T095327Z | cnamejj |
| 003 | vim | 210413T234420Z | Ray |
| 004 | Grok | 210413T192005Z | Aaroneou |
| 004 | Ruby | 210413T181754Z | histocra |
| 002 | Vim | 210413T175637Z | Aaroneou |
| 008 | Factor | 210326T161521Z | wasif |
| 006 | MAWP v1.1 | 200806T075958Z | Razetime |
| 001 | Keg | 200808T120208Z | lyxal |
| 003 | 1+ with NOP | 200808T105521Z | Twilight |
| 005 | Rust | 200731T224048Z | TehPers |
| 002 | bitch | 200728T140026Z | Dingus |
| 002 | Pyth | 200726T171807Z | Viraxor |
| 001 | PowerShell | 200726T141504Z | stackpro |
| 003 | PowerShell | 200725T124049Z | mazzy |
| 010 | Scala | 200722T222106Z | user |
| 006 | Ruby | 200721T050013Z | AShelly |
| 018 | C | 200722T202309Z | AShelly |
| 059 | ArnoldC | 200722T100700Z | Charlie |
| 007 | MATLAB... and MSDOS and Bash? | 200722T045012Z | mimocha |
| 008 | COW | 200721T082308Z | Dingus |
| 015 | C gcc | 200722T012456Z | S.S. Ann |
| 053 | Ada GNAT | 200721T230640Z | LambdaBe |
| 004 | ><> | 200721T215909Z | SE - sto |
| 001 | cat | 200721T190455Z | Stack Ex |
| 013 | Whitespace | 200721T173446Z | Ethan Ch |
| 001 | PHP | 200721T150617Z | The rand |
| 004 | Java JDK | 200720T172011Z | Olivier |
| 010 | Python 3 | 200720T190600Z | Dion |
| 007 | Batch | 200720T161024Z | Neil |
| 004 | Z80Golf | 200720T155452Z | lynn |
| 011 | Python 3 | 200720T142217Z | MLavrent |
| 006 | Backhand | 200720T005841Z | user9206 |
| 002 | SuperMarioLang | 200720T132027Z | Charlie |
| 011 | Lost | 200720T093206Z | Kevin Cr |
| 010 | SimpleTemplate | 200720T105320Z | Ismael M |
| 023 | Rust | 200720T113016Z | Vi. |
| 017 | Malbolge | 200720T112713Z | Charlie |
| 067 | Perl 5 + M5.10.0 | 200720T112332Z | Dom Hast |
| 001 | Retina 0.8.2 | 200719T214131Z | Neil |
| 029 | Pyramid Scheme | 200720T090917Z | Jo King |
| 001 | 05AB1E | 200720T091406Z | Kevin Cr |
| 008 | R | 200719T224517Z | Robin Ry |
| 008 | TSQL | 200720T070413Z | Razvan S |
| 001 | HQ9+ Family | 200720T061705Z | tsh |
| 022 | 99 | 200720T060247Z | PkmnQ |
| 010 | AlphaBeta | 200720T052636Z | PkmnQ |
| 010 | JavaScript Browser | 200719T215258Z | Matthew |
| 005 | JavaScript Node.js | 200720T031601Z | Mukundan |
| 016 | JavaScript Node.js | 200720T030837Z | GirkovAr |
| 008 | naz | 200720T023829Z | sporebal |
| 003 | Hexagony | 200720T021159Z | Mukundan |
| 001 | 7 | 200720T014321Z | Pizgenal |
| 016 | brainfuck | 200720T001553Z | user9206 |
| 015 | brainfuck | 200720T001654Z | Level Ri |
| 008 | Io | 200720T001232Z | user9206 |
| 003 | Gol><> | 200720T001011Z | Bubbler |
| 006 | Bash | 200719T223929Z | Abigail |
| 003 | Befunge93 | 200719T223411Z | Abigail |
| 111 | Unreadable | 200719T225022Z | Robin Ry |
| 009 | SQLite | 200719T224721Z | Abigail |
| 015 | AWK | 200719T224456Z | Abigail |
| 006 | perl Mfeature=say | 200719T222802Z | Abigail |
| 003 | MAWP 0.1 | 200719T191906Z | Dion |
| 001 | APL Dyalog Unicode and lots of other languages and REPLs | 200719T190642Z | Adá |
| 008 | Python 2 | 200719T190152Z | fireflam |
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Ċ
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:
- 1 byte:
0(or any other number) - 2 bytes:
''(a character literal)
Plumber, 191 bytes
[]
]
]
...88 more ']'...
]
]
][[=
Drops a packet down, which is incremented up to 92 and printed. 92 is the ASCII value for \.
///, 1 byte
A
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
Any digit works.
Or, if you think that doesn't count,
\\
\ 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
+[+++++>+<]>.
Forcefix average
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)
Ruby, 4 bytes
p 3
Adding a leading newline to lower the average from capital-letter land to digit land.
1+ (with NOP), 3 bytes
'1:
1+ (without NOP), 4 bytes
11+:
Rust, 5 bytes
||'R'
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.
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
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
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]
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
This will just output itself. Works with almost all of the printable ASCII characters.
Java (JDK), 4 bytes
A->9
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
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.
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
This is ld a, 0x91 → rst 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"
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
:%
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:
>: 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 a9@: 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 the9for the average character of unicode57.
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.
Malbolge, 17 bytes
(=<;:9876543210TA
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
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\
^-----
-
This has an average of ~48.137, so this outputs 0.
If we're allowed a trailing newline, then we can get 4 bytes
^,
-
Again, this outputs 0, but by printing the return of the pyramid, which has an extra newline
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.
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
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
This outputs 3 as a number.
brainfuck, 15 bytes
+[+++++>+<]>++.
Requires an 8 bit interpreter as it uses modulo 256 arithmetic.
Average is 53.4. Outputs 5 which is character 53.
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
echo Z
Just like my Perl solution, this was found using a brute force search.
Befunge-93, 5 3 bytes
.@!
.@ 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.
perl -Mfeature=say, 6 bytes
say"P"
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__
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
However, more interesting is:
''''
Which actually evaluates to the single quote. Try it online!