title: Connect Four Validator

text:
# Question
Title: Connect Four Validator
# Introduction

Connect Four is a game where you attempt to get four in a row: horizontally, vertically, or diagonally. In this code golf, we will be trying to find who won, given a game board. There will always be one winner, and only one winner.

---

# Task

Given a Connect Four board, figure out who the winner is: `X` or `Y`. There will always be one winner, and only one winner. The board size will always be 6 by 7 like how the game board is in the in picture.

Given a board the following board, in this instance, `X` is red and `Y` is blue:

Your input would be:

```
OOOOOOO
OOOOOOO
OOOOOOO
OOOOXOO
OOOXXOO
OOXYYYY

```

You can separate rows of the game by newline character (like above), no dividing character, divide the rows into an array or list, or you can input a matrix of characters.

Correct output for this example:

```
Y

```

Y has four in a row; so, Y is the winner. So, we output Y.

---

# Test cases

Input:

```
OOOOOOO
OOOOOOO
OOOOOOO
OOOOOOO
OOYYOOO
OYXXXXO

```

Output:

```
X

```

---

Input:

```
OOOOOOO
OOOOOOO
OOOOOOO
XXXXOOO
YXYYOOO
YXYYXYX

```

Output:

```
X

```

---

Input:

```
YXYYXOO
XYXXYOO
XXXYYOO
YYYXXOO
XXYYYYO
XXYYXXO

```

Output:

```
Y

```

---

Input:

```
OOOOOOO
OOOOOOO
OYOOOOO
OOYOOOO
OOOYOOO
OOOOYOO

```

Output:

```
Y

```

---

Input:

```
OOOOOOO
OOOOOOO
OYOOOOX
OOYOOOX
OOOXOOX
OXOXYOX

```

Output:

```
X

```

# Scoring

Least number of bytes wins!

# Answer
# Jelly, 19 bytes

```
UŒD;ŒD;Z;ṡ€4;/ṢEÞṪṪ

```

Try it online!

The core of this answer is copied from my answer to this very similar question.

## Explanation

```
UŒD;ŒD;Z;ṡ€4;/ṢEÞṪṪ
   ;  ; ;             Append {the input} and the following three values:
UŒD                     the antidiagonals of {the input};
    ŒD                  the diagonals of {the input};
       Z                the transposed {input}.
         ṡ 4          Find all length-4 substrings
          €             of each subarray within that.
            ;/        Flatten one level.
                Þ     Sort, with the following sort order:
               E        If all elements are the same, sort later.
              Ṣ         Tiebreak via lexicographical order.
                 ṪṪ   Take the last element of the last element.

```

Fairly simple: we take all rows, columns, diagonals, and antidiagonals (just as in the n-queens validator), then take all length-4 substrings of those, then sort them in such a way that the winning line of 4 sorts to the end. (We need the tiebreak in case there's an `OOOO` in addition to the `XXXX` or `YYYY`.) Take the last element of the last element, and that'll be `X` or `Y` as required.
> 2 votes

# Answer
# Retina, ~~51~~ 48 bytes

*Thanks to Martin Ender for saving 3 bytes*

```
M`X((.{6}X){3}|(.{8}X){3}|(.{7}X){3}|XXX)
T`d`YX

```

Try it Online!

Takes input as a comma-separated list of rows
> 7 votes

# Answer
# Javascript (ES6), 54 ~~55~~

*Edit* 1 byte saved thanks @Arnauld

I just check if X is the winner, as *There will always be one winner, and only one winner*

Input is a string with any separator, like in @Arnauld's answer

```
F=
b=>'YX'[+[0,6,7,8].some(x=>b.match(`X(.{${x}}X){3}`))]

;['OOOOOOO OOOOOOO OOXOOOO OOXOOOO OOXOOOO OOXOYYY'
 ,'OOOOOOO OOOOOOO OOXOOOO OOYXOOO OOYOXOO OOYYOXY'
 ,'OOOOOOO,OOOOOOO,OOOOOOO,OOOOOOO,OOYYOOO,OYXXXXO'
 ,'OOOOOOO,OOOOOOO,OOOOOOO,XXXXOOO,YXYYOOO,YXYYXYX'
 ,'YXYYXOO,XYXXYOO,XXXYYOO,YYYXXOO,XXYYYYO,XXYYXXO']
.forEach(s => console.log(s,F(s)))
```
> 6 votes

# Answer
## JavaScript (ES6), ~~77~~ ~~76~~ 69 bytes

*Saved 7 bytes thanks to Neil*

Takes input as a *something*-separated string, where *something* is basically any character.

```
b=>[...'XXXXYYYY'].find((c,i)=>b.match(`(${c}.{${(i%4+6)%9}}){3}`+c))

```

### Test cases

```
let f =

b=>[...'XXXXYYYY'].find((c,i)=>b.match(`(${c}.{${(i%4+6)%9}}){3}`+c))

console.log(f("OOOOOOO,OOOOOOO,OOOOOOO,OOOOOOO,OOYYOOO,OYXXXXO"))
console.log(f("OOOOOOO,OOOOOOO,OOOOOOO,XXXXOOO,YXYYOOO,YXYYXYX"))
console.log(f("YXYYXOO,XYXXYOO,XXXYYOO,YYYXXOO,XXYYYYO,XXYYXXO"))
```
> 5 votes

# Answer
# Jelly, ~~25~~ 22 bytes

```
ŒgL⁼¥Ðf
;UŒD€;Z;$ç€4FṀ

```

Takes a list of strings (or list of list of characters) formed of `X`, `Y`, and `O` (would also work with replacements such that the space has a lower ordinal than both counters).

**Try it online!** or run an augmented version that takes a multiline string.

### How?

```
ŒgL⁼¥Ðf - Link 1, runs of given length: list A, length B  e.g. "XYYYXXO", 4
Œg      - group runs of equal elements of A                     ["X","YYY","XX","O"]
     Ðf - filter keep:
    ¥   -     last two links as a dyad:
  L     -         length                                         1   3     2    1
   ⁼    -         equal to B?         (none kept in this case->) 0   0     0    0

;UŒD€;Z;$ç€4FṀ - Main link: list of list of chars (or list of stings) I
 U             - reverse each row of I
;              - I concatenated with that
  ŒD€          - positive diagonals of €ach (positive and negative diagonals)
        $      - last two links as a monad:
      Z        -     transpose of I (i.e. the columns)
       ;       -     concatenated with I (columns + rows)
     ;         - concatenate (all the required directional slices)
         ç€4   - call the last link (1) as a dyad for €ach with right argument = 4
            F  - flatten the result
             Ṁ - take the maximum ('Y'>'X'>'O') - this has the bonus effect of returning:
                               'Y' or 'X' for a winning board; and
                               'O' or '' for a (valid) game in progress.

```
> 4 votes

# Answer
# Python 2, 143 bytes

```
m=input()
u=[r[::-1]for r in m]
print"YX"[any(any('X'*4in''.join(t[i][j-i]for i in range(j+1))for j in range(6))for t in(m[::-1],m,u,u[::-1]))]

```

Takes a list of strings or a list of list of chars. Hard-coded for **6** rows by **7** columns, as the specification guarantees.

**Try it online!**
> 3 votes

# Answer
# K (ngn/k), 45 bytes

```
{"YX"@|//{&/'(x;+x),x@'/:|:\!4}''+'4'4''~2!x}

```

Try it online!

Takes a matrix of characters and returns one of X or Y. If simplified I/O is allowed (0, 1, 2 for X, O, Y for input and boolean for output), I can remove `2!` from preprocessing and `"YX"@` from postprocessing, giving **38 bytes**.

### How it works

```
{"YX"@|//{&/'(x;+x),x@'/:|:\!4}''+'4'4''~2!x}   x: matrix of chars
~2!x       for each char, convert X to 1 and O/Y to 0
+'4'4''    extract all 4x4 sub-matrices using size-4 windows
{...}''    for each submatrix...
|:\!4        (0 1 2 3;3 2 1 0)
x@'/:        for each row of above, extract one element from each row of x
             which gives the diagonal and the antidiagonal of x
(x;+x),      prepend x and transpose of x
&/'          reduce each by boolean AND
             x -> vertical test, +x -> horizontal test
|//        repeat reducing by boolean OR until only one value remains
"YX"@      convert 1 to X and 0 to Y

```
> 3 votes

# Answer
# Python 2, ~~201~~ ~~143~~ ~~129~~ ~~128~~ 107 Bytes

I decided to add horizontal, vertical, and diagonal together into one list and then add increment then look for X for times in it. And since there will always be a winner, I can assume Y won if X doesn't. This codes takes a matrix of all the different pieces and empty places.

```
lambda m:"YX"[any("X"*4in"".join(a)for a in zip(*m)+m+zip(*["0"*(7-i)+m[i]+"00"*i+m[i]for i in range(6)]))]

```

Try it online!

Credits
> 2 votes

# Answer
# PHP, 71 Bytes

```
echo preg_match('#X(XXX|(.{8}X){3}|(.{7}X){3}|(.{9}X){3})#',$argn)?X:Y;

```

Online Version
> 2 votes

# Answer
# Python 3, ~~105~~ ~~90~~ ~~81~~ 80 bytes

Regex based. Lines are space separated. Saved 9 bytes thanks to @Lynn.

Saved 1 byte by utilizing the fact that there is a guaranteed match. So if there's no win for X then there must be a win for Y.

```
lambda x:re.findall('X(XXX'+'|(.{%d}X){3}'*3%(6,7,8)+')',x)and'X'or'Y'
import re

```

Try it online!
> 2 votes

# Answer
# PowerShell, ~~66~~ ~~65~~ ~~58~~ 54 bytes

I just check if X is the winner, as `There will always be one winner, and only one winner`. Thanks to edc65.

Input is a string with `no dividing character`. Thanks to Arnauld.

```
param($b)'YX'[1-in(0,5,6,7|%{$b-match"X(.{$_}X){3}"})]

```

Try it online!
> 2 votes

# Answer
# Zsh, ~~207 ...~~ 158 bytes

*Version history: 4 iterations for ~25 bytes first week; then 3 more iterations for ~25 bytes 6 months later, 1 more for 1 byte 11 months later.*

```
t(){a=($^a-$^@_);for s l (${w:^^argv}){s+=$l;i=;repeat $#s a[++i]+=$s[i+1];}}
w=(+)
t $@
for s;w[++j]=${(l:j:)}_
t $@
t ${(Oa)@}
[[ $a = *XXXX* ]]&&<<<X||<<<Y

```

~~(first) (second) (third) (fourth) (fifth) (sixth) (seventh)~~  (eigth)

In the footer, I print both the input board and the array we build from it to stderr. Scroll down to debug to see them. The array we build is a lot longer now, since `t` does a cartesian product with input board on *every* call. (Hey, it shortened the code by a few bytes.)

There's a lot to cover here, so I moved the (sixth edition) comments to an annotated gist.

(tl;dr: concatenate transpositions of the original array, but make sure to keep them separated)
> 1 votes

# Answer
# K (ngn/k), ~~58 55~~ 56 bytes

```
{"XY"@|/&/'88<x ./:/:,/{x+/:/:+3+[4#1-+!3 3;]\&4}'+!6 7}

```

Try it online!

`{` `}` function with argument `x`

`+!6 7` all possible pairs of 0..5 and 0..6

`{` `}'` for each of them do

`4#1-+!3 3` are 4 of the 8 ortho-diagonal directions: `(1 1;1 0;1 -1;0 1)`

`3+[` `]\&4` start with a list of four zeroes (`&4`) and make 3 steps in each of the directions

`x+/:/:` start from each possible position and take the steps in each possible direction

`,/` concatenate. at this point we have a matrix of 4-lists of coordinate pairs, some of them extending beyond the board

`x ./:/:` look up the corresponding cells from `x`

`88<` which of them are `"Y"`-s? (88 is the ascii code of `"X"`)

`&/'` which 4-lists consist only of `"Y"`-s? (and-reduce-each)

`|/` is there at least one such? (or-reduce)

`"XY"@` if false return `"X"`, if true return `"Y"`
> 1 votes

# Answer
# 05AB1E (legacy), ~~29~~ ~~26~~ 25 bytes

```
í‚εεÐм«NFÁ]€ø`IIø)J»γ4ùSà

```

Input as a character-matrix.

Uses the legacy version for -1 byte, since min/max also works on characters. In the new version of 05AB1E, the trailing `à` (maximum) should have been  instead (sort, keep last item).

Try it online or verify all test cases.

**Explanation:**

```
í                 # Reverse each row of the (implicit) input-list
 ‚                # Pair it with the (implicit) input-list
  ε               # Map over both matrices:
   ε              #  Map over each row:
    Ð             #   Triplicate the current row
     м            #   Remove all these characters, leaving a list of empty strings of the
                  #   same size as the row
      «           #   Merge this list of empty strings to the row
       NF         #   Loop the (0-based) row-index amount of times:
         Á        #    And rotate the row with appended empty strings towards the right
  ]               # Close the nested maps and inner loop
   €              # For both mapped matrices:
    ø             #  Zip/transpose; swapping rows/columns
                  # (we now have a list of all diagonals and anti-diagonals)
     `            # Push both lists of lists separated to the stack
      I           # Push the input again
       Iø         # And push the input, zipped/transposed
         )        # Wrap everyone on the stack into a list
                  # (we now have a list of all diagonals, anti-diagonals, rows, and columns)
          J       # Join each inner-most list of characters together to a string
           »      # Join each inner list together to a string; and then join these strings
                  # with newline delimiter
            γ     # Split everything into parts with equal adjacent characters
             4ù   # Only keep the parts of length 4
               S  # Flatten it to a list of characters
                à # And get the maximum character of this list
                  # (after which it is output implicitly as result)

```
> 1 votes

# Answer
# Ruby, 84 bytes

Takes the board as a single continuous string with no separators. Finds a non-O character that's in a connect-4 and returns it.

```
->b{b[(0..41).find{|i|b[i]!=?O&&[1,6,7,8].any?{|j|(1..3).all?{|n|b[i+j*n]==b[i]}}}]}

```

Try it online!
> 1 votes

# Answer
# , 42 bytes

```
1 e.[:,4 4(*/"1@,|:,,{~3 0+3 5*/i.@4);._3]

```

Try it online!

Takes input as a matrix of integers where 0 is blank, 1 is X, and 2 is Y. Returns 1 if X wins, 0 if Y wins.
> 1 votes

# Answer
# Python 3.8 (pre-release), ~~114~~ 112 bytes

Using a bitboard approach to check for 4 in a row.
Input: a 2D list of integers, where `0` represents empty cell, `1` is `X`, and `2` is `Y`.
Output: a positive integer if X wins, or `0` if Y wins.

```
lambda L:(b:=sum(sum(zip(*(L+[[0]*7])),())[i]%2<<i for i in range(49)))*any((r:=b&b<<i)&r<<i*2for i in(1,6,7,8))

```

Try it online!

## Explanation

The bitboard's layout is as follow (the missing positions in the last row is padded with 0):

```
0  8 16 24 32 40 48
1  9 17 25 33 41 49
2 10 18 26 34 42 50
3 11 19 27 35 43 51
4 12 20 28 36 44 52
5 13 21 29 37 45 53
6 14 22 30 38 46 54

```

This is the core of the function: given the bitboard `b` representing X's occupancies, check if X is winning:

```
any(
    # shift the board by i, 2i, 3i, 4i and and all of them together
    # if there's a set bit in the result (aka result != 0), then there is a 4-in-a-row
    (r:=b&b<<i)&r<<i*2
    # do this for all 4 directions
    # 1: vertical, 7: horizontal, 6 and 8: diagonal
    for i in(1,6,7,8)
)

```

This part contructs the bitboard `b` for X:

```
b:=sum(
    sum(zip(*
        (L+[[0]*7]) # append a row of 0 at the bottom of L
    ),())           # flatten L into a list, with the index correspond
                    #   to the correct position in the bitboard layout
    [i]%2<<i        # set the ith bit to 1 if the new list has X (=1) at that index
    for i in range(49)
) # sum all the set bits together to create the bitboard

```
> 0 votes

---
Tags: code-golf, game, decision-problem
---


# Question
Title: Count how many times your program repeats
Your task is to write a program or function. Its output/return value must follow these rules:

* The program outputs `1`
* The program repeated `n` times outputs `n`
* The program backwards outputs `-1`
* The program backwards and repeated `n` times outputs `-n`
* A mix of forward and backward programs will output `number_forward - number_backward`

Take the program `aB` for example.

* `aB` should output `1`
* `aBaB` should output `2`
* `Ba` should output `-1`
* `BaBa` should output `-2`
* `aBBa` should output `0`
* `aBBaBa` should output `-1`
* `aaB`, `C`, or  would not need to be handled

This is , so shortest in bytes per language wins.

# Answer
> 27 votes
# Jelly, 2 bytes

```
NC

```

**Try it online!** Or see all test-cases.

### How?

In Jelly any sequence of monadic atoms forms a monadic chain which simply applies those monadic atoms in turn from left to right, starting with the value of it's left argument. When a full program is run with no arguments zeros are implicitly supplied as necessary, i.e. `main_link(0)` is called. As such `NC` is `C(N(0))` and `CN` is `N(C(0))`.

```
NCNC ... CN ... NC - Main Link: no arguments
N                  - negate((implicit)0)     -1 *  0 =  0
 C                 - complement(that)         1 -  0 =  1
  N                - negate(that)            -1 *  1 = -1
   C               - complement(that)         1 - -1 =  2
     ...           -
     ...           -                             ... =  a
        C          - complement(a)            1 -  a =  1 - a
         N         - negate(that)       -1 * (1 - a) =  a - 1
            ...    -
            ...    -                             ... =  b
               N   - negate(b)               -1 *  b = -b
                C  - complement(that)         1 - -b =  b + 1

```

# Answer
> 14 votes
# Jelly, 3 bytes

I wonder if 2 bytes is possible in some language (I suspect that'd require it to consider the parity of the positions of the commands).

```
‘ḷ’

```

Explanation:  increments,  decrements, and  takes the left one, and for some magic reasons, when repeated, the program works as requested. Try it online!

# Answer
> 14 votes
# Bash, 39

Thanks to:

* @pxeger for `s/EXIT|TIXE/0/`
* @Sisyphus for `s/0 # 0/0/`

```

trap echo\ $[++a] 0 ]a--[$ \ohce part

```

Try it online!

# Answer
> 9 votes
# Polyglot Japt, R, Applescript, 5 bytes

All credit for this one goes to @DanielSchepler. Daniel, if you open a duplicate answer to this, I will happily delete this one.

```
0+1-0

```

I don't know Japt at all, but this is just simple arithmetic evaluation. The result of the last evaluation is output at the end of the program by default. Japt was the first language that I found that satisfied this, but I'm sure there are others.

Forward (1): Try it online!

Forward-Backward-Backward-Forward-Forward-Backward-Backward (1):Try it online!

# Answer
> 8 votes
# Perl 5 `-0777p`, 13 bytes

```

++$_;#;_$--

```

Try it online!

# Answer
> 7 votes
# 05AB1E, 4 bytes

```
¾¼.¾

```

Try it online - 1x forward: `1`.
Try it online - 1x backwards: `-1`.
Try it online - 3x forward: `3`.
Try it online - 3x backwards: `-3`.
Try it online - 1x forward + 1x backwards: `0`.
Try it online - 2x forward + 5x backwards + 1x forward: `-2`.

**Explanation:**

The *1x forward* program does the following:

```
¾     # Push the counter variable to the stack (0 by default)
 ¼    # Increment the counter variable
  .   # No-op, because `.¾` doesn't exist as 2-byte command, so it just ignores this
   ¾  # Push the counter variable to the stack (which is 1 now)
      # (implicitly output the top of the stack as result)

```

The *1x backward* program does the following:

```
¾     # Push the counter variable to the stack (0 by default)
 .¼   # Decrement the counter variable
   ¾  # Push the counter variable to the stack (which is -1 now)
      # (implicitly output the top of the stack as result)

```

Any combination of these two programs after one another increments and decrements the counter variable, but only the last value pushed to the stack is output implicitly at the very end.

# Answer
> 7 votes
# C++ (gcc), ~~324~~ ~~325~~ 323 bytes

Note the leading and trailing newlines.

Thanks to Jonathan Allen for spotting the need for a leading newline.

```

#ifndef M//
#define M(a,b)a##b//
#define W(z,x)M(z,x)//
#import<cstdio>//
int n;struct X{X(int d){n+=d;}};main(){printf("%d",n);}//
#endif//
X W(a,__LINE__)=1;//;1-=)__ENIL__,s(W X
//fidne#
//};)n,"d%"(ftnirp{)(niam;}};d=+n{)d tni(X{X tcurts;n tni
//>oidtsc<tropmi#
//)x,z(M)x,z(W enifed#
//b##a)b,a(M enifed#
//M fednfi#

```

Try it online!

aBaB (2)

Ba (-1)

BaBa (-2)

aBBa (0)

BaaB (0)

aBBaBa (-1)

## Rundown

Comments are used to make the code legal in forward as well as reversed form.

```
#ifndef M//
...
#endif//

```

These are your basic guards to make sure we only define things once.

```
int n;struct X{X(int d){n+=d;}};main(){printf("%d",n);}//

```

Inside the guard we also declare the integer n, which will be automatically initialized to 0 by virtue of being a global, as well as define a struct X, whose constructor takes an integer value to add to the global n. The `main()` function simply prints the value of n.

`main()` is run after all global variables have been sorted out, so we use the declaring of globals as a way to alter that value of `n` before `main()` is entered.

This requires a way to declare an arbitrary amount of variables, leading to:

```
#define M(a,b)a##b//
#define W(z,x)M(z,x)//

```

The main magic of the stew: Helper macroes that allow the gluing of tokens together in a very useful way. Calling `W(a,b)` will yield the token `ab`, with the potent twist of evaluating `b` as a macro first, which makes these kinds of things possible:

```
#define M(a,b)a##b
#define W(z,x)M(z,x)
#define b 10
int W(a,b);          // This makes an int called "a10"

```

We combine this with the special preprocessor macro `__LINE__` which always expands to the current line number, allowing us a way to produce an arbitrary amount of variables having unique names.

```
X W(a,__LINE__)=1;//;1-=)__ENIL__,s(W X

```

Suppose we are at line 553; this will then declare a variable `a553` of type `X`, running its constructor with the argument 1. The reversed version is identical, save for using -1 instead.

Our preprocessor guards make sure the above line and its reverse are the only things repeated.

# Answer
> 7 votes
# , 26 bytes

```
F+
1->F#F=FF
FF=F#F>-1-
+F

```

Try it online!

!enilno ti yrT

Twice backwards and four times forwards

A very different (and shorter) approach to Giuseppe's R answer (in which he predicted that this answer was coming!).

`F` is initially a shorthand for `FALSE` and so gets coerced to `0`. When the program is run forwards, we use rightwards assignment to get `F=F+1` and `FF=F`. When concatenated with itself, the program becomes

```
F+
1->F#F=FF
FF=F#F>-1-
+FF+
1->F#F=FF
FF=F#F>-1-
+F

```

Try it online!

and so the second time, we are doing `F=+FF+1` which also increments `F`.

When run backwards, the only difference is that we use `+-1` instead of `+1`.

When the final line is run, we print `+F`.

# Answer
> 5 votes
# Nim, 115 bytes

```

when not declared i:#1=-i
 var i=0;addQuitProc do:echo i#i ohce:od corPtiuQdda;0=i rav
i+=1#:i deralced ton nehw

```

There is a leading and trailing newline. The second line has a trailing space.

Try it online!

Try it online!Try it online!Try it online!

!enilno ti yrT

!enilno ti yrT!enilno ti yrTTry it online!!enilno ti yrT

# Answer
> 5 votes
# , ~~99~~ 91 bytes

```

l=readLines();`*`=grepl;1+sum("^l"*l-"^r"*l)#1-)r*'r^'-r*'l^'(mus;lperg=`*`;)(seniLdaer=r

```

Try it online!

-8 bytes thanks to Dominic van Essen!

Tripled

Reversed

Forwards and Backwards

Yet another iteration on third time the charm.

R has an odd but often useful (and not just for golfing) feature where data can be stored in the code, and read in as such. `readLines()` reads in lines until the end of the file. Then the `grepl` counts lines beginning with `l` (adding 1) and the ones beginning with `r` (adding `-1`), then incrementing/decrementing as appropriate: the first non-empty line is not counted as it's the only code that is run.

Starts/ends with a newline for reversing and concatenation purposes.

Possibly some `->` or `<-` chicanery will yield a shorter result -- indeed, Robin Ryder has proven me right, and it's shorter by a lot!

# Answer
> 5 votes
# Ruby, 41 bytes

```

$.+=1;END{exit!p$.}#}.$p!tixe{DNE;1=-.$

```

Try it online!

# Answer
> 4 votes
# Brain-Flak (Rain-Flak), 16 bytes

```
({}())#)])([}{(

```

Try it online!

## Explanation

Making a program that when repeated counts up is easy

```
({}())

```

This adds 1 and with no input it defaults to zero, so repeating it counts the number of times.

However reversing is a little trickier. Only one balanced string is also a balanced string in reverse and that is the empty string, so we need to use some comments. We use the line comments of the Rain-Flak interpter and hide a payload between a `#` and a newline. Which simply is

```
({}[()])

```

This works the same way as the original program but with minus 1 instead of 1.

# Answer
> 4 votes
# Python IDLE, 5 bytes

```
0-~+0

```

Try it online!

## Explanation

### Forwards

```
0      # zero
 -~    # minus-complement (the increment prefix "operator", which
       #                   also works as a binary add-plus-one)
   +0  # zero

```

### Concatenated

```
0           # zero
 -~         # plus one plus
   +00      # zero
      -~    # plus one plus
        +0  # zero

```

## Reversed

```
0      # zero
 +     # plus
  ~-   # complement-minus (the decrement prefix "operator")
    0  # zero

```

## Bonus variants

* `0-~-0`, which counts up regardless of flipping (in fact, it's palindromic);
* `0+~+0`, which counts down regardless of flipping.

# Answer
> 4 votes
# Vyxal, 5 bytes

```

›#‹

```

Try it Online!

Try it Online!Try it Online!

Try it Online!Try it Online!Try it Online!Try it Online!Try it Online!

!enilnO ti yrT

!enilnO ti yrTTry it Online!!enilnO ti yrT

# Answer
> 3 votes
# Wolfram Language (Mathematica REPL), 5 bytes

```
0+1-0

```

Test cases:

```
0+1-0            1
0+1-00+1-0       2
0-1+0           -1
0-1+00-1+0      -2
0+1-00-1+0       0
0+1-00-1+00-1+0 -1

```

Try it online!

# Answer
> 3 votes
# Haskell, 35 bytes

```
main=print$0--1-
 +1--0$tnirp=niam

```

Try it online!

I tried for quite a bit to do this without comments. It doesn't seem impossible, but it does seem very hard.

# Answer
> 3 votes
# Python 3, ~~109~~ 107 bytes

Same approach as my zsh answer, but it actually beats the other Python answer!

```
c=open(__file__).read().count;print(c('w	')-c('y\t'))#))'	y'(c-)'t\w'(c(tnirp;tnuoc.)(daer.)__elif__(nepo=c

```

Try it online!

-2 bytes thanks to @Jakque

# Answer
> 3 votes
# ARM Thumb, 8 bytes excluding return statement

Raw machine code:

```
2101 1840 3901 2100

```

Assembly:

```
        .thumb
        @ R1 = 1
        movs    r1, #1
        @ r0 += 1
        adds    r0, r1
        @ Dummy code
        subs    r1, #1
        movs    r1, #0

```

Reverse each 16 bits

```
2100 3901 1840 2101

```

```
        .thumb
        @ r1 = 0
        movs    r1, #0
        @ r1 = -1
        subs    r1, #1
        @ r0 += -1
        adds    r0, r1
        @ Dummy code
        movs    r1, #1

```

Going forwards, it sets r1 to 1 and adds it to r0

Going backwards, it sets r1 to 0, subtracts 1 to get r1 to -1 (since Thumb can only load 0-255), then adds it to r0 effectively subtracting 1.

Call it with r0 = 0.

You need to end it with a return statement (`bx lr` or `4770` in hex) at the end, but those four instructions can be repeated forward and backwards as many times as you desire.

# Answer
> 3 votes
# ARM (NOT thumb), 16 bytes excluding return instruction

Second, entirely different answer, still 4 instructions though.

Machine code:

```
01 10 80 e3 01 00 80 e0 e0 80 00 01 e3 f0 10 00

```

This one, unlike my Thumb submission, is entirely different in that it is **byte** reversible (hence why it is split in 8 bits instead of 32 bits)

It happens to do basically the same thing, though, add 1 on forwards and -1 on backwards.

Forwards:

```
        movs      r1, #1
        add       r0, r0, r1
        smlatteq  r0, r0, r0, r8
        andseq    pc, r0, r3, ror #1

```

Backwards:

```
        movs      r1, #-1   @ a.k.a. mvns      r1, #0
        add       r0, r0, r1
        smlatteq  r0, r0, r0, r8
        tsteq     r0, r3, ror #1

```

You may be asking yourself, "`smlatteq`? `andseq`? `tsteq`? What the \**** do those do?"

The answer is nothing unless the zero flag is set.

This code **heavily** abuses ARM's conditional execution and "s" instructions.

`movs` will set the condition flags on the value it sets (why this exists for the immediate form, I will never know). I set them to 1 on forwards, and -1 on backwards. These are both non-zero, so they **clear** the zero flag.

We also use the version of `add` which does not update the flags, so the zero flag remains clear.

Therefore, since the zero flag is not set, all instructions with the `eq` suffix will be ignored.

And that is a VERY good thing, because `ands pc, r0, r3, ror #1` would almost certainly crash the program (it would jump to a garbage address)

Therefore, in terms of what is effectively executed, it is this:

Forwards:

```
        movs      r1, #1
        add       r0, r0, r1
        nop
        nop

```

Backwards:

```
        movs      r1, #-1           @ a.k.a. mvns      r1, #0
        add       r0, r0, r1
        nop
        nop

```

Similar to my Thumb answer, you can repeat these as much as you wish, but you must put a `bx lr` (`e12fff1e`) at the end, and it is called with `r0 == 0`.

# Answer
> 3 votes
# Python 3.8 (pre-release), ~~77~~ 71 bytes

```
for i in(1,a:=0):#)a(tnirp ro i=-a
 a+=i or print(a)#:)0=:a,1(ni i rof

```

Try it online! (include testcases)

## How it works

The starting code is this :

```
for i in(1,a:=0):#<...>
 a+=i or print(a)#<...>

```

At the first iteration of the `for` loop

* The `for` loop assigns `a` to `0` and `i` to `1`.
* since `i` is equal to `1`, `i or print(a)` won't evaluate the print and will be equal to 1
* `a+=` we increment a (become `a-=` in the reversed program)

At the second iteration of the `for` loop:

* The `for` loop assigns `i` to `0`.
* `i or print(a)` will print `a` since `i` is evaluated as `False` and return `None`
* it then crash the program (to avoid multiple printing) since we try to add `None` to an integer

When chained, the prgrams become :

```
for i in(1,a:=0):#<...>
 a+=i or print(a)#<...>for i in(1,a:=0):#<...>
 a+=i or print(a)#<...>

```

There is only one active `for` loop (the other one are commentated), and the incrementation (or decrementation when reversed) occurs once for each repetition of the program. The printing occurs only once beacause of the crash.

The reverse program is only changing `a+=` by `a-=`

# Answer
> 2 votes
# Charcoal, 16 bytes

```
υΣＩ⁰⎚¹±υ⊞υ¹⎚⁰ＩΣυ

```

Try it online! Explanation:

```
υ

```

Print the list.

```
ΣＩ⁰

```

Cast 0 to string, then take the digital sum and print it (this happens to do nothing).

Clear the canvas.

```
¹

```

Print a `-`.

```
±υ

```

Print the negated list.

```
⊞υ¹

```

Push `1` to the list. (This is what actually affects the final output.)

Clear the canvas.

Print nothing.

```
ＩΣυ

```

Cast the sum of the list to string and print it. (This code at the end of the last copy is the only output that survives the program.)

Try it reversed! Explanation: The middle instructions differ slightly when the code is reversed:

```
¹

```

Print a `-`.

```
υ

```

Print the list.

```
⊞υ±¹

```

Push `-1` to the list.

# Answer
> 2 votes
# Python 3, 164 bytes

```

import atexit as a;a._clear();a.register(lambda:print(v));v=locals().get('v',0)+1#;1-)0,'v'(teg.)(slacol=v;))v(tnirp:adbmal(retsiger.a;)(raelc_.a;a sa tixeta tropmi

```

**Try it online!** Or use this program builder (Input `F` for forward and `R` for reverse).

# Answer
> 2 votes
# JavaScript, ~~131~~ ~~121~~ 122 bytes

* -10 thanks to Arnauld
* +1 I forgot that the newline would also be reversed, so another one needed to be added

```

clearTimeout(this.a);a=setTimeout(console.log,0,b=-~this.b)//)b.siht-~=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc;

```

(notice the leading and trailing newlines. the stacksnippets removes some of the leading and trailing newlines for the entire snippet, but it still works with/without the first and last newlines)

Try It Right Here! (TryItOnline has an error where `clearTimeout` is not defined, but `clearTimeout` is a valid JavaScript function.)

aB

```
clearTimeout(this.a);a=setTimeout(console.log,0,b=-~this.b)//)b.siht-~=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc
```

aBaB

```
clearTimeout(this.a);a=setTimeout(console.log,0,b=-~this.b)//)b.siht-~=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc

clearTimeout(this.a);a=setTimeout(console.log,0,b=-~this.b)//)b.siht-~=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc
```

Ba

```
clearTimeout(this.a);a=setTimeout(console.log,0,b=~-this.b)//)b.siht~-=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc
```

BaBa

```
clearTimeout(this.a);a=setTimeout(console.log,0,b=~-this.b)//)b.siht~-=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc

clearTimeout(this.a);a=setTimeout(console.log,0,b=~-this.b)//)b.siht~-=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc
```

aBBa

```
clearTimeout(this.a);a=setTimeout(console.log,0,b=-~this.b)//)b.siht-~=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc

clearTimeout(this.a);a=setTimeout(console.log,0,b=~-this.b)//)b.siht~-=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc
```

aBBaBa

```
clearTimeout(this.a);a=setTimeout(console.log,0,b=-~this.b)//)b.siht-~=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc

clearTimeout(this.a);a=setTimeout(console.log,0,b=~-this.b)//)b.siht~-=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc

clearTimeout(this.a);a=setTimeout(console.log,0,b=~-this.b)//)b.siht~-=b,0,gol.elosnoc(tuoemiTtes=a;)a.siht(tuoemiTraelc
```

# Answer
> 2 votes
# Zsh, 91 bytes

```
<<<$[`grep -c wx $0`-`grep -c y\z $0`];:<<'Q'
'Q'<<:;]`0$ zy c- perg`-`0$ x\w c- perg`[$<<<

```

Try it online!

## Explanation

The overall idea is to read the source file and count the number of occurrences of the code forwards, minus the number backwards.

```
     `grep -c wx $0`                           # count occurrences of `wx`
                     `grep -c y\z $0`          # count occurrences of `yz`*
   $[               -                ]         # subtract
<<<                                            # print
                                      ;        # then
                                       :       # do nothing,
                                        <<'Q'  # with the rest of the file**

```

`*`: The backslash in the middle prevents the call to grep itself from being counted as an instance. In the mirrored copy on the next line, the backslash is placed inside `wx` instead, so that when re-reversed, it matches the negative one instead.

`**`: This starts a here-document, which consumes as input the rest of the file until the first line containing only `FW`. The single-quotes prevent execution of any `$[...]` and ``...`` parts from any possible repeated sections afterwards. We can't use line comments because `grep -c` outputs the number of matching lines, not individual matches. In another language we won't have this limitation.

The whole program is then duplicated, with the `\` inside the `wx` instead of the `yz`, is then reversed and put on the next line, so that it works as expected when the first instance is a reversed one.

# Answer
> 2 votes
# Klein 000, 12 bytes

```
\@+
 -
1
+@\

```

Try it online!

**Reversed**

```
\@+
1
-
+@\

```

Try it online!

# Answer
> 2 votes
# Wolfram Language (Mathematica), 31 bytes

```
tnirP//1-eniL$--
$Line++//Print

```

Try it:

A full program. `$Line` has an initial value of `1`. In a notebook, it would increment for each input expression, but this doesn't apply outside the REPL.

# Answer
> 2 votes
# Python 3, 112 bytes

```

import os#1=-KO_R.so
os.system('cls')#)5-KO_R.so(tnirp
print(os.R_OK-3)#)'slc'(metsys.so
os.R_OK+=1#so tropmi

```

very ugly, but works.

# Answer
> 2 votes
# JavaScript (Node.js), 104 bytes

```

var i=-~i,y=-~y;setTimeout(_=>--i||console.log(y))//))y(gol.elosnoc||i-->=_(tuoemiTtes;y-~=y,i~-=i rav

```

Try it online!

Using V8(`print`) or browser(`alert`) saves some bytes

# Answer
> 1 votes
# Ruby, 60 bytes

Note trailing newline:

```
a||=0;a+=1;at_exit{p a;exit!}#}!tixe;a p{tixe_ta;1=-a;0=||a

```

Try it online!

Reversed version (leading newline):

```

a||=0;a-=1;at_exit{p a;exit!}#}!tixe;a p{tixe_ta;1=+a;0=||a

```

Try it reversed!

`at_exit` specifies a block to be executed upon `exit`, `SystemExit` exception, or uncatchable error. `exit!` specifically bypasses these, giving the ability to skip all but the first registered block.

# Answer
> 0 votes
# \>\<\>, 19 bytes

## Forwards

```
l\ v
;l-n
n+l;
v \l

```

Try it online!

## Backwards

```
l\ v
;l+n
n-l;
v \l

```

Try it online!

Works a lot like my klein solution, but it has to deal with the finickiness of \>\<\>.

---
Tags: code-golf, source-layout
---


title: Three-Three-Three!

text:
# Question
Title: Three-Three-Three!
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:

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

# Answer
# Brain-Flak, Flakcats, Brain-Flueue, Brain-Flak Classic, Miniflak, and Fλak 18 bytes

***Proven optimal!***

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

```

Try it online!

## Explanation

### Brain-Flak, Brain-Flueue, Miniflak, and Fλak

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

```

This prints:

```
-3
-3
-3

```

*(There is a trailing newline)*

### Brain-Flak Classic

Brain-Flak Classic is the original version of Brain-Flak and has some important differences from modern Brain-Flak. In BFC `[...]` prints its contents rather than negating it.

```
   [()] Print 1
       [()] Print 1
           [()] Print 1
  (            ) Push 3
 (              ) Push 3
(                ) Push 3

```

At the end of executing the contents of the stack (`3 3 3`) is printed.

This prints:

```
1
1
1
3
3
3

```

*(There is a trailing newline)*

### Flakcats

Flakcats is quite different from the other 4 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:

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

```

This prints:

```
-3
-3
-3

```

*(There is a trailing newline)*

## Proof of Optimality in Brain-Flak and Miniflak

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

Since Miniflak is a subset of Brain-Flak any shorter Miniflak program would also be a shorter Brain-Flak program and thus does not exist.

## Proof of Optimality in Brain-Flueue

Brain-Flueue is a joke language based off of Brain-Flak. The two are so similar their interpreters are identical everywhere but two lines. The difference between the two is, as their names suggests, Brain-Flueue stores its data in queues while Brain-Flak stores its data in stacks.

To start we have the same restrictions on program size created by Brain-Flak, thus we are looking for a program of size 12. In addition we are going to need a `(...)` in order to create any output and another pair. the `<>` and `[]` pairs do not work in Brain-Flueue for the exact same reason they do not work in Brain-Flak.

Now we know that our program must consist of the characters `((())){{{}}}`.

Via the same methods used in the previous proof we can demonstrate that there must be a loop in the final program.

Now here is where the proofs differ, because Brain-Flueue operates across queues rather than stacks the program can exit a loop with values on the queue.

In order to exit the loop we will need a zero in the queue (or an empty queue but if the queue is empty we get the same problem as Brain-Flak) this will mean that we will have to open our program with `({})` to create the zero. We will need a push inside of the loop to push the necessary number of items to the queue. We will also need to push a non zero number before the loop so that we can enter the loop at all; this will cost us at absolute minimum `(())`. We have now used more parens than we have.

Thus there is no Brain-Flueue program to do the task that is 12 bytes, and furthermore there our program is optimal.

## Optimal solution in Flakcats and Brain-Flak Classic

The following solution is optimal in Flakcats and Brain-Flak Classic.

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

```

---

### Explanation

```
    [][][] -3
 (((      ))) push 3 times

```

## Alternative 24 byte Brain-Flak solutions

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

```

Try it online!

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

```

Try it online!

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

```

Try it online!
> 60 votes

# Answer
# Jelly, 9 bytes

```
**‘‘‘888*

```

A full program which prints **700227072**, which is 888 cubed.

**TryItOnline!**

### How?

```
**‘‘‘888* - Main link: no arguments
          - implicit L=R=0
*         - power       A = L ^ R = 1
  ‘       - increment   B = L + 1 = 1
 *        - power       C = A ^ B = 1
   ‘      - increment   D = C + 1 = 2
    ‘     - increment   E = D + 1 = 3
     888  - literal     F = 888
        * - power           F ^ E = 700227072

```
> 31 votes

# Answer
# 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 )
* (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
* (the R display also outputs \[1\] as metadata)
* RProgN
* Actually (though it actually prints `2\n2\n2\n1\n1\n1\n3\n3\n3\n`)
* ///
* Noodel
* TI-Basic
* SimpleTemplate
* ReRegex
* Husk
* Resource (although this outputs the string reversed)
* `cat`

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

Most links go to Try It Online!
> 24 votes

# Answer
## C#, ~~114~~ ~~111~~ ~~118~~ 102 bytes

If we don't care about using proper words: (102 bytes)

```
class CCcddiilMMmmnrrSSsttvvWWyy{static void Main(){{System.Console.Write(("A TEA AT TEE"));;;}}}///".

```

If we care about proper words: (120 bytes)

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

```

My original submission - case insensitive: (113 bytes)

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

```

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.

Edit: Thank you to roberto06 for catching the missing letters!
> 22 votes

# Answer
# 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)"`.
> 21 votes

# Answer
# 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

```
> 15 votes

# Answer
# brainfuck, 12 bytes

```
++[+...][][]

```

Nobody said the output had to be short. This will output 3 copies of every ascii character except the first 2.

You can prove that this is as short as it will get. You need to output therefore you need 3 '.' there need to be different outputs therefore you need 3 \[+-\] now we're up to 6. 9 characters have to be printed, which means either adding 6 more '.' or adding a loop, which will add another 6 characters.

Try it online!
> 13 votes

# 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;

```
> 10 votes

# Answer
# 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)`.
> 10 votes

# 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
> 9 votes

# Answer
# Ruby, 12 bytes

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

```

outputs

```
nil
nil
nil

```

Try it online!

To fulfill the second "encouraged" criterion, I need 15 characters:

```
p 1;p 3;p 1133;

```

produces

```
1
3
1133

```

Try it online too!
> 9 votes

# Answer
# C, 66 Bytes

```
main(i){{for(i=0;i<3;i++){printf("""poop+fart=<3<3at0m=m0n""");}}}

```

### Output

```
poop+fart=<3<3at0m=m0npoop+fart=<3<3at0m=m0npoop+fart=<3<3at0m=m0n

```

### Old Version 72 Bytes

```
main(i){for(i=0;i<3;i++){printf("poop+fart=<3<3 at {\"0m=m0\"}" "\n");}}

```
> 9 votes

# Answer
# JavaScript (ES6), 30 bytes

```
+alert((({alert}+{alert}+{})))

```

Outputs `[object Object][object Object][object Object]`.

Works by creating three objects:

* the first two are of the form `{ "alert" : alert }` using ES6 notation `{alert}`
* the third is a simple empty object

Then it uses `+` to concatenate them together, and all three have an identical expression as a string, `[object Object]`.

The leading `+` is useless, only present to fill out the number of `+` characters, but is harmless to the output of the program.
> 9 votes

# Answer
# Hexagony, 9 bytes

```
x!!xx@@!@

```

Try it online!

Print out `120120120`. `x` can be replaced by `f-m` (102-109)

### Explanation

```
  x ! !
 x x @ @
! @ . . .

```

The `xx@@` is only a filler to comply with the rules. The main flow is saving `x` into the memory (with ASCII value 120) and then print it as a number 3 times.
> 8 votes

# 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.
> 7 votes

# Answer
# Bash \+ coreutils, ~~15~~ 9 bytes

```
id;id;id;

```

Try it online!

Sample Output:

```
uid=1000 gid=1000 groups=1000 context=system_u:unconfined_r:sandbox_t:s0-s0:c19,c100,c173,c211
uid=1000 gid=1000 groups=1000 context=system_u:unconfined_r:sandbox_t:s0-s0:c19,c100,c173,c211
uid=1000 gid=1000 groups=1000 context=system_u:unconfined_r:sandbox_t:s0-s0:c19,c100,c173,c211

```

(If you try this out, it will print your uid, gid, etc., 3 times.)

---

If you want to avoid repeating the same string 3 times (and also have the same output for everybody, unlike my first answer), the best I've found for bash + Unix utilities is 15 bytes long:

```
dc<<<cczdzfzfdf

```

Try this second version online!

Output:

```
2
0
0
3
2
0
0
3
3
2
0
0

```

(No newlines in the program, 12 newlines in the output.)

Explanation of the dc program in this answer:

```
c Clears the stack.
Stack: (empty)

c Clears the stack.
Stack: (empty)

z Pushes the current size of the stack (0) onto the stack.
Stack: (top) 0

d Duplicates the item at the top of the stack.
Stack: (top) 0 0

z Pushes the current size of the stack (2) onto the stack.
Stack: (top) 2 0 0

f Prints the stack, top to bottom, with a newline after each item printed (this prints the first 3 lines of the output, 2 / 0 / 0 /)

z Pushes the current size of the stack (3) onto the stack.
Stack: (top) 3 2 0 0

f Prints the stack, top to bottom, with a newline after each item printed (this prints the next 4 lines of the output, 3 / 2 / 0 / 0 /)

d Duplicates the item at the top of the stack.
Stack: (top) 3 3 2 0 0

f Prints the stack, top to bottom, with a newline after each item printed (this prints the final 5 lines of the output, 3 / 3 / 2 / 0 / 0 /)

```
> 7 votes

# Answer
# C, 111 bytes

(Note how the byte count is also the three same numbers. Wow. You can't do more meta than that.)

```
#include<stdio.h>
#define b "<acdhlmoprsu>."
#define t "en"
main(){{{printf(("<acdhlmoprsu>." b b t t t));;;}}}

```

Prints:

```
<acdhlmoprsu>.<acdhlmoprsu>.<acdhlmoprsu>.enenen

```
> 7 votes

# 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!
> 6 votes

# Answer
# *99*, 15 bytes

```
9 9  9999
9
9
9

```

That is nine nines, three spaces, and three line feeds, the output is **-1110-1110-1110**.

**Try it online!**

### How?

```
9 9  9999 - V(9)=V(9)-V(9999)=1-1111=-1110
9         - print V(9)
9         - print V(9)
9         - print V(9)

```

The two spaces are treated as one, this third space could be a trailing space on any line too.
> 6 votes

# Answer
# LOLCODE, ~~273~~ 240 (~~360~~ 286) bytes

```
HAI 1.2
I HAS A U
IM IN YR M UPPIN YR Q TIL BOTH SAEM Q 1
VISIBLE "Y SUB.EK"
IM OUTTA YR M
IM IN YR T UPPIN YR Q TIL BOTH SAEM Q 2
VISIBLE "Y SUB.EK"
IM OUTTA YR T
IM IN YR X UPPIN YR Q TIL BOTH SAEM Q 12
VISIBLE "IM"
IM OUTTA YR X
KTHXBYE

```

Note the trailing new line and try it online. The second line was more or less arbitrary and can possibly replaced by a shorter command, but I just learned LOLCODE for this puzzle. Since the version number is required in the first line, I used the numbers to add loops of length 1, 2 and 0 mod 3 to ensure the right number of characters will be printed. From this I simply counted each character (with this tool). If it appeared 0 mod 3 times, no action was required. If it appeared 1 mod 3 times, it was added to the 1- and 2-loop so it would appear three times in the output. If it appeared 2 mod 3 times, the character was added to the 12-loop. **EDIT:** By replacing the first `VISIBLE` with an assignment (still useless but required to have 12 instead of 11 new lines), I was able to cut off 33 bytes.

Output (60 byte):

```
Y SUB.EK
Y SUB.EK
Y SUB.EK
IM
IM
IM
IM
IM
IM
IM
IM
IM
IM
IM
IM

```

Note the trailing new line.

Nice thing about this solution in comparison to the other answers is that the Output can easily manipulated to output somewhat meaningful text. Example (286 bytes with trailing new line):

```
HAI 1.2
I HAS A U
IM IN YR MW UPPIN YR Q TIL BOTH SAEM Q 1
VISIBLE "YO SUB. EEEEK!"
IM OUTTA YR MW
IM IN YR STA UPPIN YR Q TIL BOTH SAEM Q 2
VISIBLE "YO SUB. EEEEK!"
IM OUTTA YR STA
IM IN YR XURG UPPIN YR Q TIL BOTH SAEM Q 12
VISIBLE "IMO U R SWAG! "
IM OUTTA YR XURG
KTHXBYE

```

Try it online. Output (222 bytes with trailing new line):

```
YO SUB. EEEEK!
YO SUB. EEEEK!
YO SUB. EEEEK!
IMO U R SWAG!
IMO U R SWAG!
IMO U R SWAG!
IMO U R SWAG!
IMO U R SWAG!
IMO U R SWAG!
IMO U R SWAG!
IMO U R SWAG!
IMO U R SWAG!
IMO U R SWAG!
IMO U R SWAG!
IMO U R SWAG!

```

Sadly, I'm not as good with anagrams as I thought :')
> 6 votes

# Answer
**SHELL**

to joke :) ( **9 Bytes** )

```
ls;ls;ls;

```

or more seriously ( **24 Bytes** )

```
sed s/./sed.g./g <<< edg

```

Result :

```
sed.g.sed.g.sed.g.

```
> 6 votes

# Answer
PHP, 24 bytes

```
<?=111?><?=222?><?=333?>

```
> 5 votes

# Answer
# , 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
> 4 votes

# Answer
# SMBF, ~~18~~ ~~15~~ 12 bytes

This program prints its source code backwards. The first loop `[[..]]` and last `<` could be removed if it weren't for the source-restriction.

```
[[..]]<[.<]<

```

**Try it online**

**Output:**

```
<]<.[<]]..[[

```

### Proof of Optimality:

Since the output requires at least nine characters (3 unique, 3 each), the program either needs nine prints `.` plus 3x2 other instructions to meet the source-restriction (this means 15 bytes), or the code uses a loop.

If it uses a loop, the characters necessary are `[].`, three of each. Of course, a movement instruction `<` or `>` is necessary to avoid an infinite loop, meaning that a valid solution will be at least 12 bytes.
> 4 votes

# 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.
> 4 votes

# Answer
# Befunge 93, 9 bytes

```
...,,,@@@

```

TIO

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

Because Befunge's stack is padded with `0`s, 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
> 4 votes

# Answer
# 05AB1E, 9 bytes (I guess you could say this was a piece of PI)

*-0 bytes thanks to Emigna/ETHProductions, made the solution more correct.*

```
žqžqžq???

```

Alternate versions:

```
ž[g-Q]ž[g-Q]ž[g-Q]???

```

`[g-Q]` \- Can put any letter a-Q here, as long as they all match (see below).

Try it online!

**Explained:**

`PI,PI,PI,SORT,JOIN,SORT,JOIN,SORT,JOIN.`

**Result:**

`...111111222333333333444555555555666777888999999999`

The reason it is only 9 bytes is because you don't need the sorts, I just put them in to help illustrate.

**Result w/o `{` in the code:**

`3.1415926535897933.1415926535897933.141592653589793`

---

**Alternative Renditions:**

The following commands can be used in place of PI:

```
ž 23  > žg       push current year
        žh       push [0-9]
        ži       push [a-zA-Z]
        žj       push [a-zA-Z0-9_]
        žk       push [z-aZ-A]
        žl       push [z-aZ-A9-0_]
        žm       push [9-0]
        žn       push [A-Za-z]
        žo       push [Z-Az-a]
        žp       push [Z-A]
        žq       push pi
        žr       push e
        žu       push ()<>[]{}
        žy       push 128
        žz       push 256
        žA       push 512
        žB       push 1024
        žC       push 2048
        žD       push 4096
        žE       push 8192
        žF       push 16384
        žG       push 32768
        žH       push 65536
        žI       push 2147483648
        žJ       push 4294967296
        žK       push [a-zA-Z0-9]
        žL       push [z-aZ-A9-0]
        žM       push aeiou
        žN       push bcdfghjklmnpqrstvwxyz
        žO       push aeiouy
        žP       push bcdfghjklmnpqrstvwxz
        žQ       push printable ASCII character set (32-128)

```
> 4 votes

# Answer
# Japt, 9 bytes

```
000OoOoOo

```

Prints `undefinedundefinedundefined`. Test it online!

### Explanation

This code gets transpiled into the following JavaScript:

```
000,O.o(O.o(O.o()))

```

`O.o` is a function that outputs something without a trailing newline. When given no argument, it prints `undefined`, which could be considered a bug, but comes in handy here. It also returns `undefined`, so all three calls prints `undefined`.

I'm sure there are plenty of other ways to do this...
> 4 votes

# Answer
# Cubix, 12 bytes

A bit of a boring answer really. Outputs three `10`s followed by newlines

```
N@N@NOoOoOo@

```

Try it online! Maps to the cube

```
    N @
    N @
N O o O o O o @
. . . . . . . .
    . .
    . .

```

`N` Pushs 10 to the stack
`Oo` x3 Outputs 10 and newline
`@` halts the program

The initial `N@N@` is not hit.
> 4 votes

# Answer
# Japt, 9 bytes

```
`í`²²²í`í

```

Try it online!

Outputs

```
''sseerreerreerr'sererer'sererer'sererer'sererer'sererer'sererer'sererer

```

which contains each char of `'sererer` 9 times.

I found this by accident while experimenting with Japt, and wanted to share this which IMO is much more interesting than a number literal polyglot and a solution that has three dummy bytes and simply prints something three times, even though those are also 9 bytes.

### How it works

```
`í`²²²í`í

`í`        Shoco-compressed string of "'sererer"
   ²       Repeat 2 times
    ²      Repeat 2 times
     ²     Repeat 2 times
      í    Interleave with ... into a string
       `í    Shoco-compressed string of "'sererer"

```

Japt uses shoco library for string compression, which excels at compressing sequences of lowercase letters. It's actually surprising that one byte can decompress into an 8-char string.
> 4 votes

# Answer
# , 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.
> 4 votes

# Answer
# 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

```
> 4 votes

# Answer
# 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.
> 4 votes

# Answer
# 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`.
> 4 votes

# Answer
# 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)
> 3 votes

# Answer
# stacked, 24 bytes

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

```

Try it online! Outputs `54` each of `p` `u` and `t`.
> 3 votes

# Answer
# 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.
> 3 votes

# Answer
# 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 nothing<sup>1</sup>, 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.

<sub><sup>1</sup> The stack is empty, so it swallows `0` characters.</sub>
> 3 votes

# Answer
## 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!
> 3 votes

# Answer
# C, 57 bytes

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

```

**Output**

```
^^-_-^-__

```

**Alternative Version, 56 bytes**

```
main(){printf("%1$d%1$d%1$d","({{pprrmmaainttff,,}})");}

```
> 3 votes

# Answer
# 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 (`+(([[]]))`).
> 3 votes

# Answer
# 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
> 3 votes

# Answer
# 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)

```
> 3 votes

# Answer
# 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!
> 3 votes

# Answer
# Dis, ~~21~~ ~~18~~ 15 bytes

```
{{{|{{{|{{{!!!|

```

Try it online!
> 3 votes

# 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

```
> 2 votes

# Answer
# 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 !
> 2 votes

# 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.
> 2 votes

# Answer
# Retina, 27 bytes

```

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

```

**Try it online**

The output is 150 bytes, containing 12 `a`, 12 `b`, and 126 newlines.
> 2 votes

# 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 `8`s print. `>>>;;00/`  ends the program
> 2 votes

# 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 `0`s, we can just print the ASCII value and character, because printing the value also prints a space. `555` ends the program.
> 2 votes

# 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.
> 2 votes

# Answer
# 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.
> 2 votes

# Answer
# 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)
```
> 2 votes

# Answer
# 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

```
> 2 votes

# Answer
# SQL Server, PostgreSQL, SQLite, 27 bytes

```
SELECT  111222333 SSELLCCTT

```

**Oracle SQL, MySQL, 46 bytes**

```
SELECT  111222333 SSELCCTTFFRROOMMDDUUAAL  FROM DUAL

```

**Output**

```
111222333

```
> 2 votes

# Answer
## 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.
> 2 votes

# Answer
# Carrot, 21 bytes

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

```

Outputs:

```
aaaaaaaaabbbaaaaaaaaabbbaaaaaaaaabbbcccaaaaaaaaabbbaaaaaaaaabbbaaaaaaaaabbbcccaaaaaaaaabbbaaaaaaaaabbbaaaaaaaaabbbccc

```

Which is a 117 byte long string containing 81 `a`s, 27 `b`s and 9 `c`s.

---

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

```
aaabbbccc

```
> 2 votes

# Answer
# Ly, 15 bytes

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

```

Try it online!
> 2 votes

# Answer
# Perl 5, 21 bytes

```
say"\\\"ssaayyxx33"x3

```

Try it online!
> 2 votes

# Answer
# Turing Machine, 180 bytes

```
name: z
init: init
accept: accept

init,_
a1,0,>
a1,_
a2,0,>
a2,_
b0,0,>
b0,_
b1,1,>
b1,_
b2,1,>
b2,_
c0,1,>
c0,_
c1,2,>
c1,_
c2,2,>
c2,_
accept,2,>

name,3
name,3,-
za0,3
za0,-,-

```

Note the trailing new line. You can paste the source code into here. The machine takes 3\*3=9 steps by simply going right and outputting `000111222` (the infinite blank symbols `_` to the left and right are not counted). The last two states are unused states to have the source code fulfill the requirements. The used alphabet is `_0123-`, which is also dividable by 3 :-)
> 2 votes

# Answer
# Stax, 9 bytes

```
..3.3**3*

```

Run and debug online!

The output may not be what one would expect. Hope this is more interesting. Still output the same string repeated thrice, though.

## Explanation

```
..3          Two character literal. ASCII: [46, 51]
   .3*       Two character literal, "3*"
      *      Interlace, [46, "3*", 51]
       3*    Repeat 3 times
             Implicit output

```
> 2 votes

# Answer
# Java 8, ~~153~~ ~~150~~ ~~144~~ ~~138~~ ~~135~~ ~~120~~ ~~117~~ 111 bytes

```
class Sbccddggmossuvvyy{public static void main(String... a){{};;System.out.print(",,,".replace(",", ",ab"));}}

```

-27 bytes thanks to *@ØrjanJohansen*.

Prints `,ab,ab,ab`.

Try it online.

Code used to verify the occurrences of the characters are multiplies of 3, which is a modified version of my answer for a different challenge.

**Explanation of the basic golfed program (72 bytes):**

Try it online.

```
interface M{                          // Class
  static void main(String[]a){        //  Mandatory main-method
    System.out.print(",ab,ab,ab");}}  //   Print ",ab,ab,ab"

```

**Things I (and *@ØrjanJohansen*) did to create multiples of 3:**

* Changed `interface` to `class` (and added `public`  before `static`).
* Changed class-name to `Sbccddggmossuvvyy`
* Changed `String[]a` to `String... a`
* Added unused no-op `{}`-block
* Added two no-op `;`
* Changed `",ab,ab,ab"` to `",,,".replace(",", ",ab")`
> 2 votes

# Answer
# Pyth, 9 bytes

```
GGG\L\L\L

```

Try it online!

Outputs:

```
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
L
L
L

```

(Note the trailing newline)

Explanation:

```
GGG\L\L\L - full program.
GGG       - output the entire alphabet 3 times, and a trailing newline
   \L\L\L - output L 3 times, and a trailing newline

```
> 2 votes

# Answer
# Pascal (FPC), 51 bytes

```
begin write('ABCABCABC')end.bbggin  wwrrtt(())dd..'

```

Try it online!

Boring one, please see below.

---

### Pascal (FPC), ~~78~~ ~~75~~ 72 bytes

```
var f:int32;begin for f:=22to 33do write(' (())..:;;==abbdggvvww')end.a'

```

Try it online!

Output:

```
 (())..:;;==abbdggvvww (())..:;;==abbdggvvww (())..:;;==abbdggvvww (())..:;;==abbdggvvww (())..:;;==abbdggvvww (())..:;;==abbdggvvww (())..:;;==abbdggvvww (())..:;;==abbdggvvww (())..:;;==abbdggvvww (())..:;;==abbdggvvww (())..:;;==abbdggvvww (())..:;;==abbdggvvww

```

(One string 12 times)

Based on 75-byte solution. I managed to remove 3 `'`s by placing 1 from the string after `end.`. After parsing `end.`, FPC parses 1 more token, then ignores the rest. `'` alone after `end.` causes an error due to not closing the sting literal with another `'`, so I used one `a` from the string as a dummy token.

---

### 75-byte solution:

Breakthrough solution

```
var f:int32;begin for f:=22to 33do write(' ''(())''..:;;==aabbdggvvww')end.

```

Try it online!

Output:

```
 '(())'..:;;==aabbdggvvww '(())'..:;;==aabbdggvvww '(())'..:;;==aabbdggvvww '(())'..:;;==aabbdggvvww '(())'..:;;==aabbdggvvww '(())'..:;;==aabbdggvvww '(())'..:;;==aabbdggvvww '(())'..:;;==aabbdggvvww '(())'..:;;==aabbdggvvww '(())'..:;;==aabbdggvvww '(())'..:;;==aabbdggvvww '(())'..:;;==aabbdggvvww

```

(One string 12 times)

---

### 78-byte solutions:

```
var f:word;begin for f:=2to 22do write(' ''(())''..:;;==aabbgginoorrtvvw')end.

```

Try it online!

Output:

```
 '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw '(())'..:;;==aabbgginoorrtvvw

```

(one string 21 times)

or

```
var f:byte;begin for f:=2to 22do write(' ''(())''..:;;==aabdeegginvvwwyy')end.

```

Try it online!

Output:

```
 '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy '(())'..:;;==aabdeegginvvwwyy

```

(one string 21 times)

or

```
var f:char;begin for f:='a'to'c'do write('  (())..:;;==bbcdgghhinrrtvvww')end.

```

Try it online!

Output:

```
  (())..:;;==bbcdgghhinrrtvvww  (())..:;;==bbcdgghhinrrtvvww  (())..:;;==bbcdgghhinrrtvvww

```

That `v` in `var` really starts to annoy me...
> 2 votes

# Answer
# Zsh, 18 bytes

```
<<<$_
<<<$_
<<<$_

```

Try it online!

Also valid: `$-` with default options, and sometimes `$$`.

# Zsh ~~36 33 30~~ 27 bytes

This solution produces an *acyclic* output:

```
echo {e,h,o}{,{}}  eho\\cc\

```

---

```
echo {e,h,o}{,{}}  eho\\cc\
     {e,h,o}{,{}}            # expands to e h o e{} h{} o{}
                   eho       # eho
                      \\c    # '\c' stops printing

```

The output contains 3 `e`, 3 `h`, 3 `o`, 3 `{`, 3 `{`, and 6 `<space>`.

~~Try it online! Try it online!~~ Try it online!

---

> Comments on 33 byte solution:

***-3** bytes by using ) as the end of the range (still divisible by 3)*

```
<<<${(F):-{F..)}{F..)}$-$-((::..}
   ${   :-                      }  # empty string fallback
          {F..)}                   # The range {F..)} has 30 elements...
          {F..)}{F..)}             # so {F..)}{{F..)} has 900 elements
                      $-$-((::..   # Leftover junk, added to each of the 900 elements
   ${(F)                        }  # Join by newlines
<<<                                # Print to stdout

```

If trailing newlines are allowed, then `<<<aabbccabc` is a **12 byte** solution.
> 2 votes

# Answer
# Google Sheets, 12

`+++111222333` outputs `111222333`.

## Tricks Used:

The leading `+` gets auto-corrected to an `=`.
> 2 votes

# Answer
# Knight, 9 bytes

```
O!O!O!000

```

Try it online!

Output: 3x 't', 3x 'r', 3x 'u', 3x 'e', 3x newline

```
true
true
true

```

Basically this abuses the fact that the result of `OUTPUT` is `NULL`, and `!` returns true.

Expanded (which also counts for the 333 rule:

```
OUTPUT(!OUTPUT(!OUTPUT(!000)))

```

Basically:

```
!000 -> true
OUTPUT true -> null
!null -> true
OUTPUT true -> null
!null -> true
OUTPUT true -> null

```

Note that `000` is just an overlong constant for `0`, and `!0` is also `true`.
> 2 votes

# Answer
# Vyxal, 9 bytes

```
+₇S₇S₇S++

```

This is not fully in the spirit of the challenge (because it repeats the output), but it the code itself doesn't repeat which is nice.

##### Mini-explanation:

```
₇S computes "128", so ₇S₇S₇S pushes three strings to the stack
+ is concat, so ++ at the end concats all three together, while the beginning one is ignored

```

Try it Online!
> 2 votes

# Answer
# Zsh, 12 bytes

```
yes yes yes
```

Attempt This Online!

Note the trailing space. Outputs `yes yes` with a newline, repeated infinitely, so all the characters arguably appear a multiple of 3 times.

---

More boring and definitely allowed:

## Zsh, 15 bytes

```
<<<AAA<<<BB<<<B
```

Attempt This Online!

Outputs with a trailing newline:

```
AAA
BB
B

```

And if we could have a trailing newline without needing it thrice, we could just have `<<<aaabbbccc`.
> 2 votes

# Answer
# Flipbit, 15 bytes

```
^...>^...>^...>

```

Try it online!

Outputs `0x01`x3, `0x03`x3, and `0x07`x3.
> 2 votes

# Answer
# 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`.
> 1 votes

# Answer
# , 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.
> 1 votes

# Answer
# SmileBASIC, 9 bytes

```
?12?21?21

```

Output:

```
12
21
21

```

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

# Answer
# VBA, 123 bytes

```
Sub Auto_Open()
god_fx = ("OK" + " X")
For rapid = 1 To 3
MsgBox god_fx, 3 + 1 = rapid, Mid("mk OK X", 3 + 1)
Next
End Sub

```

It's a sub, but when you paste it in an empty Excel workbook, it'll run when you open the workbook.

Displays a MsgBox with in it 3x the text "OK" and 3x an "X" (the close button looks like an 'X', right?!) It even does this 3 times in a row for good measure :)

There are only 5 line endings in here, but that's because the VBA IDE always appends an empty line, making it 6 again. And since VBA doesn't care about case, I didn't either :P
> 1 votes

# Answer
# tcl, 24

```
puts 12
puts 12
puts 12

```

In the code, there is an Enter at the bottom, which the site ate.

**Output:** the output consists of `12Enter12Enter12Enter`

demo
> 1 votes

# Answer
# Python 3, 87 bytes

```
AET=' TEE'
exec("""print('A TE');exec('print("A AT");exec("print(AET)")')""")
AET=="";

```

Try it online!

I wasn't going for the shortest solution - I just really, really wanted to abuse `exec`.

It can probably be made shorter, though I don't remember the last time I've had this much fun golfing python. Great challenge!
> 1 votes

# Answer
# Octave, 21 bytes

```
'ans==ans '%%%ans=  '
ans = ans==ans

```

Creates a string: `'ans==ans '`, that's automatically printed (since `;` is omitted), with `ans =`  in front of it.
> 1 votes

# Answer
## REXX, 21 bytes

```
say 10
say 10
say 10

```

Outputs three 10s and three newlines.

I can think of funnier output, but since this is code golf, this is what you get.
> 1 votes

# Answer
# 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)

```
> 1 votes

# Answer
# Aceto, 18+1=19 bytes

Requires the use of the command-line switch `-l`

```
"aaabbbccc"\p\p\"p

```

Prints, unsurprisingly, `aaabbbccc`.
> 1 votes

# Answer
# Attache, 24 bytes

```
Print!73Print!73Print!73

```

Try it online!

The output is (with a trailing newline):

```
73
73
73

```

For bonus "encouragement" points:

### Attache, 30 bytes

```
"PPrriinntt""""||**33"*3|Print

```

Try it online!

This is just:

```
"PPrriinntt""""||**33"*3|Print
"                    "            a string ("" is an escaped double quote)
                      *3          repeated 3 times
                        |Print    then print that string

```
> 1 votes

# Answer
# PHP, 27 bytes

```
<?=$s=";\<?=\",\<?;",$s,$s;

```

prints `;\<?=",\<?;` three times

```
<?=$s="\<<?=\",\>>",$s,$s?>

```

prints `\<<?=",\>>` three times

```
<?=$s=";<?,<?=;","$s","$s";

```

prints `;<?,<?=;` three times

---

Run with `-n` or try them online. TiO includes checks and two variants of a 30 byte solution.
> 1 votes

# Answer
# JsFuck, 1044 Bytes

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

```

Bad one
> 1 votes

# Answer
# APL (Dyalog Unicode), 9 bytes

```
,⎕A,⎕A,⎕A

```

This prints the alphabet, 3 times.

Try it online!

Also works for the digits `0-9`:

```
,⎕D,⎕D,⎕D

```

Try it online!
> 1 votes

# Answer
## Matlab, 12 bytes

```
1:3,1:3,1:3,

```

Try it Online!
> 1 votes

# Answer
# ink, 30 bytes

```
-(i)>:{(-3):{(3)}}

{3>i:->i}

```

Outputs

```
>:3
>:3
>:3

```

and a trailing newline. The output was actually mostly unintentional.

Try it online!

### Explanation

```
-(i)     Labelled gather - we can read how many times we've visited this part by looking at the variable i. We can also divert to here.
>:       Print the characters > and :
{(-3):   If negative 3 is nonzero...
{(3)}}    ...print the value of the number 3
         Having at least one linebreak makes ink print a newline.
         (we have three)
{3>i:    If we've passed (i) fewer than three times...
->i}      ...jump to (i)

```

# Boring alternative, 9 bytes

```
11
21

22

```

Outputs

```
11
21
22

```

and a trailing newline. As long as there are four lines, exactly three of which contain one or more characters, you can move and replace the characters (almost) however you want.

### Explanation

We just print non-space characters as we encounter them, and print a newline whenever we encounter some number of linebreaks (and/or the end of the program)

Try it online!

# No printing literal characters at all, 39 bytes

```
-(i){3:{-3}}{0:{(0)}}{0}<><>{(i<3):->i}

```

Outputs `-30-30-30` with no trailing newline. This is basically the opposite of how you're supposed to use ink.

Try it online!

### Explanation

```
-(i)      Labelled gather - we can read how many times we've visited this part by looking at the variable i. We can also divert to here.
{3:       If 3 is nonzero (it is)
{-3}}     Print -3
{0:       If 0 is nonzero (is isn't)
{(0)}}     ...print 0 (we won't)
{0}       Print 0 (we *will*)
<><>      This is glue. It suppresses newlines.
{(i<3):   If we've passed (i) fewer than 3 times...
->i}       ...divert to (i)

```
> 1 votes

# Answer
# Runic Enchantments, 9 bytes

```
aaa333@@@

```

Try it online!

### Explanation

Pushes 10 three times, pushes 3 three times, then prints and terminates. The extra two `@` serve no purpose beyond complying with challenge requirements. `"3*@"` would comply with output rules (and is the shortest program that can), but does not comply with source rules.
> 1 votes

# Answer
# Perl 5 \+ `-p`, 15 bytes

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

```

Try it online!
> 1 votes

# Answer
# naz, 12 bytes

```
3a3o3a3o3a3o

```

Outputs `333666999`.

This contains six `3`'s, three `a`'s, and three `o`'s.
> 1 votes

# Answer
# Pxem, 9 bytes (filename).

```
~~~.n.n.n

```

Output:

```
126126126

```

## How it works

* Three tildes are not commands; each of they are literals.
* Each literal means to push its own codepoint as an integer.
* `.n` pops one item and output it as a decimal integer (if any).

Try it online!
> 1 votes

# Answer
# BrainCrash, ~~21~~ 12 bytes

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

```

Try it online!

---

Previously:

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

```

Try it online!
> 1 votes

# Answer
# JSFuck (eh, plain JavaScript), 2820 bytes

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

```

Try it online!

Probably not the most optimal JavaScript solution (but I doubt anyone will try to optimize it).

Prints:

```
NaN0NaN0NaN0

```

The program contains:

* `(`: 159
* `)`: 159
* `!`: 339
* `+`: 651
* `[`: 756
* `]`: 756

Fun fact:

The program (as an expression) evaluates to `NaN`. (When executing as a full program, it is discarded, so it isn't part of the output.)
> 1 votes

# Answer
# 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.
> 0 votes

---
Tags: code-golf, restricted-source
---