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

1 2 3
4
1
\$\begingroup\$

BrainCrash, 21 12 bytes

[[[...>>>]]]

Try it online!


Previously:

...^...^...^[[[>>>]]]

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ The TIO appears to show a different program. \$\endgroup\$
    – darrylyeo
    Commented Jun 24, 2021 at 3:34
  • \$\begingroup\$ fixed; thanks for commenting me so. \$\endgroup\$
    – user100411
    Commented Jun 24, 2021 at 8:33
1
\$\begingroup\$

Perl 5 + -p, 15 bytes

}{s{}{$~$~$~}ss

Try it online!

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

Braingolf, 27 bytes

20111[!_!_!_+]2200++[][];;;

Try it online!

It's a cheap method, but only one I can find that works in braingolf.

Explanation

20111[!_!_!_+]2200++[][];;;
20111                        Pushes 2, 0, 1, 1 and 1 to the stack
     [.......]               While loop, runs 3 times..
      !_!_!_                 ..Prints the last item on the stack 3 times without popping
            +                ..Pops and sums the last 2 items, pushing the result
              2200           Pushes 2, 2, 0 and 0 to the stack
                  ++         Sums 0 and 0, then 0 and 2
                    []       While loop, runs 4 times, does nothing
                      []     While loop, runs 3 times, does nothing
                        ;;;  Suppress implicit output (then do it 2 more times)
\$\endgroup\$
0
\$\begingroup\$

Triangular, 21 bytes

3>\..3...(;...d/dp]%<

Try it online!

Formats into this triangle:

     3
    > \
   . . 3
  . . . (
 ; . . . d
/ d p ] % <

Prints 210210210. (2, 1 and 0 each printed 3 times.)

The program with only conrol flow:

     .
    > \
   . . .
  . . . .
 . . . . .
/ . . . . <

The above is a nice loop we can fit the code into. To achieve the desired output we simply want to print 210 three times. So we push 3 to the stack (the number of times we want to print it) and then 3 after a directional (3 decrements to 2, then to 1, then to 0).

The first directional \ pushes 3 to the stack, then puts the code into this loop: (d%]. That loop first decrements the top of stack, then prints it, then jumps back if the vale is nonzero.

The next part looks like this: pd; which pops the ToS (to get rid of the 0), decrements the new ToS (which was the 3 we pushed at the start), exit if the ToS is <= 0, then uses directionals to get back into the initial loop.

\$\endgroup\$
2
  • \$\begingroup\$ I like how the triangle code contains 30 spaces :) \$\endgroup\$
    – SK19
    Commented Mar 16, 2018 at 22:44
  • 3
    \$\begingroup\$ Each character in the source should appear three times \$\endgroup\$
    – Jo King
    Commented Mar 16, 2018 at 22:55
1 2 3
4

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.