Task
Your task is to output the average character of your code.
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!
77 Answers 77
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
Mandatory answer in ArnoldC. New line characters have been added to the average as a single character of value 10.
-
\$\begingroup\$ 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). \$\endgroup\$Dingus– Dingus2020年07月22日 11:42:39 +00:00Commented Jul 22, 2020 at 11:42 -
\$\begingroup\$ @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 \$\endgroup\$Charlie– Charlie2020年07月22日 11:59:05 +00:00Commented Jul 22, 2020 at 11:59
-
1
-
\$\begingroup\$ This is a V submission. a Vim submission would require an
escat the end. \$\endgroup\$Razetime– Razetime2021年04月15日 14:28:22 +00:00Commented Apr 15, 2021 at 14:28 -
\$\begingroup\$ @Razetime Why would an
escbe required? Even though Vim is still in Insert mode, the intended text has still been outputted.escwould 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. \$\endgroup\$Aaroneous Miller– Aaroneous Miller2021年04月15日 14:46:23 +00:00Commented Apr 15, 2021 at 14:46 -
\$\begingroup\$ I'm not sure, but it's the same reason why
2i2iis a V quine rather than a vim quine \$\endgroup\$Razetime– Razetime2021年04月15日 15:43:27 +00:00Commented Apr 15, 2021 at 15:43 -
\$\begingroup\$ I think a consensus on this would be good. \$\endgroup\$Aaroneous Miller– Aaroneous Miller2021年04月15日 16:46:55 +00:00Commented Apr 15, 2021 at 16:46
-
\$\begingroup\$ 2i2I does not double the input until <esc> is pressed, that's why it's required there. This answer should be fine \$\endgroup\$Leo– Leo2021年04月15日 22:03:44 +00:00Commented Apr 15, 2021 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
+[+++++>+<]>.
Forcefix average
-
\$\begingroup\$ 13 bytes BF with proof of average \$\endgroup\$Bubbler– Bubbler2021年04月14日 04:00:50 +00:00Commented Apr 14, 2021 at 4:00
-
\$\begingroup\$ @Bubbler en.wikipedia.org/wiki/ASCII says ASCII is 0-127 \$\endgroup\$l4m2– l4m22021年04月14日 18:12:14 +00:00Commented Apr 14, 2021 at 18:12
-
\$\begingroup\$ 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 �. \$\endgroup\$Makonede– Makonede2021年04月14日 22:39:54 +00:00Commented Apr 14, 2021 at 22:39
-
\$\begingroup\$ @Makonede Do
�in every browser show�? \$\endgroup\$l4m2– l4m22021年04月15日 01:50:58 +00:00Commented Apr 15, 2021 at 1:50 -
\$\begingroup\$ 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. \$\endgroup\$Makonede– Makonede2021年04月15日 02:06:10 +00:00Commented Apr 15, 2021 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 ']'...
]
]
][[=
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"
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__
Bash, 6 bytes
echo Y
echo Z
Just like my Perl solution, this was found using a brute force search.
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.
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' }
}
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.
Python 3, 11 bytes
print('K')#
The average value is 75.09, which rounds to 75 - K.
-
\$\begingroup\$ codegolf.stackexchange.com/a/207329/92080 10 bytes \$\endgroup\$Dion– Dion2020年07月21日 05:06:04 +00:00Commented Jul 21, 2020 at 5:06
PHP, 1 byte
A
This will just output itself. Works with almost all of the printable ASCII characters.
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
-
1\$\begingroup\$ 13 bytes \$\endgroup\$ceilingcat– ceilingcat2020年07月22日 03:38:52 +00:00Commented Jul 22, 2020 at 3:38
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.
Rust, 5 bytes
||'R'
Straightforward solution, just a closure that implements Fn() -> char.
1+ (with NOP), 3 bytes
'1:
1+ (without NOP), 4 bytes
11+:
-
\$\begingroup\$ I think something is wrong with the "Try it!" link... \$\endgroup\$the default.– the default.2020年08月08日 12:08:20 +00:00Commented Aug 8, 2020 at 12:08
-
\$\begingroup\$ @Dion decided to port the website over to 8dion8.github.io/MAWP, so all try it links are broken. Here's a proper link: 8dion8.github.io/MAWP/?code=33W%2F%3A.&input= \$\endgroup\$Razetime– Razetime2020年08月08日 12:10:15 +00:00Commented Aug 8, 2020 at 12:10
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 = zisy * z = x, one may argue output any single character should be allowed. \$\endgroup\$