28
\$\begingroup\$

Inspired by this

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!

\$\endgroup\$
13
  • 4
    \$\begingroup\$ Average Character Calculator (only works for unicode characters input) \$\endgroup\$ Commented Jul 19, 2020 at 19:02
  • 7
    \$\begingroup\$ 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. \$\endgroup\$
    – Adám
    Commented Jul 19, 2020 at 19:07
  • 2
    \$\begingroup\$ @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. \$\endgroup\$
    – Dion
    Commented Jul 19, 2020 at 19:10
  • 2
    \$\begingroup\$ @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) \$\endgroup\$ Commented Jul 19, 2020 at 19:38
  • 3
    \$\begingroup\$ @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. \$\endgroup\$
    – tsh
    Commented Jul 20, 2020 at 6:25

76 Answers 76

1 2
3
1
\$\begingroup\$

Grok, 4 bytes

I[Wq

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

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Vyxal, 1 byte

7

Try it Online!

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

\$\endgroup\$
1
\$\begingroup\$

Zsh, 5 bytes

<<< 5

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

Io, 8 bytes

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

"Y"print

Try it online!

\$\endgroup\$
0
\$\begingroup\$

><>, 4 bytes

" o;

Try it online!

Outputs ; using a looping string literal.

\$\endgroup\$
0
\$\begingroup\$

Pyth, 2 bytes

"!

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

(33 + 34) / 2 = 33.5 = 33

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Keg, 1 byte

e

Try it online!

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

\$\endgroup\$
0
+150
\$\begingroup\$

Factor, 8 bytes

"Y"print

Try it online!

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

\$\endgroup\$
0
\$\begingroup\$

Ruby, 4 bytes


p 3

Try it online!

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

\$\endgroup\$
0
\$\begingroup\$

Rexx (Regina), 5 bytes

SAY C

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

Excel, 2 bytes

51

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

\$\endgroup\$
0
\$\begingroup\$

Julia, 9 bytes

print(:W)

Try it online!

also works with

:d|>print Try it online!

\$\endgroup\$
0
\$\begingroup\$

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:

  • 1 byte: 0 (or any other number)
  • 2 bytes: '' (a character literal)
\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.