74
\$\begingroup\$

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, 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.

\$\endgroup\$
14
  • 5
    \$\begingroup\$ Do newlines count (as a distinct character) ? \$\endgroup\$
    – zeppelin
    Commented Jan 25, 2017 at 19:05
  • 4
    \$\begingroup\$ Are programs that consist entirely of literals allowed? (There are a lot of languages where 123123123 will work, as currently written.) \$\endgroup\$
    – user62131
    Commented Jan 25, 2017 at 19:09
  • 2
    \$\begingroup\$ @zeppelin Yes, newlines count as a distinct character. \$\endgroup\$
    – darrylyeo
    Commented Jan 25, 2017 at 19:58
  • 2
    \$\begingroup\$ What I mean to ask is, can a program output e.g. abcabcabc with a trailing newline? \$\endgroup\$ Commented Jan 25, 2017 at 20:18
  • 2
    \$\begingroup\$ The challenge title doesn't meet the criteria, lol \$\endgroup\$
    – mbomb007
    Commented Mar 19, 2018 at 14:11

94 Answers 94

4
\$\begingroup\$

R, 9 bytes

c ;c ;c ;

Try it online!

Outputs

function (...) .Primitive("c") function (...) .Primitive("c") function (...) .Primitive("c")

This is a boring solution, still working on a more creative one.

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

Pepe, 24 bytes

rEeEEeeEEErreEErreEEreEE

Try it online!

Program contains 6 r's, 6 e's, and 12 E's.

Explanation:

rEeEEeeEEErreEErreEEreEE # full program

rEeEEeeEEE               # push '103' to the stack
          rreEErreEE     # output as int (r flag: preserve)
                    reEE # output as int

Output:

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

Brachylog, 9 bytes

000gggwww

Try it online!

Prints [[[0]]]00. Exploits (unnecessarily, it turns out) the fact that, in the absence of constraints on a variable, its value is taken to be zero, and the w predicate which prints the value of its input variable without a newline places no constraints on its output variable. (In fact, if this was allowed to have only two unique characters, gggwww would produce the same output, and gwgwgw or wgwggw would also work.)

      w      Print
000          zero
   g         enclosed in a list
    g        enclosed in a list
     g       enclosed in a list,
       w     and print something with no supplied value,
        w    and print something with no supplied value.

Various permutations of this program work, and are more visually novel than the one presented here, but it's the first version I came up with and to my mind very much to the point. Some permutations include 0gw0gw0gw which violates the second encouragement, w0gw00ggw which has a nice escalating effect, ggwgww000 which shows that the zeros being there really doesn't matter (it may as well be ggwgww777), and nothing containing the substring g0 since no matter what is on the left of the g 0 cannot possibly be a list containing it as its only element so the program will either fail or infinitely spew garbage as it tries to backtrack around the problem depending on whether or not there was a w earlier.

Less trivial variations on the same theme include 3ggw3gw3w, XgggwXwwX, w≡g≡wg≡gw, and w?gw?ggw? (which is actually compliant even with input!) I expected not to find a 9-byte solution and was pleasantly surprised to find a whole family of them.

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

INTERCAL, 84 bytes

PLEASE.4<-#4DOREADOUT.4DOREADOUT.4DOREADOUT.4DOGIVEUPPLEASELEAS..4<<--##DDOOUUGGIIVV

Try it online!

Ignores the second encouragement and essentially ignores the third (since unreachable syntax errors are pretty much comments), because I'm not feeling quite insane enough today to work around them in INTERCAL. Prints


IV

IV

IV

(6 spaces, 6 newlines, 3 Is, 3 Vs), transparently just three instances of the Roman numeral 4 which could actually just as well have been any other number since spaces get printed above them taking care of the third unique character. Had to be printed three times because number output brings two newlines along with it. Attempting to just print a third newline alone makes it a bit longer...

INTERCAL, 99 bytes

DO,1<-#1DO,1SUB#1<-#176DOREADOUT,1DO.3<-#3PLEASEREADOUT.3PLEASEGIVEUPDOOODD##UUBB7766REEAAT.LGGIIVV

Try it online!

Prints



III

(3 spaces, 3 newlines, 3 Is). Uses both numeric output and C-INTERCAL-style array output. Exactly as long as a version using just array output:

INTERCAL, 99 bytes

DO,9<-#9DO,9SUB#1<-#41DO,9SUB#4<-#77DO,9SUB#7<-#14PLEASEREADOUT,9PLEASEGIVEUPDO,<<--##SULRRTTGGIIVV

Try it online!

Prints

ëëëQQQ>>>

(no spaces or newlines for once). This is the approach which feels most clever to me, as it turns an obstructive feature of array output into a tool: when trying to output a value from an array, what it actually outputs is the previous value minus the value mod 256 with its bits read backwards. This makes it rather difficult to print any particular value, but means that if we want to print a string of repeating characters, we don't need to actually set the corresponding elements of the array, because arrays initialize their elements to zero, and the difference between two identical codepoints is also zero. So this only sets the first, fourth, and seventh elements of ,9, and hypothetically it could even get away with not setting the first one but I'm not sure that null bytes are valid characters.

INTERCAL, 87 bytes

DO,9<-#9DO,9SUB#4<-#7DO,9SUB#7<-#9DOREADOUT,9PLEASEGIVEUPPLEASEDO,,#SSUUB447RRTTLGGIIVV

Try it online!

If they are, then this version here still loses to the first one by 3 bytes, and prints this unprintable mess: 00 00 00 9F 9F 9F 0F 0F 0F.

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

stacked, 24 bytes

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

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

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

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.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ "...each line of code represents a snake swallowing its tail" (⊙.☉)7 \$\endgroup\$
    – Luigi
    Commented Jan 27, 2017 at 1:12
  • \$\begingroup\$ @Luigi en.wikipedia.org/wiki/Ouroboros (but yeah, that is a bit trippy) \$\endgroup\$
    – DLosc
    Commented Jan 27, 2017 at 3:46
3
\$\begingroup\$

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!

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

dc, 9 bytes

zfzfdzddf

Try it online!

Output:

0
1
0
3
3
3
1
1
0

(The program has no newlines; the output has 9 newlines.)


The new answer above is better than my old answer of the same length, because the new answer meets OP's suggestion that the output ideally shouldn't be the same string repeated 3 times. Here's the old answer, which I'll keep here so that @mbomb007's comment continues to make sense!

_A_A_Annn

Try the old answer online!

Output is

-10-10-10

(no newlines in either the program or the output)

\$\endgroup\$
2
  • 5
    \$\begingroup\$ ♫ Barbara _A_A_Annn \$\endgroup\$
    – mbomb007
    Commented Jan 25, 2017 at 21:03
  • \$\begingroup\$ @mbomb007 LOL!! \$\endgroup\$ Commented Jan 25, 2017 at 21:47
3
\$\begingroup\$

Chip, 30 bytes

**ZZZZZZZZZT
*gggaaabbbTT


Output:

@@@AAACCC

Try it online!

(score includes 3 total newlines, and 3 bytes 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.

\$\endgroup\$
4
  • \$\begingroup\$ Where are the 3 newlines? If you put your code in <pre><code>...</code></pre> in markdown, we'll be able to see them. \$\endgroup\$
    – mbomb007
    Commented Jan 25, 2017 at 21:06
  • \$\begingroup\$ @mbomb007 End of each line and one more at the end. Did that change anything? I don't see a difference... \$\endgroup\$
    – Phlarx
    Commented Jan 25, 2017 at 21:22
  • \$\begingroup\$ Oh, wow.... there's gray boxes. Apparently the contrast or gamma or something is really screwed up on one of my monitors. \$\endgroup\$
    – Phlarx
    Commented Jan 25, 2017 at 21:31
  • \$\begingroup\$ 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. \$\endgroup\$
    – mbomb007
    Commented Jan 25, 2017 at 21:35
3
\$\begingroup\$

C, 57 bytes

main(){printf("^^-_-^-__","");("{{pprrmmaainttff,,}}");;}

Output

^^-_-^-__

Alternative Version, 56 bytes

main(){printf("%1$d%1$d%1$d","({{pprrmmaainttff,,}})");}
\$\endgroup\$
5
  • \$\begingroup\$ { and } appear only once in your code, so I'm afraid this is not a valid answer. \$\endgroup\$
    – Laikoni
    Commented Apr 19, 2017 at 8:14
  • \$\begingroup\$ You also have a non-multiple-of-three number of " \$\endgroup\$ Commented Apr 19, 2017 at 8:28
  • \$\begingroup\$ @Laikoni added two more of { and }. \$\endgroup\$
    – Khaled.K
    Commented Apr 19, 2017 at 9:07
  • 1
    \$\begingroup\$ @VisualMelon added ,"" to printf \$\endgroup\$
    – Khaled.K
    Commented Apr 19, 2017 at 9:08
  • \$\begingroup\$ You can remove all three commas. \$\endgroup\$
    – Jakob
    Commented Jun 4, 2018 at 1:36
3
\$\begingroup\$

JSFuck (JavaScript), 84 bytes

!![]+!![]+[!![]+!![]]+(!![]+!![])+(+!![])+(+!![])+(+!![])+(+[])+(+[])+(+[])+(([[]]))

Try it online!

first we take the 3 shortest chars to express in jsfuck:

0: +[] (3 chars)
1: +!![] (5 chars)
2: !![]+!![] (9 chars)

combining them to get "222111000" we get this (75 chars) (this requires putting the second char in an array but then after that we can just add the other characters with the + operator):

!![]+!![]+[!![]+!![]]+(!![]+!![])+(+!![])+(+!![])+(+!![])+(+[])+(+[])+(+[])

this has these charcounts:

[ & ]: 13
( & ): 7
!: 18
+: 17

we can increase our +, (), and [] counts just enough by adding an arithmetic 0 to the end (+(([[]]))).

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

Squire commit c82e0e5, 21 bytes

dump(dump(dump(III)))

Squire hath provideth a strange builtin called dump, which releases some forbidden knowledge about what it was called with, then rewards the value itself.

Outputeth:

Number(3)
Number(3)
Number(3)

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

Julia 1.0, 21 bytes

@show @show @show 111

output:

111 = 111
#= /home/runner/.code.tio:1 =# @show(111) = 111
#= /home/runner/.code.tio:1 =# @show(#= /home/runner/.code.tio:1 =# @show(111)) = 111

inspired by EasyasPi's answer

Try it online!

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

Dis, 21 18 15 bytes

{{{|{{{|{{{!!!|

Try it online!

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

Plumber, 45 bytes

]][]
==[[=]=]]
[]][ [[=][
[[=][[[=
  =]][[=


Try it online!

The ]] and == at the beginning of the first two lines do nothing except lower the number of spaces and increase the number of those characters, and there are two trailing newlines to bring the total up to 6. This outputs the numbers 111000222.

Characters:

  • 15 [
  • 12 ]
  • 9 =
  • 6 \n
  • 3
\$\endgroup\$
2
\$\begingroup\$

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 

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

Retina, 27 bytes


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

Try it online

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

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Output typically has to be to stdout, not stderr. You should ask the OP if that's okay. \$\endgroup\$
    – mbomb007
    Commented Jan 25, 2017 at 22:53
  • \$\begingroup\$ @mbomb007 Maybe not: meta.codegolf.stackexchange.com/a/2451/36398 \$\endgroup\$
    – Arc676
    Commented Jan 26, 2017 at 9:30
  • \$\begingroup\$ @mbomb007 it's a default for allowed, but ill ask him. \$\endgroup\$
    – Offtkp
    Commented Jan 26, 2017 at 14:36
  • \$\begingroup\$ @P.Ktinos It has a lot of downvotes as well. For each 3 upvotes, there are at least 2 downvotes. The other answers are far less controversial. \$\endgroup\$
    – mbomb007
    Commented Jan 26, 2017 at 14:39
2
\$\begingroup\$

GNU Sed, 12 bytes

Golfed

abc
abc
abc

(note the trailing newline)

How It Works

a text

Appending text after a line. This is a GNU extension.

Appends the "bc" string + LF 3 times, resulting in 3 b, 3 c and 3 LF characters in the output.

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 !

\$\endgroup\$
3
  • 2
    \$\begingroup\$ The newline only appears twice, I think you can add an extra newline at the end to meet this requirement \$\endgroup\$
    – user41805
    Commented Jan 25, 2017 at 20:05
  • 2
    \$\begingroup\$ ^ What he said. Your source code's length must be divisible by 3. \$\endgroup\$
    – mbomb007
    Commented Jan 25, 2017 at 20:11
  • \$\begingroup\$ @KritixiLithos, mbomb007 - Thank you ! Should be fixed now ! \$\endgroup\$
    – zeppelin
    Commented Jan 25, 2017 at 20:15
2
\$\begingroup\$

Bash, 21 bytes

A pure Bash solution that has no external dependencies.

 e== ;e=cchhoo;echo $e$e$e;

Testing script

For convenience, I also wrote a test script that counts the number of occurrences of a character in a string. You can use it to validate your own solutions.

o={};
prompt``.split``.forEach(
ch=>o[ch]=o[ch]?o[ch]+1:1
);console.log(o)

\$\endgroup\$
3
  • \$\begingroup\$ Question states "... full program. Not an answer". Off of this I think this is invalid. \$\endgroup\$ Commented Jan 26, 2017 at 16:25
  • \$\begingroup\$ @geisterfurz007 Fixed. \$\endgroup\$ Commented Jan 26, 2017 at 16:40
  • \$\begingroup\$ Looking good I think :) Just noticed that I wrote an answer instead of a function... \$\endgroup\$ Commented Jan 26, 2017 at 16:57
2
\$\begingroup\$

Labyrinth, 12 bytes

Program:

!!!(!(!(!@@@

Output:

000-1-1-1

The last two @ aren't technically a comment, but they're just as useless. However, it's kind of inevitable since @'s a necessary character to exit a Labyrinth.

Explanation:

Labyrinth's stack contains an infinite number of 0's at the bottom.

!: pops the top of the stack and prints its decimal representation

(: decrements the top of the stack by 1

@: terminates the program

Because this program is a single line, most of Labyrinth's rules for deciding what direction to go are irrelevant; it just moves down the line from left to right.

\$\endgroup\$
2
\$\begingroup\$

VBA, 12 Bytes

Anonymous VBE immediates window function that takes no input and outputs to the VBE immediates window.

?75:?75:?75:

Output

75 
75 
75 
\$\endgroup\$
2
\$\begingroup\$

Python 27 Characters

print"\\\"printprint**"*333

The output and code comply with the rules. All characters occur 3 times in the code, as you can probably see. Since I'm multiplying by multiply of 3 the output will always be divisible by 3.

\$\endgroup\$
2
\$\begingroup\$

Carrot, 21 bytes

aaa^*2^bbb^*2^ccc^*2^

Outputs:

aaaaaaaaabbbaaaaaaaaabbbaaaaaaaaabbbcccaaaaaaaaabbbaaaaaaaaabbbaaaaaaaaabbbcccaaaaaaaaabbbaaaaaaaaabbbaaaaaaaaabbbccc

Which is a 117 byte long string containing 81 as, 27 bs and 9 cs.


This also works for 9 bytes but it isn't as fun:

aaabbbccc
\$\endgroup\$
1
  • \$\begingroup\$ I see you have an interest in Carrot :D Maybe you can help me decide a potential feature change in chat (don't mind the wrong ping in the message btw :/). \$\endgroup\$
    – user41805
    Commented Jun 15, 2017 at 16:55
2
\$\begingroup\$

SQL Server, PostgreSQL, SQLite, 27 bytes

SELECT  111222333 SSELLCCTT

Oracle SQL, MySQL, 46 bytes

SELECT  111222333 SSELCCTTFFRROOMMDDUUAAL  FROM DUAL

Output

111222333
\$\endgroup\$
2
  • 1
    \$\begingroup\$ The top answer needs an extra E: SELECT 111222333 SSELLCCT makes it 27 bytes (which makes sense, 26 isn't a multiple of 3). \$\endgroup\$
    – BradC
    Commented Jun 15, 2017 at 15:05
  • \$\begingroup\$ Other 27-character solutions exist, like PRINT 123PRINT 123PRINT 123 (for MS SQL), but I think I found one for 24: PRINT 12PRINT 12PRINT 12, since we can count the newline that PRINT produces. \$\endgroup\$
    – BradC
    Commented Jun 15, 2017 at 15:10
2
\$\begingroup\$

Ly, 15 bytes

'&::'o::'&::o&o

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Perl 5, 21 bytes

say"\\\"ssaayyxx33"x3

Try it online!

\$\endgroup\$

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.