Write a program that produces an output such that:

  1. At least three distinct characters appear.
  2. The number of occurrences of each character is a multiple of 3.

For example, A TEA AT TEE is a valid output since each of the 4 distinct characters, A, E and T and (space), occurs 3 times.

Of course, a challenge about the number 3 needs to have a third requirement. So:

  1. The program itself must also follow the first two requirements. (This means your program will be at least 9 bytes long.)

You must write a full program, not a function. Be sure to show your program's output in your answer.

Also, to keep things interesting, you are highly encouraged:

  • not to use comments to meet requirement 3 if you can help it
  • to produce output that isn't just a string repeated 3 times
  • to make the output different from the program itself (for languages that can automatically output the contents of its own program, you can contribute to this community wiki).

This is . Shortest code in bytes wins.

share|improve this question
3  
Do newlines count (as a distinct character) ? – zeppelin 12 hours ago
3  
Are programs that consist entirely of literals allowed? (There are a lot of languages where 123123123 will work, as currently written.) – ais523 12 hours ago
    
@ais523 Thanks for pointing that out. Since a few such answers have already been posted, I've updated the question to simply discourage them. – darrylyeo 11 hours ago
2  
What I mean to ask is, can a program output e.g. abcabcabc with a trailing newline? – ETHproductions 11 hours ago
1  
@ETHproductions Ah, I see. No, that is not allowed. Three trailing newlines would be acceptable, however. – darrylyeo 11 hours ago

32 Answers 32

Brain-Flak (Flakcats, Brain-Flueue and Miniflak), 18 bytes

Proven optimal!

((([[[()()()]]])))

Try it online!

This prints

-3
-3
-3

(There is a trailing newline)

Explanation

Brain-Flak, Brain-Flueue and Miniflak

   ([[[()()()]]]) Push -3
  (              ) Copy
 (                ) Copy

Flakcats

Flakcats is quite different from the other 3 flaks and I am surprised that this works in Flakcats. The three operators here are nearly the same as the ones that Brain-Flak uses.

The main difference in this particular program between Flakcats is the (...) operator which in Flakcats is equivalent to ([{}]...) in Brain-Flak. This however does not make a difference to us because it picks up zeros and thus operates much in the same way that Brain-Flak does.

Here is that program compiled into Brian-Flak:

([{}]([{}]([{}][[[()()()]]])))

Proof of optimality

This is not a formal proof, but rather an informal proof that would have to be expanded to be made more rigorous

Because of the restrictions that Brain-Flak programs must be a balanced-string and the program length must be a multiple of 3 any valid submission must be a multiple of 6 in length. This means any solution smaller than 18 must be length 12.

Because of the outputs trailing newline the final height of the stack must be a multiple of three or we will break the restrictions on output.

Any valid submission of length 12 must have 2 types of braces (having less would break the restrictions on number of distinct characters and more would mean more than 12 characters). Since the program produces output it must have a push.

This leaves us to select our other set of braces. The options are:

<...>/<>

This fails because we need to generate "value" in order to create any number other than zero we must give up a () to create a one which makes it impossible to push more than two times.


[...]/[]

This fails for the same reason the last failed. The square braces are really bad at making value. The [] monad can create value but we need to push numbers first and we then don't have enough parens left over to push three times.


{...}/{}

This one is promising, we could create a loop and use one () to push multiple times, but alas it is not possible.

In order for the loop to end there must be a zero on the stack at some point and in order for us to have the correct output we must have something other than zero on the stack at the end of the program. Since we have neither [] nor <> the zero at the end of the loop must be a implicit zero from the bottom of the stack. This means the loop cannot add any new numbers to the stack making it useless.


Since none of the brace choices can create a program of length 12 none can exist.

Alternative 24 byte solutions

(<((<((<(())>)())>)())>)

Try it online!

((<((<((<>)())>)())>)())

Try it online!

((((((()()()){}){}){})))

Try it online!

share|improve this answer
4  
+1 for proof(s) of optimality! – 1000000000 10 hours ago

C#, 114 111 118 bytes

If we don't care about case:

class EreBeWyvern{static void Main(){int embedwildbanana; {System.Console.Write(("A TEA AT TEE"));;}}}/// V".

If we do:

class erebeWyvern{static void Main(){int embedWildbanana; {System.Console.Write(("A TEA AT TEE"));;}}}/// VMMmSSsCCc".

I know the comment isn't really in the spirit of the CG, but it's all I could come up with in a limited amount of time, I'll see if I can improve it through the day. Surely I must get at least some bonus points for the nod to being adventurous.

share|improve this answer
1  
I'm a C++ guy, not C#, but can you not just wrap the Write call in {()} without affecting it? – Sparr 11 hours ago
    
Thanks for the suggestion! The curly braces work, the parentheses don't – Dmihawk 11 hours ago
1  
You might be able to put the parentheses around the argument, rather than the call as a whole. – ais523 11 hours ago
1  
Brownie points for the wild banana. – darrylyeo 10 hours ago
2  
Nice! I like the variable names. +1 – Mistah Figgins 5 hours ago

Polyglot of purely literal answers, 9 bytes

333111222

This is a community wiki post for collecting answers that are just a literal that the language in question prints out automatically. Because it's a community wiki, feel free to edit it to add more languages where it works.

This program works in:

  • PHP
  • HTML (arguably not a language)
  • Jelly (and M)
  • 7 (more interesting, because the program's interpreted as both data and code; the first 3 prints the data, the rest of the program is useless stack manpulation)
  • CJam
  • Japt
  • Carrot
  • RProgN
  • Actually (though it actually prints 2\n2\n2\n1\n1\n1\n3\n3\n3\n)

Ignoring the final newline, this is valid in quite a few more languages:

Most links go to Try It Online!

share|improve this answer
2  
This prints 2\n2\n2\n1\n1\n1\n3\n3\n3\n in Actually, which is perfectly valid. Should that be added to the post? – ETHproductions 11 hours ago
    
@ETHproductions I actually think Actually should be added to the post since it uses the same code ;) – Kritixi Lithos 11 hours ago
    
@ETHproductions: I'm unsure. It's more interesting than the other languages, but it's still just literals. I wouldn't be upset either way. – ais523 11 hours ago
    
As the person who made Actually, I agree that it belongs in this post. The newlines don't really make a difference. – Mego 4 hours ago

CJam, 9 bytes

10,10,10,

Outputs 012345678901234567890123456789

Try it online!

Explanation

10,       The range from 0 to 9
   10,    The range from 0 to 9
      10, The range from 0 to 9
share|improve this answer

Microscript II, 9 bytes

{{{~~~}}}

Explanation: Creates a code block, but doesn't invoke it. When execution ends, the contents of the main register (IE this code block) are implicitly printed.

share|improve this answer
    
Have you posted something similar in the Quine challenge? – wizzwizz4 12 hours ago
    
@wizzwizz4 {} would technically be a quine, but I don't think it meets our definition of a "proper quine". The program "q"q (which I did submit to the quine challenge) does, however. – SuperJedi224 12 hours ago
    
@wizzwizz4: That wouldn't be a proper quine, because each character represents itself. – ais523 12 hours ago

JavaScript, 36 33 bytes

alert(((alert|alert||333111222)))

Alerts 333111222. This works because | converts both of its operands to 32-bit integers, and any value that doesn't look anything like an integer (e.g. the function alert) gets converted to 0. 0|0 is 0, so the || operator returns its right operand, or 333111222

A few more interesting versions:

(a="(trelalert)\\\"")+alert(a+=a+=a)

Outputs (trelalert)\"(trelalert)\"(trelalert)\".

A solution using .repeat would be the same length, thanks to the shared aert:

alert("(trpp.all)\\\"".repeat(3.33))

which outputs (trpp.all)\"(trpp.all)\"(trpp.all)\".

Taking advantage of the extra backslashes to get rid of l and p almost works:

a\x6cert("(trax.cc)\"".re\x70eat(6.00677))

This one outputs (trax.cc)"(trax.cc)"(trax.cc)"(trax.cc)"(trax.cc)"(trax.cc)".

share|improve this answer
    
Nice abuse of decimals! – darrylyeo 11 hours ago
2  
@darrylyeo Heh, thanks. I could've easily stuck those in the string, but that wouldn't be as fun ;-) – ETHproductions 11 hours ago
    
I was just about to suggest rt=alert(lerta=ale=((111222333))), which is 33 bytes long as well. – Arnauld 10 hours ago

Perl 6, 15 bytes

.say;.say;.say;

Prints six distinct characters, three times each:

(Any)
(Any)
(Any)

Try it online!

How it works

  • A bare method call operates on the current topic, $_.
  • $_ starts out as the type object of type Any, which say prints as (Any).
share|improve this answer

Ruby, 12 bytes

p$@;p$@;p$@;

outputs

nil
nil
nil

Try it online!

share|improve this answer

Python 2, 36 30 bytes

Since a trailing newline isn't allowed, this is probably as short as it can get:

print"\\\""*3;print;print;3**3

Try it online

Outputs \" three times, followed by three newlines.


The below programs don't count the trailing newline, so they're not valid.

27 bytes:

print"""printprint"""*3*3*3

Prints 54 of each character in print.

Try it online


Same length, shorter output:

print"""printprint*3*3"""*3

Outputs printprint*3*3printprint*3*3printprint*3*3


24 bytes:

print~9;print~9;print~9;
share|improve this answer
    
You could do print"""printprint*3*3"""*3 for a much shorter output ;-) – ETHproductions 11 hours ago
    
Could you not do print 123;print 123;print 123; for the naive solution? – ETHproductions 11 hours ago
    
OP has clarified that the single trailing newline is not allowed (see comments). – FlipTack 11 hours ago
1  
@ETHproductions Sure. It depends how naive we're being. – mbomb007 11 hours ago
    
@FlipTack Fixed it, and I feel like I just hit an optimal solution for when the trailing newline isn't forgiven. – mbomb007 10 hours ago

dc, 9 bytes

_A_A_Annn

Try it online!

Output is

-10-10-10

(no newlines in either the program or the output)

share|improve this answer
2  
♫ Barbara _A_A_Annn – mbomb007 10 hours ago
    
@mbomb007 LOL!! – Mitchell Spector 10 hours ago

V, 9 bytes

12i12i12i

Try it online!

Outputs 12i 24 times:

12i12i12i12i12i12i12i12i12i12i12i12i12i12i12i12i12i12i12i12i12i12i12i12i

Vim, 12 bytes

12i12i12i<ESC><ESC><ESC>

Outputs the same as the V answer

share|improve this answer

PKod, 9 bytes

sonsonson

Outputs: 111222333


Explanation:

Background: PKod has only one variable that you mess with, with the code
This variable starts with default value of 0

s  -  Add next char to the variable, and jump over it. 
n  -  Print numeric value of variable

o has ascii char code "111" in decimal. Thus s adds 111 to the variable, then prints the number. First "son" makes it 111 and prints 111. Next makes it 222 and prints 222, lastly makes it 333 and prints 333

share|improve this answer

Batch, 36 21 bytes

@echo
@echo
@echo

Outputs

ECHO is on.
ECHO is on.
ECHO is on.

Edit: Saved 15 bytes thanks to @P.Ktinos.

share|improve this answer
1  
Wouldn't 3 alone echo's work? echo\necho\necho - replace \n with a new line - it looks valid to me image.prntscr.com/image/ef96173169eb41168815203387d4975b.png , makes it 14 bytes. – P. Ktinos 10 hours ago
    

Befunge 93, 9 bytes

...,,,@@@

TIO

Prints 0 0 0 (Trailing space, followed by 3 null bytes)

Because Befunge's stack is padded with 0s, we can print both the ASCII character with that value, and the integer itself. Because Befunge automatically prints a space after an integer, we are left with 3 distinct characters.

. prints 0 (trailing space), , prints a null byte, and @ ends the program

share|improve this answer

PHP, 33 bytes

<?=($s="<?;<?=;'".'"').($s).($s);

Opted for something more interesting than the 9-byte program with no PHP tag.

Outputs <?;<?=;'"<?;<?=;'"<?;<?=;'"

Try it online!

share|improve this answer

Forth, 21 bytes

 1 1 1 . cr . cr . cr

Program contains 3 of each of 1.cr, and 9 spaces. Output contains 3 ones, 3 spaces, and 3 newlines.

Try it online

Output:

Each 1 has a space after it.

1 
1 
1 

share|improve this answer

SMBF, 18 15 bytes

<+...+...+...<<

Try it online

Output:

===>>>???
share|improve this answer
    
I think you can move two < to the end to drop the w. – Martin Ender 11 hours ago

Ouroboros, 12 bytes

n11n222n1(((

Outputs 011222 three times. Try it here.

How?

In Ouroboros, each line of code represents a snake swallowing its tail. Execution proceeds from the head (start) of the line to the tail (end), and then loops back to the head. The ( instruction swallows characters from the tail. If the instruction pointer is swallowed, execution halts.

The n command outputs a number. Popping the empty stack gives zero, so the first n prints 0. The next prints 11, and the third prints 222.

Now we come to 1(: push 1 and swallow that many characters. The final paren is swallowed. The next-to-last paren does nothing1, and execution loops back to the beginning.

The second time through, the next-to-last paren is swallowed and we loop again. The third time, the third-to-last paren is swallowed. This swallows the IP, and the program ends.

1 The stack is empty, so it swallows 0 characters.

share|improve this answer

Chip, 28 bytes

**ZZZZZZZZZT
*gggaaabbbTT


Output:

@@@AAACCC

(score includes 3 total newlines, and 1 byte for -w on the command line)

Chip is a new language I've been designing, and this is it's first real test drive! It's a 2D bit-based language that functions somewhat like an integrated circuit you might put together with a breadboard.

This solution outputs three @'s (binary 01000000), three A's (01000001), then three C's (01000011) by turning the bits successively on.

Breakdown

Ungolfed (or, really, without the excess parts):

*ZZZZZZZZZ
g  a  b  T

* is a source element which produces a high signal; that is sent to
g , which represents the bit 0x40 of the output stream, and
Z , which propagates signal after one clock tick. After 3 ticks (for three Z elements),
a receives a high signal, and now the 0x1 bit is also on. Three ticks later,
b turns on the 0x2 bit, and three ticks again activates
T , which terminates execution.

All other added elements are active (e.g. not a comment), but they don't do anything, similar to assigning a variable to itself.

share|improve this answer
    
Where are the 3 newlines? If you put your code in <pre><code>...</code></pre> in markdown, we'll be able to see them. – mbomb007 10 hours ago
    
@mbomb007 End of each line and one more at the end. Did that change anything? I don't see a difference... – Phlarx 10 hours ago
    
Oh, wow.... there's gray boxes. Apparently the contrast or gamma or something is really screwed up on one of my monitors. – Phlarx 10 hours ago
    
I had that problem with a monitor a few months back. It fixed itself after a few days. Idk what caused it, but changing settings wouldn't fix it. Also, that final newline is required in the markdown, because the block shows one less due to some SE formatting issue. – mbomb007 10 hours ago

Retina, 18 12 bytes

Byte count assumes ISO 8859-1 encoding.


aaa¶¶ccc

¶

prints


a
a
a




c
c
c


That's 12 linefeeds.

Try it online!

share|improve this answer

SmileBASIC, 9 bytes

?12?21?21

Output:

12
21
21

Not the most exciting thing, but it fulfills all 3 recommendations.

share|improve this answer

Batch ~ 9 bytes

bc
bc
bc

Two random chars, followed by a new line, makes 3 chars that are shown 3 times.
Hex dump: 62 63 0A 62 63 0A 62 63 0A

Output:

C:\Users\4story\Desktop>bc
'bc' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\4story\Desktop>bc
'bc' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\4story\Desktop>bc
'bc' is not recognized as an internal or external command,
operable program or batch file.

My environment username happens to be "4story". However, it doesnt matter what directory you are in, or what your username is - output will always fulfill the rules.

share|improve this answer
    
Output typically has to be to stdout, not stderr. You should ask the OP if that's okay. – mbomb007 8 hours ago

MATL, 12 9 bytes

3 Bytes saved thanks to @Luis

JVvJVvJVv

Outputs:

0 +1i
0 +1i
0 +1i

Try it Online!

Explanation

J is the shortcut for the complex number 0 + 1i. We convert this to a string with V and repeat this motif 3 times and concatenate the entire stack vertically three times using v.

share|improve this answer
    
@LuisMendo Unfortunately since MATL trims trialing newlines it only has 2 :( – Suever 10 hours ago
    
@LuisMendo Ah you're right! There's also the newline in the TIO version. Thanks – Suever 10 hours ago

GNU Sed, 12 bytes

Golfed

abc
abc
abc
 

(note the trailing newline)

Test

%echo|sed -n 'abc
abc
abc
'

bc                                                                                                                                                      
bc                                                                                                                                                      
bc

%echo|sed -n 'abc
abc
abc
'|tr \\n N|fold -1|sort|uniq -c

3 N                                                                                                                                               
3 b                                                                                                                                               
3 c

Try It Online !

share|improve this answer
2  
The newline only appears twice, I think you can add an extra newline at the end to meet this requirement – Kritixi Lithos 11 hours ago
2  
^ What he said. Your source code's length must be divisible by 3. – mbomb007 11 hours ago
    
@KritixiLithos, mbomb007 - Thank you ! Should be fixed now ! – zeppelin 11 hours ago

stacked, 24 bytes

''''   'putput'3*3*3*put

Try it online! Outputs 54 each of p u and t.

share|improve this answer

Pip, 9 bytes

PzPzPzuuu

Outputs the lowercase alphabet three times, each time followed by a newline. Try it online!

Explanation

The naive attempt

P12P12P12

actually prints 12 four times. That's because Pip autoprints the result of the last expression in the program. P12 prints 12, but it is also an expression that evaluates to 12. So an extra 12 is printed.

We can avoid this by making the last expression in the program evaluate to nil. When nil is printed, it produces no output--not even a newline. The variable u is preinitialized to nil. Repeating it three times is fine, just adds a couple no-ops.

share|improve this answer

Retina, 27 bytes


aaabbb
S\`
S\`
S\`
\`\`\`

Try it online

The output is 150 bytes, containing 12 a, 12 b, and 126 newlines.

share|improve this answer

Del|m|t, 15 bytes

TIO

8 9 8 9 8 9 555

Prints 0 0 0 (with a trailing space) (there are null bytes after every space, including the trailing one

Because the stack is padded with 0s, we can just print the ASCII value and character, because printing the value also prints a space. 555 ends the program.

share|improve this answer

V, 9 bytes

¬ac¬ac¬ac

Try it online!

This outputs:

ababcabcc

This is pretty straightforward. Each ¬ is the "range operator", that takes two character arguments and inserts each character in that range. So ¬ac inserts abc. Repeating this three times causes some weird issues with the layout of the output (which is why they're not in order) but thankfully this doesn't matter for this particular answer.

share|improve this answer

Del|m|t, 21 bytes

TIO

; ; ; 8 8 8 8 8 8 555

prints 32 -1 32 -1 32 -1 (with a trailing space)

No command line argument = as delimiter

; pushes -1 followed by the delimiter, and 8 prints the top of the stack. 555 ends the program

Here's another interesting solution with 24 bytes total:

TIO

; 0 / / 8 8 8 >>>;;00/  

(2 trailing spaces to make it a multiple of 3)

This one just uses the -1, but is longer due to the lack of repetition, so the "end" command had to be pretty long

prints -1 -1 -1 (also a trailing space)

The ; pushes the delimiter (as above), the 0 drops the top, so the stack only has a -1 on it. / / duplicates it twice, and 3 8s print. >>>;;00/ ends the program

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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