15
\$\begingroup\$

It's well known that Brainf*ck is very bad at Kolmogorov-complexity problems, for example, it requires around 100 characters just to print "Hello world".

However, there might be texts where Brainf*ck is just very good at.

Your task is now to write a program that takes no input, and it displays the following:

That is, a smiley face (ASCII 1, if you browser does not render it).

Brainf*ck can do it in 2 characters.

+.

Try to find a language that beats it!

We assume your console can actually display that character (or your font has it, etc.).

Shortest code wins. If there are more of the same length, the first wins, but I'll upvote the others as well.

EDIT: I'm very sorry, I did not think the first post arrives this soon. A quick edit: the language has to be Turing-complete!

\$\endgroup\$
2
  • 10
    \$\begingroup\$ I must dispute your description of the output: While your code really outputs a character with the binary code 1, it is not ASCII-encoded, but belongs to some DOS codepage encoding like CP850 or CP437. In any modern console the smiley will not appear, because modern == UTF-8. ☺ \$\endgroup\$
    – Sven
    Nov 9, 2012 at 16:06
  • 4
    \$\begingroup\$ I've voted to close this as a duplicate of Hello World, because the string to output is so short, so the task is essentially "how short is it to output any string" \$\endgroup\$
    – pxeger
    Jun 11, 2022 at 5:59

26 Answers 26

10
\$\begingroup\$

FALSE (2)

1,

All that reading about BF paid off! False is an ancestor of Brainfuck.

\$\endgroup\$
3
  • \$\begingroup\$ Ouch! Strange that no one thought of this until now. :) \$\endgroup\$
    – vsz
    Nov 9, 2012 at 7:20
  • 1
    \$\begingroup\$ I had to accept this one, as the versions with plain-text and html were not actually done with programming languages. \$\endgroup\$
    – vsz
    Nov 17, 2012 at 18:12
  • \$\begingroup\$ I tried to do it with BLC, but I can't make any sense out of BLC. And even a 1-state Turing machine needs 4 or 5 elements in the tuple. \$\endgroup\$ Nov 17, 2012 at 18:49
8
\$\begingroup\$

C, 18 chars

Far from beating Brainf**k, but as good as C can get (I guess).
Only works on little-endian platforms, must run without parameters.

main(c){puts(&c);}
\$\endgroup\$
7
\$\begingroup\$

Micronetics System MUMPS 4.4 (7 chars)

w $c(1)
\$\endgroup\$
2
  • \$\begingroup\$ MUMPS? Oh, the horror... I never even imagined that I'll see it here. +1 just for the pure shock value! \$\endgroup\$
    – vsz
    Nov 9, 2012 at 12:56
  • \$\begingroup\$ @vsz it's the only Golf suitable language I know, it often beats most common langs :) \$\endgroup\$
    – DaveShaw
    Nov 9, 2012 at 12:59
5
\$\begingroup\$

Brainf*ck (only 2 characters)

+.
\$\endgroup\$
4
  • \$\begingroup\$ Of course, I'll still accept a solution of length 2. \$\endgroup\$
    – vsz
    Nov 8, 2012 at 18:55
  • \$\begingroup\$ Could you explain how this works? It should output ASCII 1 which is a non-printable character. \$\endgroup\$
    – Luna
    Oct 27, 2014 at 13:58
  • \$\begingroup\$ @nyuszika7h : many consoles output a smiley for ASCII 1. \$\endgroup\$
    – vsz
    Oct 27, 2014 at 19:19
  • 3
    \$\begingroup\$ Really? I've never seen such a console. I bet they use some obscure charset. \$\endgroup\$
    – Luna
    Oct 27, 2014 at 19:21
5
\$\begingroup\$

Doesn't beat 2 chars, but:

PHP 11 chars.

<?=chr(1)?>

For everyone saying you can simply place the smiley in php and it will output :

Running it with php.exe in the command line gives Γÿǁ and placing it in the browser gives ☺

It does not work.

\$\endgroup\$
5
  • \$\begingroup\$ You could also go the HTML route that m0nhawk did. \$\endgroup\$
    – Mr. Llama
    Nov 9, 2012 at 17:35
  • \$\begingroup\$ @GigaWatt You cannot. It puts out gibberish using PHP. Did you even try? I tried it in the CLI and the browser. \$\endgroup\$ Nov 9, 2012 at 17:48
  • \$\begingroup\$ Works fine for me. ideone.com/6wYzx9 \$\endgroup\$
    – Mr. Llama
    Nov 9, 2012 at 17:56
  • \$\begingroup\$ Running it with php.exe in the command line gives Γÿǁ and placing it in the browser gives ☺ \$\endgroup\$ Nov 9, 2012 at 18:56
  • 3
    \$\begingroup\$ If you do a hex dump of your file, you'll see that it was saved as unicode representation of a smiley (\xE298BA), not as \x01. Try manually making a file with a single \x01 byte in it and running it from the command line with PHP. \$\endgroup\$
    – Mr. Llama
    Nov 9, 2012 at 21:04
5
\$\begingroup\$

DC - 2 characters

1P

It doesn't require any explanation.

\$\endgroup\$
4
\$\begingroup\$

Golfscript, 3 characters

"☺"

Not a golfscript expert, but I don't believe there is a way to convert an integer into the corresponding ASCII character using only 1 character, so it seems like this is the shortest it can get

\$\endgroup\$
4
\$\begingroup\$

PHP (1)

Technically this is a valid PHP file (a web server will happily serve it).

\$\endgroup\$
3
\$\begingroup\$

LaTeX (51/77 characters)

Short solution

\documentclass{book}
\begin{document}
☺
\end{document}

Good solution (Compile with latex main.tex):

\documentclass{book}
\usepackage{wasysym}
\begin{document}
\smiley
\end{document}
\$\endgroup\$
1
  • \$\begingroup\$ The first one does not work because pure LaTeX cannot read unicode chars. Oddly enough, this does not work neither in XeLaTeX, nor in LuaLaTeX because the default font table does not contain this symbol. Please consider this: \documentclass{book} \usepackage{fontspec} \setmainfont{DejaVu Sans} \begin{document}☺\end{document} — and please specify the rendering engine you are using (pdfLaTeX) in the “good” solution. \$\endgroup\$ Nov 14, 2016 at 16:57
2
\$\begingroup\$

J (3 chars)

'☺'

The code require appropriate font.

According to Wikipedia

In the Wingdings font, the letter "J" is rendered as a smiley face (note this is distinct from the Unicode code point U+263A, which renders as ☺).

\$\endgroup\$
1
  • \$\begingroup\$ Another variation is u:1. \$\endgroup\$
    – FireFly
    Oct 8, 2013 at 21:30
2
\$\begingroup\$

Q/k (9 chars)

Can't do it in 2 unfortunately.

-1"\001";

I seem to recall a bug in an older version of the interpreter which produced the other smile symbol in less characters. I'll look it up.

Edit: found the quirk. It only appears to work on windows versions of the interpreter:

q)1(1b);
☺
\$\endgroup\$
2
\$\begingroup\$

Whitespace, 9 bytes

   	
	
  

Try it online!

ssstl   push 1 on stack
tlss    output char
\$\endgroup\$
1
\$\begingroup\$

Burlesque - 6 Characters

,1L[sh

Explanation:

, pops stdin. 1L[ pushes one and convert to char (by codepoint) sh is used to switch to pretty format. (Otherwise it would print a leading ').

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

Tcl, 1

Displays a ☺ with some other stuff.
There are rumors that this also works with PHP or other languages.

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

Arduino, 24

char a=1;Serial.print(a)
\$\endgroup\$
1
\$\begingroup\$

Keg, 2 characters

Push the number 1 and print it. (Surprised that 1, also works; -1 from Lyxal.)

1,

Try it online!

Keg, 1 character

Keg is actually Turing-complete, and any unrecognized command acts as a push onto the stack.

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ It's actually 1, making it 2 bytes. \$\endgroup\$
    – lyxal
    Feb 20, 2020 at 6:42
1
\$\begingroup\$

05AB1E, 2 characters

Just a boring hard-coding. It's encoded in CP437.

"☺

Try it online!

05AB1E, 2 bytes

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ You may want to include the encodings. Your top answer is only 2 bytes in an encoding like CP850 or CP437, which contains both the characters and " in their codepage. But using the 05AB1E encoding, the top answer isn't even possible, and using the UTF-8 encoding it would be 4 bytes. \$\endgroup\$ Feb 20, 2020 at 8:44
  • \$\begingroup\$ The challenge says that characters are a valid encoding system... \$\endgroup\$
    – user92069
    Feb 20, 2020 at 8:50
1
\$\begingroup\$

Stax, 2 bytes

1]

Run and debug it

\$\endgroup\$
1
  • \$\begingroup\$ The Stax ] doesn't work prefixly - it pops an item from the stack and creates a list from it. So you might alternatively need 1] for the program. \$\endgroup\$
    – user92069
    Feb 20, 2020 at 1:30
1
\$\begingroup\$

chevron - 4 bytes/2 runes

>☺
\$\endgroup\$
0
\$\begingroup\$

Perl 6 (7 chars)

say '☺'

I'm bending the rules a little by assuming that a \n is welcome to avoid shell prompt mess.

\$\endgroup\$
1
  • 5
    \$\begingroup\$ Are you sure you need that space character? \$\endgroup\$
    – J B
    Aug 28, 2013 at 21:46
0
\$\begingroup\$

JavaScript, 10 Bytes

alert("☺")

enter image description here

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

SmileBASIC, 3 characters

?"☺

​​

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

PowerShell, 5 bytes

if a program should output the smile face char.

'☺'

Try it online!


PowerShell, 7 bytes

if a program should output the char with code 1.

[char]1

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Why not just '☺' ? By the way, the face isn't rendered for me in TIO or the console \$\endgroup\$ Feb 17, 2020 at 15:32
  • \$\begingroup\$ because the code for the smile face is not 1 in the Powershell. Try it online! \$\endgroup\$
    – mazzy
    Feb 17, 2020 at 15:39
  • 1
    \$\begingroup\$ Should your answer be '[Char]9786' instead then? I'm really confused :-D \$\endgroup\$ Feb 17, 2020 at 15:44
  • 1
    \$\begingroup\$ Ha! You are right. I thought I'd write a program that outputs a character with code 1. But you can interpret it as writing a program that outputs a smiley face. \$\endgroup\$
    – mazzy
    Feb 17, 2020 at 15:48
0
\$\begingroup\$

Gol><>, 2 bytes

1H

Try it online!

Just for completeness. Push a single 1, print all the contents as characters and halt.

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

MineFriff, 5 bytes

C1,o;

Try it online!

Simply:

  • Treat the temp register as a character
  • Add one to the register and push
  • Output the top item and finish.
\$\endgroup\$
0
\$\begingroup\$

C (gcc), 15 bytes

f(){puts("☺");}

Try it online!

\$\endgroup\$

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