title: Build me a brick wall!

text:
# Question
Title: Build me a brick wall!
## Challenge

I need help building a brick wall! Throw together some code for me using no input and produce the following output wall shown below:

```
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

Now, this wall is exactly `10` characters high and `70` characters wide.

As stated above, no inputs, only code. Least amount of bytes, we have to efficiently build this brick wall. Obviously, this program has to function to get the wall built..? or it obviously won't build itself! Good luck!

---

## Winner

The winner goes to **Marinus** using the `APL` language, requiring a whole `12` bytes! https://codegolf.stackexchange.com/a/99028/61857

---

Thank you everyone for participating!

# Answer
> 49 votes
# APL, 12 bytes

```
10 70⍴'_|__'

```

Output:

```
      10 70⍴'_|__'
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 193 votes
## Trumpscript, ~~303~~ ~~285~~ ~~244~~ ~~231~~ 226 bytes

```
make i 1000005-1000000
as long as,i;:
make i,i - fact;
say "_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|"
say "___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__"!
America is great

```

I would like to say this is one of the most verbose languages where almost everything fails to compile into a working program.

Apparently whether `-` works instead of `minus` is completely up to the interpreter and sometimes works. This time it did so I'm putting it in as golfed.

Abuses the fact Trumpscript is written in Python and therefore `fact` when used as an integer is one.

Golfing tips welcome.

# Answer
> 21 votes
# J, 12 bytes

```
10 70$'_|__'

```

Shapes the string on the right into a 10 by 70 shape. Simple!

# Answer
> 18 votes
# BBC BASIC, 28 bytes

Tokenised filesize 23 bytes.

```
WIDTH70P.STRING$(175,"_|__")

```

`WIDTH70` would normally be followed by a newline. It sets the field width to 70. Then we just print 175 copies of the string, which wrap around.

# Answer
> 17 votes
# Brainfuck, 171 bytes

```
+++++[>+++++++++++++++++++<-]+++++++[>>++++++++++++++++++<<-]>>--<<++[>>>+++++<<<-]+++++[>.>.>>+++++++++++++++++[<<<...>.>>-]<.>+++++++++++++++++[<<<...>.>>-]<<<..>>.<<<-]

```

Brainfuck is fun, here is my submission.

Here is the output:

```
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

Here is a link to try it

https://repl.it/EW2Z/0

# Answer
> 16 votes
# WinDbg, 45 bytes

```
f2000000 L2bc 5f 7c 5f 5f;da/c46 2000000 L2bc

```

How it works:

```
f 2000000 L2bc 5f 7c 5f 5f; *Repeat the pattern _|__ (5F 7C 5F 5F) to fill 2BC (700) bytes
                            *starting at 2000000
da /c46 2000000 L2bc        *Show 2BC (700) ASCII chars starting from 2000000 in lines
                            *of length 0x46 (70)

```

Output:

```
0:000> f2000000 L2bc 5f 7c 5f 5f;da/c46 2000000 L2bc
Filled 0x2bc bytes
02000000  "_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|"
02000046  "___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__"
0200008c  "_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|"
020000d2  "___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__"
02000118  "_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|"
0200015e  "___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__"
020001a4  "_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|"
020001ea  "___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__"
02000230  "_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|"
02000276  "___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__"

```

# Answer
> 10 votes
# Pyth, 12 bytes

Code:

```
jcT*175"_|__

```

Explanation:

```
       "_|__    # For the string "_|__"
   *175         # Repeat it 175 times
 cT             # Chop into 10 equal pieces
j               # Join them by newlines

```

Try it here.

# Answer
> 10 votes
## Python 2, 37 bytes

```
s="_|__"*17;print(s+"_|\n__%s\n"%s)*5

```

Decomposes two rows as 17 copies of `_|__`, plus another copy interrupted by a newline, plus 17 more copies, plus another newline.

Longer alternatives:

```
print"%s_|\n__%s\n"%(2*("_|__"*17,))*5

s="_|__"*17;print"%s_|\n__%%s\n"%s%s*5

for i in[0,2]*5:print("_|__"*18)[i:i+70]

print("_|__"*17+"_|\n"+"___|"*17+"__\n")*5

for s in["_|__","___|"]*5:print(s*18)[:70]

s="_|__"*99;exec"print s[:70];s=s[2:];"*10

print("%s"*70+"\n")*10%(175*tuple("_|__"))

```

# Answer
> 8 votes
# 05AB1E, 13 bytes

Code:

```
"_|__"175×Tä»

```

Explanation:

```
"_|__"         # For the string "_|__"
      175×     # Repeat that 175 times
          Tä   # Split into 10 even pieces
            »  # And join them by newlines

```

Uses the **CP-1252** encoding. Try it online!

# Answer
> 7 votes
# PHP, ~~44~~ ~~42~~ 41 characters

```
<?=chunk_split(str_pad(_,700,"|___"),70);

```

(Just because had no chance to use `chunk_split()` ever before.)

Thanks to:

* user59178 for suggesting to use `str_pad()` (-1 character)

Sample run:

```
bash-4.3$ php <<< '<?=chunk_split(str_pad(_,700,"|___"),70);'
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 7 votes
## Vim, ~~30~~ ~~24~~ 19 keystrokes

```
18a___|<esc>YP2x}h.yk4P

```

Thanks to DrMcMoylex and nmjcman101 for saving valuable keystrokes!

# Answer
> 6 votes
# Perl, ~~47~~ ~~34~~ 29 bytes

```
$_="_|__"x175;say for/.{70}/g

```

# Answer
> 5 votes
# , ~~24~~, 16 bytes

```
175i_|__ò70|lé

```

Try it online! This contains `<esc>` characters (`0x1B`) so here is a hexdump:

```
0000000: 3137 3569 5f7c 5f5f 1bf2 3730 7c6c e90a  175i_|__..70|l..

```

8 bytes indirectly saved thanks to Jordan!

# Answer
> 5 votes
## Perl, 31 bytes

```
say+($@="_|__"x17,"_|
__$@
")x5

```

You'll need `-E` flag to run it :

```
perl -E 'say+($@="_|__"x17,"_|
__$@
")x5'

```

# Answer
> 5 votes
# Python 2, ~~46~~ 44 Bytes

Just using string multiplication to build the string, and slicing to get the right bits :)

```
k='_|__'*18
print'\n'.join([k[:70],k[2:]]*5)

```

<sup>*thanks to Antony Hatchkins for saving two bytes :)*</sup>

# Answer
> 5 votes
# , 18 bytes

-1 byte thanks to DJMcMayhem.

```
175i_|__<Esc>Ó.û70}/°ò

```

Here it is with unprintable characters in xxd format:

```
0000000: 3137 3569 5f7c 5f5f 1bd3 2efb 3730 7d2f  175i_|__....70}/
0000010: b0f2                                     ..

```

Try it online!

# Answer
> 5 votes
# MATL, 15 bytes

```
'_|__'700:)70e!

```

Of course, you can Try it online! Explanation:

```
'_|__' % Put a brick on the stack
700    % 700 times
:)     % Makes a happy mason...
70e!   % Secret freemason code

```

OK, actually, it works as follows:

```
'_|__' % Put the first bit of the string on the stack
700:   % Put 1, 2, ..., 700 on the stack as array
)      % Index into the string, modularly. Result: '_|___|__ ... __'
70e    % Reshape into 70 rows (and consequently, 10 columns)
!      % Transpose to get the desired output.

```

# Answer
> 4 votes
# Jelly, 14 bytes

```
“_|__”ṁ700s70Y

```

**TryItOnline!**

### How?

```
“_|__”ṁ700s70Y - Main link: no arguments
“_|__”         - literal ['_','|','_','_']
      ṁ700     - mould like something 700 long
          s70  - split into chunks of length 70
             Y - join with line feeds

```

# Answer
> 4 votes
## PowerShell v2+, ~~34~~ 30 bytes

```
'_|__'*175-split"(.{70})"-ne''

```

Stupid regex matching algorithm requiring the `-ne''` ... wastes five bytes!

```
'_|__'*175-split"(.{70})"-ne''
'_|__'*175                     # Repeat this string 175 times
          -split"       "      # Split on this regex pattern:
                  .{70}        # Match any character 70 times
                 (     )       # Encapsulated in parens so we keep the regex results
                         -ne'' # But don't select the empty strings
                               # Output with newlines via Write-Output is implicit

```

*Saved 4 bytes thanks to Conor!*

# Answer
> 4 votes
# C, ~~131~~ ~~115~~ ~~113~~ ~~103~~ ~~97~~ 95 Bytes

```
i,j;main(){for(;i<10;puts(i++&1?"|__":"|"))for(j=0;j<18-(i&1);printf(&"|___"[j++?0:i&1?1:3]));}

```

Time to start golfing this...

```
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 3 votes
# MATL, 16 bytes

```
'___|'10:E!70:+)

```

Try it online!

```
'___|'   % Push this string
10:E!    % Push [2; 4; 6; ...; 20] (10×1 column vector)
70:      % Push [1, 2, 3, ..., 70] (1×70 row vector)
+        % Add. Gives a 10×70 matrix of all pairwise additions
)        % Index (modular, 1-based) into the string

```

# Answer
> 3 votes
# CJam, 15 bytes

```
"_|__"175*70/N*

```

Try it online!

Port of Adnan's 05AB1E answer.

```
"_|__"             e# Push this string
      175*         e# Repeat 175 times
          70/      e# Split in pieces of size 70
             N*    e# Join by newlines

```

# Answer
> 3 votes
**Javascript REPL, 45 bytes**

```
"_|__".repeat(175).match(/.{70}/g).join("\n")

```

# Answer
> 3 votes
# JavaScript (ES6), 48 bytes

```
f=(n=350)=>n?(n%35?'_':`
_`)+"|_"[n%2]+f(n-1):""

```

Because recursion.

# Answer
> 3 votes
# Bash, 44, 41, 40 bytes

```
printf _\|__%.0s {1..175}|egrep -o .{70}

```

The printf makes a single line 700 characters long, the egrep matches it 70 characters at a time.

# Answer
> 3 votes
# ///, 43 bytes

```
/a/___|//b/aaccccc//c/aaa//d/_|b
b__
/ddddd

```

Try it online!

# Answer
> 2 votes
# Befunge-98, 63 bytes

```
'_\:3+4%0`!> #0 #\ #|' $ #\_\,1+:7a*%0`!> #0 #, #a_:7aa**\`!#@_

```

TryItOnline!

# Answer
> 2 votes
# Ruby, 30 bytes

Thanks to manatwork for this solution

```
puts ("_|__"*175).scan /.{70}/

```

# Ruby, 39 bytes

```
10.times{|i|puts ("_|__"*18)[i%2*2,70]}

```

# Answer
> 2 votes
# ///, 51 bytes

If a trailing newline is allowed:

```
/e/aaaa//a/_|__//b/eeeea_|//c/__eeeea//d/b
c
/ddddd

```

Try it online!

# Answer
> 2 votes
## Pyke, 12 bytes

```
w�"_|__"*TfX

```

where  is the literal byte 163.

Try it here! (`w�` replaced with literal)

# Answer
> 2 votes
# Retina, ~~23~~ ~~21~~ 20 bytes

```

175$*_

_|_
!`.{70}

```

**Try it online**

# Answer
> 2 votes
# Haskell, ~~56~~ 47 bytes

```
unlines$[1..5]>>take 70.cycle<$>["_|__","___|"]

```

# Answer
> 2 votes
# R, 78 bytes

```
    strwrap(gsub('(.{70})','\\1 ',paste(rep('___|',175),collapse='')),70)

```

How?

```
    x=paste(rep('___|',175),collapse='')   #Creates string on 1 line
    y=gsub('(.{70})','\\1 ',x)             #Adds spaces every 70 characters
    z=strwrap(y,70)                        #Creates a new line every space
    z                                      #Print the finished product

```

# Answer
> 2 votes
# C, 61 bytes

TCC Version

```
main(i){for(;i+699;)printf("\n%c"+(--i%70||!i),"___|"[i&3]);}

```

GCC Version

```
main(i){for(;i+699;)printf("\n%c"+(i%70||!i),"___|"[--i&3]);}

```

# Answer
> 2 votes
# Befunge-93, 42 bytes

```
:4%1g,1+:"F"%!#v_0#@_
_|__~>:+#5,#:4#<1g*`^

```

Try it online!

# Answer
> 2 votes
# bash 36 Byte

```
printf '_|__%.0s' {1..175}|fold -w70

```

OUtput:

```
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 2 votes
# Python 3, 40 bytes

```
p="_|__"*17
print((p+"_|\n__"+p+"\n")*5)

```

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

```
_=>`_|__`.repeat(175).match(/.{70}/g).join`
`

```

Try it online!

# Explanation :

```
_ =>                    // lambda function (argument passed to save a byte)
    `_|__`              // simple enough
    .repeat(175)        // repeat the above mentioned shape 175 times
    .match(/.{70}/g)    // simple regexp to match a shape 70 (something :) ) long
    .join`\n`           // and join them on a new line

```

---

Simple enough.

# Alternate version :

# JavaScript (Node.js), 714 bytes

```
_=>`_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__`

```

Try it online!

No explanation required. Simple hard coded.

# Answer
> 2 votes
# Jelly, 13 bytes

```
70:þ⁵“_|__”ṁY

```

Try it online!

The dyad given to `þ` doesn't matter so long as it outputs a scalar, so I chose `:` solely for aesthetic purposes.

```
   þ             Take the rangifying outer product
  :              by integer division
70               of 70
    ⁵            and 10,
     “_|__”ṁ     mold "_|__" like it,
            Y    and join on newlines.

```

# Answer
> 2 votes
# 05AB1E, 11 bytes

```
…_|_ĆƵм×Tä»

```

Try it online!

```
         ä   # split...
…            # three char string...
 _|_         # literal...
    Ć        # concatenated with its first character...
       ×     # repeated...
      м      # numeric literal...
     Ƶ       # converted from base 255 to decimal plus 101...
       ×     # times...
         ä   # into...
        T    # 10...
         ä   # equal pieces...
          »  # by newlines
             # implicit output

```

# Answer
> 1 votes
# Python 2, ~~50~~ 48 bytes

```
for b in range(10):print('_|__'*175)[b*70:][:70]

```

2 saved with thanks to @xnor but also thanks to @Shebang for the suggestion :)

# Answer
> 1 votes
# C#, 106 102 101 118 107 106 100 96 bytes

Thanks shebang for saving 2 bytes and pointing out a mistake, Yodle for saving 6 bytes and Link Ng for saving 4 bytes.

```
var a="";int i;for(;i++<175;)a+="_|__";for(i=0;i<10;)Console.Write(a.Substring(i++*10,70)+"\n");

```

You can test it directly on http://csharppad.com/.

# Answer
> 1 votes
# Jolf, 17 bytes

```
RZc*"_|__"Τ755@FS

```

Try it here!

## Explanation

```
RZc*"_|__"Τ755@FS
   *"_|__"         repeat this string:
          Τ755      7*5*5 = 175 times
 Zc           @F   chop into groups of 70 (F's charcode)
R               S  join by newlines

```

# Answer
> 1 votes
# SOML, 16 bytes

```
_|__”’ø*L{:jjp»»

```

explanation:

```
_|__”             push "_|__"
     ’ø           push 18
       *          repeat the "_|__" 18 times
        L{        repeat 10 times:
          :       duplicate the sting
           jj     pop the last 2 letters off
             p    output it
              »»  put the last 2 characters at the start

```

# Answer
> 1 votes
# Pyth, ~~24~~ ~~23~~ 22 bytes

```
VT:*175"_|__"J*70N+70J

```

OK, I'm still learning. Any hints gratefully received :)

**Edit**

Saved a byte by moving the assignment of J to first use

# Answer
> 1 votes
# Java 8 + Guava, ~~81~~ 106 bytes

25 bytes for import: `com.google.common.base.*;`

Lambda that takes no input and returns the required wall.

```
()->String.join("\n",Splitter.fixedLength(70).split(Strings.repeat("_|__",175)));

```

Same as many other solutions. Takes a repeating string of "\_|\__" 175 times, splits it into lengths of 70, then joins them on newline.

# Answer
> 1 votes
## GolfSharp, 38 bytes

```
c(r(175).s(n=>"_|__").j().S(70).j(N));

```

# Answer
> 1 votes
# PHP, 46 bytes

```
<?=wordwrap(str_repeat('_|__',175),70,"\n",1);

```

**Output:**

```
C:\PHP>php build-me-a-brick-wall.php
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 1 votes
## Racket 159 bytes

```
(let p((n 2)(x 0)(t 0)(d display))(when(> x 69)(d"\n")(set! x 0))(cond[(> t 699)
(d"\n")][(> n 2)(d"|")(p 0(+ 1 x)(+ 1 t)d)][(d"_")(p(+ 1 n)(+ 1 x)(+ 1 t)d)]))

```

Ungolfed:

```
(define (f)
  (let loop ((n 2)   (x 0)   (t 0)  (d display))

    (when (> x 69)  (d "\n")
                    (set! x 0))
    (cond
      [(> t 699)    (d "\n")]

      [(> n 2)      (d "|")
                    (loop    0    (+ 1 x) (+ 1 t) d)]

      [else         (d "_")
                    (loop (+ 1 n) (+ 1 x) (+ 1 t) d)]
      )))

```

Testing:

```
(f)

```

Output:

```
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 1 votes
# Ruby, ~~89~~ ~~80~~ ~~77~~ ~~76~~ ~~72~~ ~~53~~ ~~47~~ 42 Bytes

```
puts (%w[___]*176*?|)[2..-1].scan(/.{70}/)

```

Demo:

```
>> puts (%w[___]*176*?|)[2..-1].scan(/.{70}/)
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

Update: I didn’t see there’s already an answer with 30 bytes.

# Answer
> 1 votes
## Java 8, 128

This code directly calculates each character and has no imports or dependencies.

Golfed:

```
()->{String s="";for(int x,y=0;y<10;++y){for(x=0;x<70;++x)s+=((y%2<1&(x+3)%4<1)|(y%2>0&(x+1)%4<1))?"|":"_";s+="\n";}return s;}

```

Ungolfed:

```
() -> {
  String s = "";
  for (int x, y = 0; y < 10; ++y) {
    for (x = 0; x < 70; ++x)
      s += ((y % 2 < 1 & (x + 3) % 4 < 1) | (y % 2 > 0 & (x + 1) % 4 < 1)) ? "|" : "_";
    s += "\n";
  }
  return s;
}

```

# Answer
> 1 votes
# Swift 3, 69 bytes

```
(3...702).map{print($0%4<1 ?"|":"_",terminator:($0-2)%70<1 ?"\n":"")}

```

Output after compiling and running:

```
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

Try online here (In this tool it run as script so it will produce a warning due the `map` result is unused.

# Answer
> 1 votes
## Clojure, ~~117~~ 110 bytes

```
(fn[](println(apply str(map #(str(apply str %)"\n")(partition 70(subs(apply str(repeat 175 "_|__"))0 700))))))

```

Basically creates a long string of `"_|__"`s 700 characters long, cuts it every 70 characters, then joins them with newline.

Managed to get rid of the calls to `join`!

Ungolfed:

```
(defn build-wall []
  (println
    (apply str
      (map #(str (apply str %) "\n")
        (partition 70
          (subs (apply str
                  (repeat 175 "_|__"))
                0 700))))))

```

# Answer
> 1 votes
## Python 3, 43

```
print(("_|__"*17+"_|\n"+"__|_"*17+"_\n")*5)

```

Fixed to be more Trump-like.

# Answer
> 1 votes
## SAS, 68

```
option linesize=70;data;length w$700;w=repeat('_|__',174);put w;run;

```

The 174 is not a typo - in SAS the repeat function rather pedantically returns the original string plus `n` repeats.

# Answer
> 1 votes
# Kotlin, 99 bytes

```
fun main(a:Array<String>){"_|__".repeat(999).split(Regex("(?<=\\G.{70})")).take(10).map(::println)}

```

Regex taken from here. First ever golf, done in 10 minutes, probably improvable..

# Answer
> 1 votes
# Lua, 54 bytes

```
w=("_|__"):rep(17)print((w.."_|\n__"..w.."\n"):rep(5))

```

No fancy splits for Lua, but it does have an easy repeat.

# Answer
> 1 votes
# Python 2, 46 bytes

```
import textwrap as t;print t.fill('_|__'*175)

```

I was going to do an exec loop similar to @xnor's one alternate solution but he/she got to it before me. I guess I'll just have to let Python do the dirty work for me.

# Answer
> 1 votes
# R, 62 bytes

Don't have the rep to comment, so posting as an answer: @user3297046's answer can be golfed-down to 62 bytes:

```
cat(gsub('(.{70})','\\1
',paste(rep('_|__',175),collapse='')))

```

which results in

```
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 1 votes
## PHP, 56 bytes

Although I know it can be done smaller using wordwrap or string splits, I prefer more hacky solutions.

```
for($i=0;$i<700;$i++){echo($i%70?'':'
').'_|___'[$i%4];}

```

# Answer
> 1 votes
# C (gcc), ~~61~~ 58 bytes

-3 bytes thanks to ceilingcat.

```
f(i){for(i=700;i--;i%70|!i||puts(""))printf(L"__|_"+i%4);}

```

Try it online!

# Answer
> 1 votes
# Symbolic Python, 69 bytes

Outputs as a list of lines.

```
_=-~(_==_)
__=-~_*-~_*_
_=[('_|__'*__)[:-_],('___|'*__)[:-_]]*-~(_*_)

```

**Try it online!**

Alternatively, for 16 more bytes, we can print the wall:

```
_=-~(_==_)
__=-~_*-~_*_
_=(('_|__'*__)[:-_]+"""
"""+('___|'*__)[:-_]+"""
""")*-~(_*_)

```

**Try it online!**

# Answer
> 1 votes
# Prolog (SWI), 83 bytes

```
?-between(0,699,I),(1 is I mod 4->write("|");write("_")),69 is I mod 70,nl,1=0;1=1.

```

Try it online!

# Answer
> 1 votes
# Tcl, ~~84~~ ~~78~~ ~~77~~ 76 bytes

```
time {append a [expr [incr i]%4-2?"_":"|"];if $i%70<1 {puts $a;unset a}} 700

```

Try it online!

# Answer
> 1 votes
# Common Lisp, 70 bytes

```
(dotimes(i 700)(format t"~[|~:;_~]~[
~:;~]"(mod(1- i)4)(mod(1+ i)70)))

```

Try it online!

# Answer
> 1 votes
# Canvas, 10 bytes

```
B?³‟‾Ｈ×‾7ｎ

```

Try it here!

# Canvas, 10 bytes

```
αｎｑ［‟５＊‾7ｍ

```

Try it here!

# Answer
> 1 votes
# Vyxal `j`, 10 bytes

```
‛_|ǏǏ⁺J*₀/

```

Try it Online!

## How?

```
‛_|ǏǏ⁺J*₀/
‛_|         # Push string "_|"
   ǏǏ       # Append its first character twice, yielding "_|__"
     ⁺J*    # Repeat it 175 times
        ₀/  # Split into ten equal parts

```

# Answer
> 0 votes
# Perl, 37 bytes

```
print$_.$/x!(++$i%35)for('_|',__)x175

```

Ungolfed:

```
my $i = 0;
print($_, "\n" x !(++$i % 35)) for ('_|', '__') x 175;

```

# Answer
> 0 votes
## Lithp, 72 bytes

```
#::((print (replace (repeat "_|__" 175) (regex "(.{70})" "g") "$1\n"))))

```

Sample usage:

```
% wall.lithp
(
    (def x #::((print (replace (repeat "_|__" 175) (regex "(.{70})" "g") "$1\n"))))
    (x)
)

```

Output:

```
$ ./run.js wall.lithp
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 0 votes
## Batch, 90 bytes

```
@set s=_________________
@for /l %%i in (1,1,5)do @echo _^|%s:_=___^|%&echo __%s:_=_^|__%

```

`|`s cause problems if I want to use them as contents of the variable so it's easiest to stick with them as replace strings.

# Answer
> 0 votes
# BASH, ~~91~~,34 bytes

```
printf _\|__%.0s {1..175}|fold -70

```

# Answer
> 0 votes
# Java 7, ~~136~~ ~~124~~ ~~120~~ 115 bytes

```
String c(){String r,x=r="";int i=999,q=0;for(;i-->0;x+="_|__");for(;i++<10;r+=x.substring(q,q+=70)+"\n");return r;}

```

**Ungolfed & test code:**

Try it here.

```
class M{
  static String c(){
    String r,
           x = r = "";
    int i = 999,
        q = 0;
    for(; i-- > 0; x += "___|");
    for(; i++ < 10; r+= x.substring(q, q+=70) + "\n");
    return r;
  }

  public static void main(String[] a){
    System.out.println(c());
  }
}

```

**Output:**

```
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 0 votes
## Ruby, 30 bytes

```
puts ('_|__'*175).scan /.{70}/

```

Output:

```
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 0 votes
## Vim, ~~26~~ 22 strokes

Assume the `q` register to be empty (if not type `qqq`)

```
175i_|__<esc>0qq70li<enter><esc>q8@q

```

# Answer
> 0 votes
# Java 8, ~~101~~ 119 bytes

18 for the import: `java.util.stream.*;`

Lambda that returns the wall. We generate an infinite Stream of brick pieces ('\_|\__'), limit it to 175, and collect them into a string. We then use replaceAll to swap in a newline every 70 characters.

```
()->Stream.generate(()->"_|__").limit(175).collect(Collectors.joining()).replaceAll("(.{70})","$1\n")

```

# Answer
> 0 votes
# Gema, 45 characters

```
\A=@subst{<U70>=\$1\\n;@repeat{175;_|__}}@end

```

Sample run:

```
bash-4.3$ gema '\A=@subst{<U70>=\$1\\n;@repeat{175;_|__}}@end'
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 0 votes
## Javascript, 232 bytes

```
brick = ["_","_","_","|"];
brickIndex = 2;
output = "";
for(var y=0;y<10;y++){
    for(var x=0;x<70;x++){
      brickIndex = brickIndex % 4;
      output += brick[brickIndex++];
    }
    output += "\n";
}
console.log(output)

```

# Answer
> 0 votes
# jq, 37 characters

(33 characters code + 4 characters command line options)

```
range(10)|.*2|("_|__"*70)[.:.+70]

```

```
range(10)|("_|__"*70)[.*2:.*2+70]

```

```
range(0;20;2)|("_|__"*70)[.:.+70]

```

Sample run:

```
bash-4.3$ jq -nr 'range(10)|.*2|("_|__"*70)[.:.+70]'
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

On-line test code 1, code 2 and code 3 (Passing `-r` through URL is not supported – check Raw Output yourself.)

# Answer
> 0 votes
# sh (via base64 and pigz) 59 bytes

```
echo eNqLr4mPpxxzgQjKMRc5mkZdM+oaAG7xGAs=|base64 -D|pigz -d

```

# Answer
> 0 votes
# FurryScript, 71 bytes

```
A[ <_|> 17 REP +<___|> +BR +<__> 17 REP +<_|__> +BR ]
<<A><A><A><A><A>>

```

**Explanation:**

```
A[ ... ]            {{ Subroutine called A }}
<_|>                {{ Push string "_|" }}
17 REP              {{ Repeat next command 17 times: }}
+<___|>             {{ Concatenate "___|" }}
+BR                 {{ Concatenate newline }}
+<__>               {{ Concatenate "__" }}
17 REP              {{ Repeat next command 17 times: }}
+<_|__>             {{ Concatenate "_|__" }}
+BR                 {{ Concatenate newline }}
<<A><A><A><A><A>>   {{ Template; result of A, 5 times }}

```

# Answer
> 0 votes
# bash, 35 bytes

```
printf '\e[8;;70t_|__%.0s' {1..175}

```

Must be run in graphical terminal as it sets the size of the window.

# Answer
> 0 votes
# Python 3.5.2, 44 bytes

`exec("print('_|__'*18);print('___|'*18);"*5)`

This is my first attempted golf, so feel free to leave a suggestion!

Try it here

# Answer
> 0 votes
# MySQL, ~~196~~ ~~123~~ ~~118~~ 95 bytes

First wall was backwards, removed procedure.

```
set @x:=repeat('_|__',99);select left(repeat(concat(left(@x,70),'\n',mid(@x,3,70),'\n'),9),709)

```

# Answer
> 0 votes
# Python 3 - 41 chars

```
s="_|__"*17
print((s+"_|\n__"+s+"\n")*5)

```

# Answer
> 0 votes
# Python 3, 54 bytes

```
for i in range(10):print(('_|__'*175)[70*i:70*(i+1)])

```

I know this is longer than other Python 3 solutions, so I post because it is a different approach.

# Answer
> 0 votes
# Pushy, 21 bytes

```
`_|__`17:4d;T:vv"^^{{

```

Really wish I could golf it more, will have another go later. It works like so:

```
`_|__`                  % Push the brick string to the stack
      17:4d;            % Copy 17 times
            T:          % 10 times do:
              vv"^^     %   Print without the last two characters
                   {{   %   Shift the string left twice

```

Seeing as there's no online interpreter as of yet, here's what it looks like:

```
$ pushy brickwall.pshy

_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__
_|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|__

```

# Answer
> 0 votes
# SOGL V0.12, 10 bytes

```
Ωo³‘'╥*'4n

```

Try it Here!

Explanation:

```
Ωo³‘        push "_|__"
    '╥*     multiply the string 175 times
       '4n  split into lines of length 70

```

# Answer
> 0 votes
# Japt `-R`, 15 bytes

```
AÆ70î"_|__"éX*2

```

Try it online!

### Unpacked & How it works

```
Ao@70î"_|__"éX*2

Ao@      range(10).map(X=>...)
70î        Repeat the following string to length 70...
"_|__"éX*2   This string rotated X*2 chars to the right.
         `-R` joins the resulting array with newline
         Implicit output

```

# Answer
> 0 votes
# Brainfuck, 141 bytes

```
+++++[>+++++[>>++++>+++++<<<-]>++>-<<<-]>>>>->+++++[<<.>.>>++++++++[>++>++<<-]>+>+<[<<<<...>.>>>-]<<<<<.>>>>>>[<<<<<...>.>>>>-]<<<<<..<.>>>-]

```

Try it online !

My first brainfuck answer !

There is a more aerial and commented version :

```
+++++[>+++++[>>++++>+++++<<<-]>++>-<<<-]>>>>->  value storage
+++++[                                          doing this ↓ 5 times
  <<.>.>                                        first "_|"
  >++++++++[>++>++<<-]>+>+<                     storing 17 two times
    [<<<<...>.>>>-]                             first 17 "|___" batch
    <<<<<.>>>>>>                                new line
    [<<<<<...>.>>>>-]                           second 17 "|___" batch
  <<<<<..<.>>>-                                 last "__" and new line
]

```

# Answer
> 0 votes
# Charm, 87 bytes

```
f := " ___| " 18 repeat
s := substring pstring newline
[ f 2 72 s f 0 70 s ] 5 repeat i

```

Try it online!

Charm's `repeat` makes this kind of thing easy, but its syntax prevents very good scores regardless.

Explanation:

```
f := " ___| " 18 repeat " function to push 18 bricks " pop
s := substring pstring newline " we need to get a substring before printing it with a newline at two different points during the program, so we save bytes defining a function for it " pop
[ f 2 72 s f 0 70 s ] 5 repeat i " now we apply our functions, getting two slightly different substrings of the bricks from the f function and printing them, repeating this 5 times "

```

# Answer
> 0 votes
# Charcoal, 11 bytes

```
⪪×¹⁷⁵_|__⁷⁰

```

Try it online!

---
Tags: code-golf, string, ascii-art, kolmogorov-complexity
---


title: Whyte Notation Translator

text:
# Question
Title: Whyte Notation Translator
Whyte Notation is a classification method mainly for steam locomotive, that classifies by wheel arrangement. On a steam locomotive ( we're only focusing on non articulated locomotives here ), the wheels are generally disposed like this : you have a specific number of leading wheels, then a specific number of driver wheels, and then a specific number of trailing wheels. On the top of that, each different wheel arrangement has its own name.

For example, look at this machine :

It has 2 leading wheels ( 1 on each sides ), 8 driving wheels ( 4 on each sides ) and 2 trailing wheels ( 1 on each sides )

Its Whyte Notation would be 2-8-2, and its name associated with it is "Mikado". Based on the Whyte Notation, we can create a visual arrangement that can be represented by a string, with the `o` character as a small wheel ( leading wheel if in front of the driver wheels, else trailing ), and a caps `O` for the driver wheels

Taking the previous locomotive as an example, its visual arrangement would be this : `oOOOOo`, with one small `o` on the front ( the leading wheels ), 4 caps `O` in the middle ( the driving wheels ), and one small `o` at the end ( the trailing wheels )

Here is the conversion table that we'll use to base the code on ( the table of entries that will have to be supported by your code ) :

```
    Input    |   Output
-------------+----------
oO           | Planet
oOo          | Jenny Lind
oOO          | Porter
oOOo         | Columbian
ooO          | Jervis
ooOoo        | Huntington
oooO         | Cramton
OO           | Four-coupled
OOo          | Olomana
OOoo         | Forney
ooOO         | American
ooOOo        | Atlantic
ooOOoo       | Jubilee
oOOO         | Mogul
oOOOo        | Prairie
oOOOoo       | Adriatic
ooOOO        | Ten-wheeler
ooOOOo       | Pacific
ooOOOoo      | Hudson
OOOO         | Eight-coupled
oOOOO        | Consolidation
oOOOOo       | Mikado
oOOOOoo      | Berkshire
ooOOOO       | Mastodon
ooOOOOo      | Mountain
ooOOOOoo     | Northern
oooOOOOooo   | Turbine
OOOOO        | Ten-coupled
OOOOOo       | Union
oOOOOO       | Decapod
ooOOOOO      | El Gobernador
ooOOOOOo     | Overland
oOOOOOo      | Santa Fe
oOOOOOOoo    | Texas
ooOOOOOOo    | Union Pacific
ooOOOOOOOoo  | AA20

```

## Your task

Your task is to write 2 programs of functions.

### First program / function : from arrangement to name

The first function / program will be taking as input a string that exists in the table given previously, and will output the associated name ( for example, `oOOOOo` will return "Mikado" ).

For the input, the only inputs you have to support are the one in the table previously given. Anything else that isn't in the table leads to undefined behavior.

For the output, the string has to be the exact name, with the exception of case, which can be whatever you want. Trailing spaces are fine too.

Examples of acceptable output : `Mikado`, `mikado`, `MIKADO` , `mIkAdO`, `Ten-wheeler`

Examples of not acceptable output : `Mi Ka Do`,  `Mikado`, `Tenwheeler`, `Ten_wheeler`, `Ten wheeler`

### Second program / function : the opposite

This program of function will do the opposite of the first program, meaning that when given a name, it will print / return / output the string representing the wheel arrangement of the locomotive.

As input, it will take whatever name existing in the "Output" part of the previously given table. Shall the name not exist, it leads to undefined behavior

As output, it will give the exact string that represents the wheel arrangement, no flexibility allowed. So for example, `Mikado` as input must return `oOOOOo`.

## Global constraints

Both of the programs have to be able to take as input the other program's output, and `func2(func1(wheel_arrangement_string))` has to be equal to `wheel_arrangement_string`. Same goes the other way, with `func1(funct2(wheel_arrangement_name))` that has to be equal to `wheel_arrangement_name`.

Aside from that, standard I/O rules apply, and default loopholes are forbidden

## Additionnal Rules

Programs and functions can call each others, and share calls to any additional functions or use any additional data you want, as long as they are included in the score

## Scoring rules

Your score will simply be the sum of each program / function code sizes, as well as the size of any additional data / function required to make the code work. Each functions need to support all the entries listed in the table previously given.

# Answer
> 5 votes
# JavaScript (Node.js), 463 bytes

A function that translates whatever string it is given in both directions.

```
s=>"5Planet2Four-coupled2Jervis1Jenny lind1Porter3Olomana3Cramton2American3Columbian1Mogul5Forney3Eight-coupled5Huntington2Atlantic1Ten-wheeler7Prairie1Consolidation16Ten-coupled13Jubilee2Pacific1Mastodon13Adriatic2Mikado1Decapod31Union30Hudson2Mountain1El gobernador29Berkshire2Santa fe126Northern2Overland320Union pacific126Texas380Turbine1412Aa20".replace(/(\d+)(....\D*)/g,(_,a,b)=>(a=(t+=+a).toString(2).replace(/./g,(n,i)=>i?'oO'[n]:''))==s?b:b==s?a:'',t=0)

```

Try it online!

### How?

Each wheel arrangement is encoded as a binary pattern with a forced leading \\$1\\$ followed by \\$0\\$'s for `o`'s and \\$1\\$'s for `O`'s.

Once the list has been sorted from lowest to highest pattern under this encoding scheme, each name is prefixed with the delta value that must be added to the previous pattern to get the new one.

```
 Name         | Arrangement | As binary | As decimal | Delta
--------------+-------------+-----------+------------+-------
 Planet       |       oO    |     101   |      5     |   5
 Four-coupled |       OO    |     111   |      7     |   2
 Jervis       |      ooO    |    1001   |      9     |   2
 Jenny lind   |      oOo    |    1010   |     10     |   1
 Porter       |      oOO    |    1011   |     11     |   1
 Olomana      |      OOo    |    1110   |     14     |   3
 Cramton      |     oooO    |   10001   |     17     |   3
 American     |     ooOO    |   10011   |     19     |   2
 ...          |      ...    |     ...   |    ...     |  ...

```

Which is stored as:

```
"5Planet2Four-coupled2Jervis1Jenny lind1Porter3Olomana3Cramton2American..."

```

---

# JavaScript (Node.js),  ~~566~~  552 bytes

*Saved 14 bytes thanks to @HatsuPointerKun*

I personally think that the challenge is more interesting with two independent functions (and I originally assumed it was a requirement) so here is my attempt under this constraint.

The first function outputs the name with the first letter in upper case and everything else in lower case. The second function accepts the name in the same format (but it actually doesn't care about the case).

## Arrangement to name,  ~~378~~  364 bytes

```
s=>"CramtonPorterXMountainXTurbineXEl gobernadorJervisXHudsonSanta feMikadoColumbianXXDecapodMogulBerkshireAdriaticUnionOlomanaEight-coupledXAa20ForneyOverlandAtlanticUnion pacificXFour-coupledTen-wheelerPrairieNorthernHuntingtonXConsolidationPlanetPacificTen-coupledAmericanXMastodonTexasJenny lindJubilee".match(/.[^A-Z]*/g)[s.replace(/./g,c=>c>{}?3:7)%88812%47]

```

Try it online!

### How?

The pattern is turned into an integer by replacing `o`'s with \\$3\\$'s and `O`'s with \\$7\\$'s. For instance, `ooOOOoo` becomes \\$3377733\\$.

This is reduced modulo \\$88812\\$ and modulo \\$47\\$ to get the final index in the lookup table, e.g. \\$(3377733 \bmod 88812)\bmod 47=10\\$.

The lookup table is encoded as a single string where each entry starts with a capital letter. We use a single `X` for undefined entries.

```
"CramtonPorterXMountainXTurbineXEl gobernadorJervisXHudson..."
 ^      ^     ^^       ^^      ^^            ^     ^^
 0      1     23       45      67            8     9|
                                                    10

```

Hence the answer for `ooOOOoo`: `Hudson`.

## Name to arrangement, 188 bytes

```
s=>0x4489B662749DEFD3631DBEB225C432AC03F6DBD8C78503C3FE918DA62325B6895775C9FAFB8E0E03939CD081D4537BDD91B2D228n.toString(3).split`2`[parseInt(s[7]+s,33)*362%763%61].replace(/./g,c=>"Oo"[c])

```

Try it online!

### How?

We can't use `parseInt` directly on the name because, for instance, `Union` and `Union pacific` would both be parsed as `Union`.

Instead, we use:

```
parseInt(s[7] + s, 33)

```

Example:

```
"Jenny lind" ~> "iJenny lind" ~> 22045409

```

We apply a slightly more complicated formula to the result:

$$f(n)=((n\times 362)\bmod 763) \bmod 61$$

Example:

$$f(22045409)=2$$

The patterns are encoded in ternary, with \\$0\\$'s for `O`'s, \\$1\\$'s for `o`'s and \\$2\\$'s for the separators. This leads to a pretty huge integer which is stored as a BigInt in hexadecimal.

```
0x4489B66274...28n.toString(3).split`2`

```

gives:

```
[ '110001', '', '101', '0000', '10001', ... ]
                  ^
                'oOo'

```

Hence the answer for `Jenny lind`: `oOo`.

# Answer
> 2 votes
# C (gcc), ~~698~~ ~~671~~ 670 bytes

* -26 thanks to ceilingcat
* -2 using `\n` instead of `\012`

I encoded the Whyte notation into a bit encoding `xxyyyzz`, with `xx` being the leading wheels, `yyy` the driving wheels and `zz` the trailing wheels; these are stored at the beginning of each train name to save space. `f()` is the name-to-type conversion and `g()` is the type-to-name conversion.

```
#define F(a,b)for(;i/a;i-=a)printf(#b);
#define G(a,b)for(i*=a;b*s;s++)i++;
char*a[]={"$Planet","%Jenny Lind","(Porter",")Columbian","DJervis","FHuntington","dCramton","\8Four-coupled","\tOlomana","\nForney","HAmerican","IAtlantic","JJubilee",",Mogul","-Prairie",".Adriatic","JTen-wheeler","KPacific","LHudson","\020Eight-coupled","0Consolidation","1Mikado","2Berkshire","PMastodon","QMountain","RNorthern","iTurbine","\024Ten-coupled","\025Union","4Decapod","TEl Gobernador","UOverland","5Santa Fe",":Texas","ZUnion Pacific","^AA20"},**b;i;f(char*s){for(b=a;strcmp(s,1+*b);b++);i=**b;F(32,o)F(4,O)F(1,o)}g(char*s){G(0,111==)G(8,79==)G(4,)for(b=a;i-**b;b++);puts(1+*b);}

```

Try it online!

# Answer
> 1 votes
# Ruby, ~~478~~ 474 bytes

Latest edit: rearranged the order of names to allow for all to be in caps. Saved a few bytes by grouping constants and minor formatting.

```
->q{s=w=3;r=p=0;e="-WHEELER";z=46
'H`0
PDavU$J24(d:1E,_I8F9iXYZeV5*%hTy'.bytes{|i|t="UNION PACIFICCONSOLIDATIONEL GOBERNADORJENNY LINDHUNTINGTONCOLUMBIANBERKSHIRESANTA FENORTHERNMOUNTAINMASTODONOVERLANDATLANTICADRIATICAMERICANPACIFICTURBINECRAMTONPRAIRIEOLOMANAJUBILEEDECAPODJERVISPORTERFORNEYHUDSONPLANETMIKADOTEXASUNIONMOGULEIGHTAA20FOURTENTEN"[p-=w,w]
x=(y=[?o*(i/4%4)+?O*(i/16-1&7)+?o*(i%4),t+e*(1&z/=2)]).index q
x&&r=y[~x]
u=t.sum
u>s||w+=w/10*2+1
s=u
e="-COUPLED"}
r}

```

Try it online!

A single function which takes either kind of input and returns the correct output.

This is written to allow for further compression of the name string later.

The names of the configurations are generated in order from the shortest to the longest per the table below. A checksum is made by adding all the characters and normally this checksum is nondecreasing; when the checksum decreases the code increases `w` by the length of the name by 1 (or when jumping from `Jenny Lind` to `El Gobernador` by 3), thus the trigger to increase the length of the name is encoded in the string of names itself. After unpacking `-wheeler` or `-COUPLED` is added as a suffix.

We iterate through the names using a string of single characters that corresponds to the wheel configuration. This is unpacked using the string `?o*(i/4%4) + ?O*(i/16-1&7) + ?o*(i%4)` which covers the possibility of the front and back wheels numbering 0 through 3. Driven wheel counts `n` of 1 through 6 are encoded by `(n+1)*16`. For 7 pairs of driven wheels, the encoding is zero, plus `10` for the idler wheels giving ASCII 10 (newline) for the only locomotive with this number of wheels (`AA20`.) During the decoding process, this gives `n=-1` which is corrected to 7 by ANDing with -7.

```
["ooOOO", "TEN-WHEELER"]
["OOOOO", "TEN-COUPLED"]
["OO", "FOUR-COUPLED"]
["ooOOOOOOOoo", "AA20"]
["OOOO", "EIGHT-COUPLED"]
["oOOO", "MOGUL"]
["OOOOOo", "UNION"]
["oOOOOOOoo", "TEXAS"]
["oOOOOo", "MIKADO"]
["oO", "PLANET"]
["ooOOOoo", "HUDSON"]
["OOoo", "FORNEY"]
["oOO", "PORTER"]
["ooO", "JERVIS"]
["oOOOOO", "DECAPOD"]
["ooOOoo", "JUBILEE"]
["OOo", "OLOMANA"]
["oOOOo", "PRAIRIE"]
["oooO", "CRAMTON"]
["oooOOOOooo", "TURBINE"]
["ooOOOo", "PACIFIC"]
["ooOO", "AMERICAN"]
["oOOOoo", "ADRIATIC"]
["ooOOo", "ATLANTIC"]
["ooOOOOOo", "OVERLAND"]
["ooOOOO", "MASTODON"]
["ooOOOOo", "MOUNTAIN"]
["ooOOOOoo", "NORTHERN"]
["oOOOOOo", "SANTA FE"]
["oOOOOoo", "BERKSHIRE"]
["oOOo", "COLUMBIAN"]
["ooOoo", "HUNTINGTON"]
["oOo", "JENNY LIND"]
["ooOOOOO", "EL GOBERNADOR"]
["oOOOO", "CONSOLIDATION"]
["ooOOOOOOo", "UNION PACIFIC"]

```

# Ruby, 499 bytes

This is the compressed version. The characters `A..U` are compressed in groups of 3 down to 2 characters in printable ASCII range. Q does not appear in any locomotive name and is used for other characters. After decompression Q is replaced by the other characters  `Y VVYX20H` .

It's a bit of a fail as it's longer than the original. Also many compromises were made in the original to make this compression possible so maybe I will revise the original later.

```
->q{s=w=3;r=p=0;e="-WHEELER";z=46;d=""
261.times{|i|d<<('a`$9*wHx`m(`b5mHA{?`V(]pE7]k]|pd{^t1dp]x]+px!p!$9y)6$esqb[#)53fKnj|;`Dui]\\"{$a`?5B ;t^^'[i/3].ord*95+"I2._M7Du2GLm>FzF{zM=p0)M7'3-ziSJzjAt`\\,u,w7z2X2+_E:2J}#A[WSngy>8fBi`wf)>,Z{~7[2fsVrW.))"[i/3].ord-3135)/21**(i%3)%21+65}
'  Y  VVYX20H`0
PDavU$J24(d:1E,_I8F9iXYZeV5*%hTy'.bytes{|i|d=~/Q/?d.sub!(?Q,i.chr): (t=d[p-=w,w]
x=(y=[?o*(i/4%4)+?O*(i/16-1&7)+?o*(i%4),t+e*(1&z/=2)]).index q
x&&r=y[~x]
u=t.sum
u>s||w+=w/10*2+1
s=u
e="-COUPLED")}
r}

```

Try it online!

# Answer
> 1 votes
# C#, 846 Bytes

```
using System;using System.IO;using System.IO.Compression;class P{
string[]D(){byte[]b=new byte[565];new GZipStream(new MemoryStream(Convert.FromBase64String("H4sIAAAAAAAAClWRbU7DMAyG//sUvcAkxA3K2ECIkkmMA6SNWa2l8eSmg90e52MD+ssfr53Hb9nAztuAEdgwvGAIl+aVgtNUOywRJYUMa/bL1JMNwGxUKGeaU8gMz0uIFA6RU0+ba7FTSnTDlhdZDbycPDrNGYznyQabYtauBLykLQbaCYWGsl51bVSqSENJlWzpySMmFgMdHxafQ4adWBIqDdW1Tshe5wzsMay+RkSfzqgDdqDPqyDTuznDqnxDhzHeeJNAr+EwsyenW9OBRj+Gjo7Wcc0YHlCO80iiGGWos3Nklw2pA6wmWboVGN7U3BGleJZLDPtFegqYYQr8r3d5zUe4QRh4xMGeWDlrvvHNE/e6UtHqudnyM4qaWe/Rwrs6a5tt8azA7PHb5t/5953mn1VV2bb3dz9Z/JdzNQIAAA==")),(CompressionMode)0).Read(b,0,565);return System.Text.Encoding.ASCII.GetString(b).Split('\n');}
public string A(string i){var L=D();return L[Array.FindIndex(L,s=>s==i)-1];}
public string B(string i){var L=D();return L[Array.FindIndex(L,s=>s==i)+1];}}

```

## How?

I edited the table into a bare minimum text file where the Whyte Notation lines are followed by a line with their name.

Then I gzipped the text and encoded those bytes in base64 to make a compressed string literal to store in the code.

The original text data took up 565 bytes and the base64 string is just 444 bytes.
Making a constant literal array for these strings in C# would have taken at least 781 bytes. The function to decompress and return the array is only 622 bytes.

When either function `A()` or `B()` in the program runs, it decodes and decompresses the base64 string into an array of strings. Using some simple `Array.FindIndex` I can find the line matching the function input and return the line either above or below the matched index.

# Answer
> 1 votes
# Retina, (445+262)= 707 bytes

## Notation -\> Name, 445 bytes

```
O+
$.&
oo
V
V2V
Jubilee
V2o
AtlXtic
o2o
ColumbiX
2V
Forney
V2
AmericX
o2
Porter
2o
OlomXa
2
FourY
V7V
AA20
Vo4Vo
Turbine
o6V
Texas
V6o
5o V3o
V4V
Northern
V5o
OverlXd
V3V
HudsW
o4V
Berkshire
V4o
Mountain
V5
El Gobernador
o5o
SXta Fe
o3V
Adriatic
V3o
Pacific
o4o
Mikado
V4
MastodW
5o
UniW
o5
Decapod
V1V
HuntingtW
o3o
Prairie
V3
Ten-wheeler
o4
CWsolidatiW
Vo1
CramtW
o3
Mogul
o1o
Jenny Lind
V1
Jervis
o1
PlXet
5
TenY
4
EightY
W
on
X
an
Y
-coupled

```

Try it online!

### Approach

Replace each run of `O`s with its length, giving us for example `oo7oo`. Replace each `oo` with `V`, giving us for example `V7V`. Then replace that shortened notation with the appropriate name.

There wasn't a whole lot of similarity between names -- the only substrings I found to be worth extracting were `-coupled`, `an`, and `on`

## Name -\> Notation, 262 bytes

```
Hun.*
ZOZ
....(..?).*
$1
AA20
Z7Z
at
o3Z
ic
Z2
nt
Z2o
sh
o4Z
mb
o2o
ol
o4
to
ZoO
po
o5
ob
Z5
t-
4
ey
2Z
-c
2
on
Z3Z
y
oOo
is
ZO
le
Z2Z
od
Z4
do
o4o
ta
Z4o
he
Z4Z
an
2o
la
Z5o
et
oO
er
o2
ri
o3o
fi
Z3o
a
o5o
wh
Z3
co
5
s
o6Z
in
Zo4Zo
n
Z6o
n
5o
l
o3
Z
oo
\d
*O

```

Try it online!

### Approach

Extract 2 unique characters from each name, and use that to determine the notation. I found the 5th and (if present) 6th characters to work pretty well. `Huntington` clashes with `Turbine`, so `Hun.*` is replaced in advance. The shortened notation is the same as what's used for the Notation-\>Name program, but in reverse.

---
Tags: code-golf, kolmogorov-complexity
---


title: Happy Fibonacci Day!

text:
# Question
Title: Happy Fibonacci Day!
## Background

Today (or Yesterday) is (or was) 11/23 or Fibonacci day! What better way to celebrate than to make a Fibonacci cake?

---

## Examples

```
3

    ii
i_i_ii_i_i

```

\</\>

```
8

              ii
              ii
              ii
              ii
              ii
              ii
              ii
              ii
            i ii i
            i ii i
            i ii i
            i ii i
            i ii i
          i i ii i i
          i i ii i i
          i i ii i i
        i i i ii i i i
        i i i ii i i i
      i i i i ii i i i i
    i i i i i ii i i i i i
i_i_i_i_i_i_i_ii_i_i_i_i_i_i_i

```

## Challenge

You're not really making a cake, just the candles because I can't ascii-art a cake

To make the cake you must first get the first `n` Fibonacci numbers sorted ascending. The candle (`i`)'s height is determined by value of the current Fibonacci number. The candles are separated by an underscore (`_`).

The cake should be symmetrical. So the candles should then be flipped and concatenated.

## Example Construction

```
Input: 6
First 6 Fibonacci Numbers: 1, 1, 2, 3, 5, 8
Candle heights:

          i
          i
          i
        i i
        i i
      i i i
    i i i i
i i i i i i
-----------
1 1 2 3 5 8

Output would be:
          ii
          ii
          ii
        i ii i
        i ii i
      i i ii i i
    i i i ii i i i
i_i_i_i_i_ii_i_i_i_i_i

```

## Reference Fibonacci Numbers

For reference, here are the first 15 Fibonacci numbers. In this challenge, you'll be starting at `1`.

```
1,1,2,3,5,8,13,21,34,55,89,144,233,377,610

```

# Answer
> 2 votes
# Pyth, 31 bytes

```
jaPJ_.ts_BuaaGks>4GtQ]\idXeJ" _

```

Try it online: Demonstration

### Explanation:

```
jaPJ_.ts_BuaaGks>4GtQ]\idXeJ" _   implicit: Q = input number
          u        tQ]\i          reduce the list [1, ..., Q-2], start with G=["i"]
            aGk                      append the empty string to G
           a   s>4G                  append the sum of the last 4 strings in G to G
                                  this gives ["i", "", "i", "", "ii", "", "iii",..]
       s_B                        extend the list with the reversed list
     .t                  d        pad to a rectangle with spaces and transposes
   J_                             reverse the order and assign to J
  PJ                              remove the last string of J
 a                                and append
                         XeJ" _   the last string of J with spaces replaced by "_"
j                                 print each string on a separate line

```

# Answer
> 6 votes
# J, 58 bytes

```
3 :''' i_''{~|.|:(,|.)(#&1,2#~0&=)"*}.,0,.(%-.-*:)t.1+i.y'

```

Uses `(%-.-*:)t.` for Fibonacci generation. Explanation might come a bit later.

Usage:

```
   f=.3 :''' i_''{~|.|:(,|.)(#&1,2#~0&=)"*}.,0,.(%-.-*:)t.1+i.y'
   f 5
        ii
        ii
      i ii i
    i i ii i i
i_i_i_i_ii_i_i_i_i

```

Try it online here.

# Answer
> 5 votes
# CJam, ~~41~~ 39 bytes

```
"i""_"1$ri({1$1$4$+}*]),f{Se[}W<_W%+zN*

```

This prints a fair amount of leading whitespace. Try it online in the CJam interpreter.

### How it works

```
"i""_"1$ e# Push "i", "_", and a copy of "i".
ri(      e# Read an integer from STDIN and subtract 1.
{        e# Do that many times:
  1$     e#   Copy the last underscore.
  1$4$+  e#   Copy the last strings of i's and concatenate them.
}*       e#
]),      e# Wrap the results in an array, pop the last string, and get its length.
f{       e# For each remaining string, push the string and the length; then:
  Se[    e#   Pad the string to that length by prepending spaces.
}
W<       e# Remove the last string (underscore).
         e# We have now generated the columns of the left half of the output.
_W%+     e# Append a reversed copy (columns of right half).
z        e# Transpose rows with columns.
N*       e# Separate the rows by linefeeds.

```

# Answer
> 3 votes
# TeaScript, ~~93~~ ~~84~~ 76 + 1 = 77 bytes

+1 byte for "Inputs are numbers?" checkbox

```
r×ß(p.R((w=F(x©-F(i¬©+"i"R(F(i¬±)t¡ß(j=i<w-1?" ":"_",(A=l¿i>0?j+l:l)µ)+Av©j§

```

**Ungolfed version:**

```
r(x)m(#(p.R((w=F(x))-F(i+1))+"i"R(F(i+1))))t()m(#(j=i<w-1?" ":"_",(A=ls``.m(#i>0?j+l:l)j``)+Av))j`
`

```

Thanks to @Vɪʜᴀɴ for the tips.

# Answer
> 3 votes
## Python 2, 117 bytes

```
a=b='i'
l=a,
exec"l+='_',b,;a,b=b,b+a;"*~-input()
for r in map(None,*l+l[::-1])[::-1]:print''.join(x or' 'for x in r)

```

The idea is simple: generate the picture in columns going bottom to top, left to right, with the mirrored right half the reverse of the left. The columns are generated by iterating the Fibonacci recurrence, on strings of `i`'s, interspersed with `_`'s for the bottom row.

To print the picture with columns starting from the bottom, we need to rotate it, which means transposing and reversing. Unfortunately, Python doesn't have a simple way to transpose an array of unequal-length rows. The built-in `zip` truncates to the shortest row. This uses the `map(None,_)` trick, but has to convert all the `None` to spaces afterwards.

# Answer
> 2 votes
# Haskell, ~~182~~ 176 bytes

```
import Data.List
f=0:scanl(+)1f
b n c s|length s<n=b n c(c:s)|0<1=s
m s=s++reverse s
c n=mapM_ putStrLn$transpose$m$map(b(f!!n)' ')$intersperse"_"$map(\x->[1..f!!x]>>"i")[1..n]

```

Call `c`.

(`f` shamelessly stolen from https://stackoverflow.com/questions/232861/fibonacci-code-golf)

# Answer
> 2 votes
# Jelly, 23 bytes

```
RÆḞ”iẋz⁶Ḣj”_ƊṭK€Ṛ$Ɗm€0Y

```

Try it online!

Jelly's not great at and neither am I

## How it works

```
RÆḞ”iẋz⁶Ḣj”_ƊṭK€Ṛ$Ɗm€0Y - Main link. Takes N on the left
R                       - [1, 2, ..., N]
 ÆḞ                     - k'th Fibonacci for each k in the range
   ”i                   - "i"
     ẋ                  - Repeat "i" k times for each k
      z⁶                - Transpose filling with spaces
                  Ɗ     - To this matrix:
            Ɗ           -   First:
        Ḣ               -     Pop and yield the first element (the base)
         j”_            -     Join with "_"
                 $      -   Then:
              K€        -     Join the other rows on spaces
                Ṛ       -     Reverse
             ṭ          -   Take the base onto the end of the rows
                   m€0  - Mirror each row
                      Y - Join on newlines

```

# Answer
> 1 votes
# Python 2, 213

Saved 12 bytes thanks to DSM.

```
def f(r):
 a=b=1
 while r:yield a;a,b=b,a+b;r-=1
n=list(f(input()))
n.remove(1)
h=max(n)-1
r=1
while h:
 l='  '*(len(n)+1)+('i '*r)[:-1];print(l+l[::-1]);h-=1
 if h in n:r+=1;n.pop()
l='i_'*r+'i_i'
print l+l[::-1]

```

Ungolfed version.

```
max_height = input()
def fib(r):
    a=b=1
    while r:
        yield a
        a,b = b, a + b
        r-=1

numbers = [x for x in fib(max_height) if x>1]
highest = max(numbers) -1
rows = 1
while highest:
    line =' '*((len(numbers)+1)*2) + ' '.join('i'*rows)
    print(line + line[::-1])
    highest -= 1
    if highest in numbers:
        rows += 1
        numbers.pop()

line = '_'.join('i'*(rows+2))
print(line + line[::-1])

```

# Answer
> 1 votes
# Ruby, ~~151~~ ~~146~~ ~~142~~ ~~137~~ 132 bytes

```
->n{s=1,1;3.upto(n){s<<s[-1]+s[-2]};s.map!{|i|[' ']*(s[-1]-i)+[?i]*i}.transpose.map!{|a|v=a*'_ '[a.count(?i)<=>n];puts v+v.reverse}}

```

**137 bytes**

```
->n{s=1,1;3.upto(n){s<<s[-1]+s[-2]};o=s.map{|i|[' ']*(s[-1]-i)+[?i]*i}.transpose.map{|a|v=a*' ';v+v.reverse};o[-1]=o[-1].tr' ',?_;puts o}

```

**142 bytes**

```
->n{s=1,1;(3..n).map{s<<s[-1]+s[-2]};puts s.map{|i|[' ']*(s[-1]-i)+[?i]*i}.transpose.map{|a|v=a*' ';v+v.reverse}.tap{|c|c[-1]=c[-1].tr' ',?_}}

```

**146 bytes**

```
->n{s=1,1;(3..n).map{s<<s[-1]+s[-2]};puts s.map{|i|[' ']*(s[-1]-i)+[?i]*i}.transpose.map{|a|v=a.join' ';v+v.reverse}.tap{|c|c[-1]=c[-1].tr' ',?_}}

```

**151 bytes**

```
->n{s=1,1;(3..n).map{s<<s[-1]+s[-2]};puts s.map{|i|[' ']*(s[-1]-i)+['i']*i}.transpose.map{|a|v=a.join ' ';v+v.reverse}.tap{|c|c[-1]=c[-1].tr ' ', '_'}}

```

Ungolfed:

```
-> n {
  s = 1,1
  3.upto(n) {
    s << s[-1] + s[-2]
  }
  s.map! { |i|
    [' '] * (s[-1]-i) + [?i] * i
  }.
  transpose.
  map! { |a|
    v = a * '_ '[a.count(?i)<=>n]
    puts v + v.reverse
  }
}

```

**Usage:**

```
->n{s=1,1;3.upto(n){s<<s[-1]+s[-2]};s.map!{|i|[' ']*(s[-1]-i)+[?i]*i}.transpose.map!{|a|v=a*'_ '[a.count(?i)<=>n];puts v+v.reverse}}[8]

```

Output:

```
              ii
              ii
              ii
              ii
              ii
              ii
              ii
              ii
            i ii i
            i ii i
            i ii i
            i ii i
            i ii i
          i i ii i i
          i i ii i i
          i i ii i i
        i i i ii i i i
        i i i ii i i i
      i i i i ii i i i i
    i i i i i ii i i i i i
i_i_i_i_i_i_i_ii_i_i_i_i_i_i_i

```

# Answer
> 1 votes
# Matlab, ~~172~~ 152 bytes

Unfortunately, Matlab hasn't a build in Fibonacci function and string Manipulation is a bit fiddly.

```
function t(n);f=@(n)getfield([0 1;1 1]^n,{3});m=char(flipud(bsxfun(@(a,b)(a<=f(b/2)&mod(b,2)==0)*'i',(1:f(n))',2:2*n)));m(end,2:2:end)='_';[m fliplr(m)]

```

With line breaks:

```
function t(n);
f=@(n)getfield([0 1;1 1]^n,{3});
m=char(flipud(bsxfun(@(a,b)(a<=f(b/2)&mod(b,2)==0)*'i',(1:f(n))',2:2*n)));
m(end,2:2:end)='_';
[m fliplr(m)]

```

# Answer
> 1 votes
# Vyxal, 21 bytes

```
v∆F\i*∩vṄṘøɽvm‡\_ḞuV⁋

```

Try it Online!

## How?

```
v∆F\i*∩vṄṘøɽvm‡\_ḞuV⁋
v∆F                   # For each item in [1, implicit input], get the nth fibonacci number
   \i*                # For each, repeat that many "i"s
      ∩               # Transpose
       vṄ             # Join each by spaces
         Ṙ            # Reverse
          øɽ          # Prepend leading spaces to each to right-align it
            vm        # Mirror each
              ‡\_ḞuV  # To the last item, replace spaces with "_"
                    ⁋ # Join on newlines

```

---
Tags: code-golf, ascii-art, fibonacci
---


# Question
Title: Confound my attempts to solve the halting problem
**Please note:** By its nature, the spec for this challenge is difficult to understand. It probably requires at least a freshman course in computability theory, or equivalent background reading. In addition, the challenge itself is rather hard. Answering it will require writing an entire interpreter for some subset of your language of choice, and not only that but the interpreter will have to be in the form of a something like a quine. If your answer isn't doing all of this, it is almost certain not to meet the spec.

You don't need to solve the halting problem (even partially) in order to solve this challenge. However, you almost certainly *do* need to write an interpreter (of the language you are using, written in the same language it interprets), though it need not be feature complete. It's this that makes this an interesting challenge.

I promised to award a 500 point bounty to the first answer that meets the spec, and this will be awarded to Jo King's BF answer.

**The challenge**

A rough, simplified version of Alan Turing's proof of the unsolvability of the halting problem goes something like this:

Suppose I've written a program `F` that's meant to solve the halting program. That is, `F` takes the source code of another program as input, and `F(G)` is supposed to return `1` if `G` halts, and `0` otherwise.

But if I give you my program `F` then you can construct another program, `H`, that runs my program with `H` as its input. If `F(H)` returns `0` then `H` returns `0`, but otherwise it deliberately goes into an infinite loop. This leads to a paradox, and we have to conclude that `F` can't solve the halting problem after all.

Your task is to write the program `H`, but with a twist: I'm not going to give you my program. Instead, your program will receive my program's source code as an input. That is:

* **Your program** will receive **my program** as an input, in source code form. (E.g. as a file or as command line input, the details are up to you.)
* **My program** will be written in the same language as your program, and also takes input in the form of a source code string.
* If **my program** returns `0` when given **your program** as input, **your program** should halt (and return `0`) when given **my program** as input. (The exact meaning of "returing `0`" is up to you.)
* if **my program** doesn't halt, or if it returns anything other than `0` when given your program as input, **your program** should keep running indefinitely.

The twist is that, just to make it really quite a lot harder, you have to obey the following rules:

1. You can't use any kind of built-in `exec` or `eval`-type function.
2. You can't use any "cheating" methods to get at your own program's source code. (E.g. you can't say "save this in a file called 'program'" and then have `open(program)` in your program.)

This means that your program has to be some kind of crazy super-quine that can not only reproduce its own source code in the form of a string, but is also capable of correctly parsing and interpreting the language it's written in.

To make it slightly less insanely hard, you're allowed to use just a (Turing-complete) subset of your chosen language. So if your program is written in Python and will only work if my program only contains `if`s and `while` loops and basic string operations, then that's OK as long as your program only uses those things too. (This means that you don't have to worry about implementing your chosen language's entire standard library!) However, your program does have to actually run - you can't just make up your own language.

This is , so the answer with the most votes wins. However, as mentioned above, it's a serious challenge just to meet the spec at all, so I will award a 500 point bounty to the first answer that does so according to my judgement.

**please note:** no doubt there are many ways you can "cheat" at this challenge, given the exact wording I've used. However, I'm really hoping for answers that enter into the spirit of the question. The challenge as intended is very difficult but possible, and I'm really hoping to see genuine solutions to it. I won't award the bounty to an answer that feels cheaty in my judgement.

---

Note: this challenge was originally posted as , but it was closed in 2016 due to not having an "objective winning criterion", and I changed it to in order to get it reopened. However, I've found that, as of January 2018, s are not in fact banned on PPCG (with this being the most recent meta discussion) so closing it in the first place was against site policy. I understand that popcons are not popular these days, but this is an old challenge, and its nature makes it really unsuitable for the scoring system. If anyone still feels strongly that it shouldn't be allowed then let's have a meta discussion before close votes start getting thrown around. Finally, on the off-chance that someone's spent the last year attempting to golf their solution, rest assured that it will be just as competitive in this challenge, and just as worthy of the bounty, as it would have been in the version.

# Answer
# brainfuck, ~~6013~~ ~~4877~~ 4376 bytes

Edit: -1136 bytes. Switched to a better way of generating the data for the quine

Edit2: -501 bytes. Revisited my self-interpreter and cut it down a couple of hundred bytes

```
->++>++++>+>++>+++>>++++>>++++>>+++>>++++>>+++>>++>++>++>++>++>++>++>++>++>++>++++>+++++>+>++>++>++>++>++>++>>+++>+>++>++>++++>+>+++>+>++++>+>+++>+>++>>>+++++>++++>++++>>+++>>++++>>+++>>++>++>++>++>++>++>++>++++>+++++>+>++>++>++>++>++>++>>+++>+>++>++++>+>+++>+>++++>+>+++>+>++>>>+++++>+++>>+++>+>+++++>+++++>++++>>++>+>++>++>++>++>++>++>+++>>++>++>>++++>>+++>++>++>++>++>++>++++>+++++>>++>++>++>+>+++>>++++>>++>++>++>>++>++>++>>++>++>++>>++>++>++>++>++>++>>++>++>++>++>++>++>>++>++>++>>++>++>++>++>>++>++>++>++>++++>+>+++>>+++++>+++>>++>>+++++>>>++>>++>++>++>>+++++>+++++>>>++>++>++++>+>+++>+>+>++++>+>+++>+>+>++++>+>+++>>++++>++++>++++>>+++>>>++++>>+++>>>++++>>+++>+>++++>+++++>>>++>+>+>+++>+>++++>+>+++>+>+>++++>+>+++>+>+>++++>+>+++>>+++++>+++>>++++>>+++>>>++++>>+++>>>++++>>+++>>>++++>+++++>+>+>++>++++>+>+++>+>++>>>++++>>+++>>+++>+>+>++++>++++>+++++>>++>+>+++>+>+++>>>++++>>+++>>++++>++++>+++++>+>++>>+++>>+++>+>+>++++>+>+++>+>+>++++>+>+++>+>+>++++>+>+++>>+++>>>>++++>>+++>>>++++>>+++>+>++++>++++>+++++>+++>+>+++>>>>++++++>++++>>++>++>++>++>++>++>++>++++>+>+++++>+++++>+++++>+++++>+++++>+++++>>+++++>+++>++>+>+++++>++++>>+++>>++++>+>++>+>++>>>>>+++>+>+>+>+++++>++++>>+++>>++++>+>++>+>++>>>>>+++>+>+>+>+++++>++++>>+++>>++++>+>++>+>++>>>>>+++>+>+>+>+++++>++++>>+++>>++++>+>+++++>+>++>++>++>>>>>+++>+>+>+>+++++>+++++>+++++>+++++>+++++>+++++>+++++>+++++>+++++>+++++>+++++>+++++>+++++>+++++>++++>>+++>>++++>+>++>++>+>++>>>>>+++>+>+>+>+++++>+++++>++++>>+++>>++++>+>+++++>+>++>++>++>++>++>++>++>>>>>+++>+>+>++>++>++>++>++++>+++++>+>+++++>+++++>+++++>+++++>+++++>+++++>>+++>++>+>++>++++>>+++>>++++>+>++>++>+>++>>>>>+++>+>+>+>+++++>+++++>++++>>+++>>++++>+>+++++>+>++>>>>>+++>+>+>+++++>+>++++>++>+++>+>++++>>+++>>++++++>+++>>>>++>+>+>+>+>+++++>++++>+>+++>>++++>+++++>++++>+>+>+++>>++++>+>++>++++>>+++>>>++++>+>+++>+>+>++++>>>++>++++>+>+>++++>+>+++>+>+>+++++>++++>>>+++>+>++++>>>>>++++>>+++>>++>+>+>++++>+>+++>+>+++>+>+++++>++++>>>+++>+>++++>>>>>++++>>+++>>+++++>+>+>++++>+>+++>+>+++>+>++>++>++++>+++++>>>++>+>+>+++>>>++++>>+++>>+++>+>+++>+>++++>+>+++>>+++++>+>+++>>+++++>++++>+>+>+++>>++++>+>++>++>++++>>+++>>>++++>+>+>+++>>++++>+>+>++>++++>+>+>++++>+>+++>>++++>+++++>+>+>++>>>+++>>+++++>+++++>++++>+>+>+++>>++++>++++>>+++>>++>+>+>++++>+>+++>+>+++>>++>++++>+>+>+++>>++++>++++>>+++>>+++++>+>+>++++>+>+++>+>+++>>++>++++>>+++>>+++>+++>+>+>++++>+>+++>>+++++>+++++>+>+++>>+++++>++++>+>+>+++>>++++>++++>>+++>>>+++++++>+>+>+>++++>+>+++>+>+++>>+++++>++++>+>+>+++>>++++>++++>>+++>>>+++++>+>+>+>++++>+>+++>+>+++>>+++++>++++>+>+>+++>>++++>++++>>+++>>>++++++>+>+>+>++++>+>+++>+>+>+>++++>+>+++>+>++++>+>+++>>++++>++++>>+++>>++++>>+++>>>>++++>>+++>>>++>+>+>+>++++>+>+++>+>+>+>++++>+>+++>+>++++>+>+++>>+++++>+++>>++++>>+++>>++++>>+++>>>++++>+>+++>+>+++>>+++++>++++>+>+>+++>>++++>++++>>+++>>>++>+>+>+>++++>+>+++>+>+++>>+++++>++++>+>+>+++>>++++>++++>>+++>>>>++++>>>+++>>++++>+>+>+>++++>+>+>+++>+>++>>>>++++>>>+++>>+++++>+++>>++++>+++++>+++>+>+>++>++++>+>++++>+++++>>>++>+>+>+++>+>+++>+>++++>+++++>>>++>+>+>+++>+>++++>+>+++>+>+++>>+++++>++++>+>+>+++>>++++>++++>>+++>>++>++>++++>+++++>+++++>>++++>+++++>+>+>++>>>+++>>+++>++>+>+>+++++>++++>++>++>+>+>+++>+>++++>+++++>>>>++++>>>+++>>++>+>+>+>++++>+>+>+++>+>+++>+>++++>+>+++>+>+++>+>++>++>++>++>++>++>++>++>>>++++>++>+>+>+++++>>>+++>>+++>>>++++>++++[<+]>[>[>]>[>]>++++++++++[-<++++++>]<++[<]<[<]<+>>-[[>]>[>]>+++++++[-<++++++>]<+[<]<[<]<+>>-]>]<--[>+<++++++]>++>[>]+++++[->+++<]>[>+++>+++>+++>++++++>++++++>+++>++++>++++[<]>-]>+>->>+>+++>-->>++[<]<<[<]<<[<]>[[[>]>>[>]>>[>]<[->>+<<]<[<]<<[<]<<[<]>-]>[>]>>[>]>>[>]>>[-<<+[<]<+>>[>]>]<<[[->+<]<]>>[>]>[[-<+>]>]<<[<]<<[<]<<[<]>]>>>[>]>>[>]<[[-]<]>>>,[>+++++++[<------>-]+<-[>]>[<+<+>>>>]<<<-[>]>[<+<+>>>>]<<<-[>]>[<+<+>>>>]<<<-[>]>[<-<+++>>>>]<<<--------------[>]>[<++<+>>>>]<<<--[>]>[<-<+++++++>>>>]<<++++[-<------>]+<+[>]>[<++<+>>>>]<<<--[>]>[<-<+>>>>]<<-<[+]<[>]>,]>>>+<<<<-[<]>[-[<<]>[<+[>]>>[<]<<[>>+[<<[<]<<-[>>]<[>>>>[>]>+<<[<]<]<-[>>]<[>>>>[>]>-<<[<]<]<++[->>+<<]>>[>]>]<]<[<]>-<]>-[<<]>[<++[>]>>[<<]>[<<+[<<[<]>[-<<+>>]>--[<<]>[[>]>+<<[<]<]>+[<<]>[[>]>-<<[<]<]>+[>]>]]<<[<]>--<]>-[<<]>[[>]>>.<<<[<]<]>-[<<]>[[>]>>-<<<[<]<]>-[<<]>[[>]>>,<<<[<]<<<[<]<[<]>[[>]>[>]>>>[>]>>+<<<[<]<<<[<]<[<]>-]>[>]>[>]>>[<]<]>-[<<]>[[>]>>+<<<[<]<]>-[<<]>[[>]>>>[>>]>[<<<[<<]<+>>>[>>]>-]>[-]<<+[<[->>+<<]<]<[->>+<<]<[<]<]>-[<<]>[[>]>++[-->[-<<+>>]>]+<<-[++<<]<[->>>[>>]>+<<<[<<]<]<[<]<]<++++++++>>[+<<->>]>]>>[]

```

**Try it online!** The input here is a simple cat program (`,[.,]`) which will print the program itself.

"Return 0" is defined by ending the program on a cell with value 0.

A unholy combination of two programs I've written in the past, a quine and a self-interpreter. First section is the quine part, which takes the data and populates the tape with the the data generation followed by the source code. Next is the self-interpreter, which takes **your program** and runs it. This is pretty much a unchanged copy of a normal self interpreter, except that instead of taking input directly, it gets input from the beginning of the data section, setting the cell to 0 if there is no more input. Finally, end on the current cell of **your program** and run `[]`. If the returned value was 0, **my program** will end on zero. If it is anything else, it will run an infinite loop. If **your program** runs forever, **my program** will run forever.

## How It Works:

### Part 1: Data Generation

```
->++>++++> ....... >+++++>>>+++>>+++>>>++++>+++

```

This part makes up the data section of the quine, and is by far the majority of the code at 3270 bytes. The beginning `-` is a marker for the beginning of the data. Each `>+++` represents a character of the code after this section.

```
Number of Pluses
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
> | < | + | ] | [ | - | , | . |

```

### Part 2: Generate the data section using the data

```
+[<+]>

[
    Add a right arrow
    >[>]>[>]>(10++++++++++)[-<(6++++++)>]<++[<]<[<]
    <+>>-
    Add the right amount of pluses
    [
        [>]>[>]>(7+++++++)[-<(6++++++)>]<+[<]<[<]<+>>-
    ]
    >
]
Add the beginning minus
<--[>+<++++++]>++

```

This uses the data from part one to add the characters that are used to generate the data to the code section. It adds a `>` to the end of the code section and that cell's value many pluses.

### Part 3: Generate the rest of the code using the data

```
Initialises the 8 characters of brainfuck
>[>]+++++[->+++<]>[>+++>+++>+++>++++++>++++++>+++>++++>++++[<]>-]
>+>->>+>+++>-->>++[<]<<[<]<<[<]>

Tape looks like:
data 0 0 code 0 0 characters

Runs through the data destructively and adds the represented symbol to the code section
[
    [
        For each plus in this cell
            Shift the gap in the characters over one
        [>]>>[>]>>[>]<[->>+<<]
        <[<]<<[<]<<[<]>-
    ]
    Navigate to character
    >[>]>>[>]>>[>]>>
    Copy the character to the end of the code section
    [-<<+[<]<+>>[>]>]

    Shift the symbol section over one
    <<[[->+<]<]
    >>[>]>[[-<+>]>]

    Navigate to next byte of data
    <<[<]<<[<]<<[<]>
]

Remove characters
>>[>]>>[>]<[[-]<]

```

Destroys the data section and adds the rest of the source code to the code section

### Part 4: Get inputted program

```
>>>,
[
    >(7+++++++)[<(6------)>-]+<-
    [>]>
    [plus <+<+>>>>]<<<
    -[>]>
    [comma <+<+>>>>]<<<
    -[>]>
    [minus <+<+>>>>]<<<
    -[>]>
    [dot <-<+++>>>>]<<<
    (14--------------)[>]>
    [left <++<+>>>>]<<<
    --[>]>
    [right <-<+++++++>>>>]<<
    (29++++[-<------>]+<+)
    [>]>
    [start loop <++<+>>>>]<<<
    --[>]>
    [end loop <-<+>>>>]<<
    -<[+]<[>]>,
]

```

Gets the inputted program. Removes non-brainfuck characters and represents each character with a number:

```
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
] | [ | . | - | , | + | > | < |

```

Represents the end of the program with `255`.

### Part 5: Interpreting the input

```
Initialise simulated tape
>>>+<<<<-

[<]>
[
    -[<<]>
    [end loop
        co 0 0 0 e:  _1 0 0 0 1 ?
        Check if current cell is one
        <+[>]>>[<]<<
        co 0 0 1 e _1: 0 0 !0 1
        or
        co 0 0 1 e _1 0: 0 0 1
        [ If current cell is one navigate to corresponding start loop
            Create counter
            >>+
            [
                co 0 0 de _1 0 c: !0 1
                checks if next instruction is an end loop
                <<[<]<<-
                [>>]<
                c !0 0: 0 de _1 0 c !0 1
                or
                c: 0 0  0 de _1 0 c !0 1
                [>>>>[>]>+<<[<]<] Add one to counter if it is
                checks if start loop
                <-[>>]<
                c !0 0: 0 de _1 0 c !0 1
                or
                c: 0 0  0 de _1 0 c !0 1
                [>>>>[>]>-<<[<]<] Subtract one from counter if it is
                c ? 0: 0 de _1 0 c !0 1
                Adds two to counteract checks and move to the next instruction
                <++[->>+<<]
                >>[>]>
                c 0 0 ode _1 0 c: !0 1
                End on the counter
                    If the counter is 0 then we have reached the corresponding bracket
            ]
            c 0 0 2 de _1 0 0: !0 1 0
            <
        ]
        c 0 0 1?2 de _1 0: 0 0 1 0
        Subtract one from current instruction
            This executes the start loop code next but that does nothing
        <[<]>-<
    ]
    >-[<<]>
    [start loop
        c 0 0 0 de:  _1 0 0 ? 1
        <++[>]>>[<<]>
        c 0 0 2 de _1 0 0 0 1:
        or
        c 0 0 2 de _1 0 0: !0 1
        [ If current cell is 0 navigate to corresponding end loop
            Initialise counter
            <<+
            c 0 0 ode _1 0 c: 0 1
            [ While counter is not 0
                Transfer current instruction over (first instruction is guaranteed to be start loop)
                <<[<]>[-<<+>>]>
                co 0 0 de _1 0 c: 0 1
                Check if start loop
                --[<<]>
                co 0 0: !0 e _1 0 c 0 1
                or
                co 0 0 0 e _1 0 c 0 1
                [[>]>+<<[<]<] Add one to counter if so
                checks if end loop
                >+[<<]>
                co 0 0: !0 e _1 0 c 0 1
                or
                co 0 0 0 e:  _1 0 c 0 1
                [[>]>-<<[<]<] Subtract one from counter if so
                Add one to counteract checks and navigate to counter
                >+[>]>
                co 0 0 de _1 0 c: 0 1
                End on counter
                    If counter is 0 then we have reached the corresponding end loop
            ]
            co 0 1 e _1 0 0: 0 1
        ]
        co 0 0 2?1 e _1 0 0: ? 1
        Subtract two from the current instruction to bring it back up to the right value
        <<[<]>--<
    ]
    3 of these are pretty self explanatory
    Navigate to the current cell and execute the instruction on it
    >-[<<]>
    [output
        [>]>>.<<<[<]<
    ]
    >-[<<]>
    [minus
        [>]>>-<<<[<]<
    ]
    >-[<<]>
    [input
        Reset current cell
        [>]>>, (no more input so this is set to 0)
        co 0 0 0 e:  _1 0 0 0: 1 b 1 a 0 d 1 e 1 f
        Navigate to start of code section
        <<<[<]<<<[<]<[<]>
        d: ata 0 co 0 0 0 e _1 0 0 0 1 b
        or
        0: co 0 0 0 e _1
        Transfer next instruction to current cell
        [[>]>[>]>>>[>]>>+<<<[<]<<<[<]<[<]>-]
        0: ata 0 co 0 0 0 e _1 0 0 d 1 b
        or
        0: co 0 0 0 e _1
        Navigate back to the normal spot
        >[>]>[>]>>[<]<
    ]
    >-[<<]>
    [plus
        [>]>>+<<<[<]<
    ]
    >-[<<]>
    [right
        Simulated tape looks like:
            a b c: d e f
        co 0 0 0 e:  _1 0 0 c 1 b 1 a 0 d 1 e 1 f
        Navigate to value of cell to the right
        [>]>>>[>>]>
        co 0 0 0 e _1 0 0 c 1 b 1 a 0 d: 1 e 1 f
        Transfer it to temporary cell
        [<<<[<<]<+>>>[>>]>-]
        co 0 0 0 e _1 d 0 c 1 b 1 a 0 0: 1 e 1 f
        Pop extra marker if it exists from the right cells and add one to the left
        >[-]<<+
        co 0 0 0 e _1 d 0 c 1 b 1 a 1: 0 0 e 1 f
        Transfer all left cells over 2 cells
        [<[->>+<<]<]<[->>+<<]
        co 0 0 0 e _1 0: 0 d 1 c 1 b 1: a 0 e 1 f
        Navigate back to normal spot
        <[<]<
    ]
    >-[<<]>
    [left
        Simulated tape looks like:
            a b c: d e f
        co 0 0 0: e _1 0 0 c 1 b 1 a 0 d 1 e 1 f
        Add temporary marker
        [>]>++
        co 0 0 0 e _1 0 2: c 1 b 1 a 0 d 1 e 1 f
        Remove temporary marker and transfer all left cells over two
        [-->[-<<+>>]>]
        co 0 0 0 e _1 c 0 b _1 a _1 0 0: d 1 e 1 f
        Add marker to right cells remove marker from left cells and reset left cell's markers
        +<<-[++<<]<
        co 0 0 0 e _1 c: 0 b 1 a 0 0 1 d 1 e 1 f
        Transfer current cell to to right cells
        [->>>[>>]>+<<<[<<]<]
        co 0 0 0 e _1 0: 0 b 1 a 0 c 1 d 1 e 1 f
        Navigate back to normal spot
        <[<]<
    ]
    Add 8 to reverse checks
    <(8++++++++)>>

    Execute next instruction
    [+<<->>]>
]

```

Interprets the program. The only difference from a normal one is that the input is taken from the beginning of the code section instead of the input.

### Part 6: Halt if return is not 0

```
>>[]

```

Navigate to the ending cell of **your program** and run an infinite loop if the return is not 0. If it is 0, exit the loop and end on that same 0.

## Test Inputs:

Always returns 0 (halts and returns 0)

```
(empty program)

```

Always returns 1 (runs forever)

```
+

```

Returns all input added together, mod 256 (returns 211, so it runs forever)

```
,[[->+<],]>

```

Returns 0 if the last two characters of a code are an infinite loop (`[]`) (**your program** returns 0 when given **my program**, therefore **my program** halts)

```
,[>,]>(9+++++++++)[-<(10++++++++++)>]<[-<-<->>]+<---[[-]>[-]<]<-[[-]>>[-]<<]>+>[-<->]<

```

### Fun Fact for those who are still reading

If the input for this program is the source code of this program, then it will start recursing, repeatedly creating self-interpreters that run this program and then give it the same program again. This gives me some interesting ideas on creating actual recursive programs in brainfuck. Instead of checking the return value and starting an infinite loop as in this question, the return value can be saved and acted upon. A simple example would be a factorial program that goes

```
If cell1 == 0:
    Get input into cell1
If cell1 == 1 or cell1 == 0:
    Return 1
Else:
    Initialise self-interpreter-quine function
    Pass cell1-1 into cell1 of the function
    Run function
    Multiply cell1 by the return value
    Return cell1

```

Of course, this is a completely insane way of coding brainfuck, given that running recursing self-interpreters will increase the runtime exponentially.
> 32 votes

# Answer
# Lazy K, 5891 bytes

````ssk``s``si``s``si`ks``s``si`kk``s``si``s``si`ks``s``si``s``si`ks``s``si`kk`k
s``s``si``s``si`ks``s``si``s``si`ks``s``si`kk`ks``s``si``s``si`ks``s``si`kk``s``
si`ks``s``si``s``si`ks``s``si``s``si`ks`ki``s``si`kk``s``si``s``si``s``si`ks`ki`
`s``si`ks``s``si`kk``s``si``s``si`ks``s``si``s``si`ks``s``si`kk`ks``s``si``s``si
`ks``s``si`kk``s``si`ks``s``si``s``si`ks``s``si``s``si`ks`ki``s``si`kk``s``si``s
``si`ks`ki`kk``s``si`kk`ki``s``si``s``si`ks``s``si`kk`kk``s``si``s``si`ks``s``si
`kk`kk``s``si``s``si`ks``s``si``s``si`ks``s``si`kk`ks``s``si``s``si`ks``s``si`kk
``s``si`ks`ki`kk``s``si``s``si`ks``s``si`kk`kk``s``si``s``si`ks``s``si``s``si`ks
``s``si`kk`ks``s``si``s``si`ks``s``si`kk`kk``s``si``s``si`ks``s``si`kk`ks``s``si
``s``si`ks``s``si`kk``s``si`ks`ki`kk``s``si`kk``s``si``s``si`ks``s``si`kk`kk``s`
`si`ks``s``si`kk``s``si``s``si`ks``s``si``s``si`ks``s``si`kk`ks``s``si``s``si`ks
``s``si`kk`kk``s``si``s``si`ks``s``si`kk`ks``s``si``s``si`ks``s``si`kk``s``si`ks
`ki`kk``s``si`kk`kk``s``si`kk``s``si``s``si`ks``s``si``s``si`ks``s``si`kk`ks``s`
`si``s``si`ks``s``si`kk`kk``s``si``s``si`ks``s``si`kk`ks``s``si``s``si`ks``s``si
`kk``s``si`ks`ki``s``si``s``si``s``si`ks`ks``s``si`ks``s``si``s``si`ks``s``si``s
``si`ks``s``si``s``si`ks``s``si``s``si`ks`ki``s``si`kk``s``si``s``si`ks``s``si``
s``si`ks`ki`ki`kk``s``si`kk`ki``s``si`kk``s``si`kk``s``si`kk`ki``s``si`kk``s``si
`kk`ks``s``si`kk`kk``s``si`kk`kk``s``si``s``si`ks`ki`ki``s``si`kk`kk``s``si``s``
si`ks``s``si`kk`kk``s``si``s``si`ks``s``si``s``si`ks``s``si``s``si`ks``s``si``s`
`si`ks``s``si``s``si`ks``s``si``s``si`ks``s``si``s``si`ks`ki``s``si`kk``s``si``s
``si`ks``s``si`kk``s``si`ks``s``si`kk``s``si``s``si`ks``s``si`kk`kk``s``si``s``s
i`ks``s``si`kk`kk``s``si``s``si`ks``s``si`kk`kk``s``si``s``si`ks``s``si`kk`kk`kk
``s``si``s``si`ks``s``si`kk``s``si`ks``s``si`kk``s``si`ks``s``si`kk``s``si``s``s
i`ks``s``si`kk``s``si`ks``s``si``s``si`ks`ki``s``si`kk``s``si``s``si``s``si`ks``
s``si``s``si``s``si`ks``s``si``s``si`ks`ki`ki``s``si``s``si`ks`ks`ks``s``si``s``
si`ks``s``si`kk`ks`kk``s``si``s``si`ks`ki``s``si``s``si`ks`ki`ki``s``si``s``si`k
s``s``si``s``si`ks``s``si`kk`ks`kk`ki`kk``s``si``s``si`ks``s``si``s``si`ks``s``s
i`kk`ks``s``si``s``si`ks``s``si``s``si`ks``s``si`kk`ks``s``si``s``si`ks``s``si`k
k`kk``s``si``s``si`ks``s``si`kk`ks``s``si``s``si`ks``s``si`kk``s``si`ks``s``si`k
k``s``si``s``si`ks``s``si`kk`ks`kk``s``si``s``si`ks``s``si`kk``s``si`ks`ki`kk``s
``si`kk``s``si``s``si`ks``s``si`kk``s``si`ks`ki`kk``s``si`kk``s``si`kk``s``si``s
``si`ks``s``si``s``si`ks``s``si``s``si`ks``s``si``s``si`ks``s``si``s``si`ks`ki``
s``si`kk``s``si`kk`ki``s``si`kk``s``si`kk``s``si`kk``s``si``s``si`ks`ki``s``si`k
k``s``si``s``si``s``si``s``si`ks``s``si``s``si`ks``s``si`kk`ks`kk`ki``s``si``s``
si`ks``s``si`kk``s``si`ks`ks``s``si`ks``s``si``s``si`ks`ki``s``si``s``si`ks`ks``
s``si`kk`ki``s``si``s``si`ks`ks``s``si``s``si``s``si`ks`ks`ki``s``si``s``si`ks`k
s``s``si``s``si`ks`ks``s``si`kk`ki``s``si`kk``s``si`kk``s``si``s``si`ks`ki``s``s
i`kk``s``si``s``si`ks``s``si``s``si`ks`ki``s``si``s``si`ks`ks``s``si``s``si``s``
si`ks`ks`ki``s``si``s``si`ks`ks``s``si`kk`ki``s``si``s``si`ks`ks``s``si``s``si`k
s``s``si``s``si`ks`ks`ks``s``si``s``si``s``si`ks`ks`ki``s``si``s``si`ks`ks``s``s
i`kk`ki``s``si`kk``s``si``s``si`ks`ki``s``si`kk``s``si``s``si`ks``s``si``s``si`k
s``s``si``s``si``s``si`ks`ks`ki``s``si``s``si`ks`ks``s``si``s``si`ks`ks``s``si`k
k`ki`ks``s``si``s``si`ks``s``si``s``si`ks`ki``s``si``s``si`ks`ks``s``si``s``si``
s``si`ks`ks`ki``s``si``s``si`ks`ks``s``si`kk`ki``s``si``s``si``s``si`ks`ks``s``s
i``s``si`ks`ks`ki``s``si``s``si`ks`ks``s``si`kk`ki``s``si`kk``s``si``s``si`ks``s
``si``s``si`ks``s``si`kk`ks``s``si``s``si`ks``s``si`kk`kk``s``si``s``si`ks``s``s
i`kk`ks``s``si``s``si`ks``s``si`kk``s``si`ks`ki``s``si``s``si`ks``s``si`kk`kk``s
``si``s``si`ks`ki``s``si`kk``s``si``s``si`ks``s``si`kk`ks`kk``s``si`kk`kk``s``si
`kk`ki``s``si`kk`ki``s``si`kk`ki``s``si`kk`ki``s``si`kk`ki``s``si`kk``s``si``s``
si``s``si`ks`ki``s``si`ks``s``si`kk``s``si``s``si`ks``s``si`kk``s``si`ks``s``si`
`s``si`ks`ki``s``si`kk``s``si``s``si``s``si`ks``s``si``s``si`ks`ki`ki``s``si``s`
`si`ks`ki`ki``s``si``s``si`ks``s``si``s``si`ks``s``si`kk`ks`kk`ki`kk``s``si``s``
si`ks`ki`ki``s``si`kk``s``si`kk``s``si``s``si``s``si`ks`ki`ki``s``si``s``si`ks`k
i`ki``s``si`kk``s``si`kk``s``si`kk`ki``s``si``s``si`ks``s``si``s``si`ks``s``si`k
k`ks``s``si``s``si`ks``s``si`kk``s``si`ks`ki``s``si``s``si`ks``s``si`kk``s``si`k
s``s``si``s``si`ks`ki``s``si``s``si`ks``s``si``s``si`ks`ki``s``si``s``si`ks``s``
si``s``si`ks`ki``s``si`kk`ks``s``si`kk`ks``s``si`kk`kk``s``si``s``si`ks``s``si``
s``si`ks``s``si``s``si`ks``s``si``s``si`ks``s``si``s``si`ks``s``si``s``si`ks`ki`
`s``si`kk``s``si``s``si`ks``s``si``s``si`ks``s``si`kk`ks``s``si``s``si`ks``s``si
``s``si`ks``s``si`kk`ks``s``si``s``si`ks``s``si`kk`kk``s``si``s``si`ks``s``si`kk
`ks``s``si``s``si`ks``s``si`kk``s``si`ks``s``si`kk``s``si``s``si`ks``s``si`kk``s
``si`ks``s``si`kk`kk``s``si``s``si`ks``s``si`kk``s``si`ks``s``si`kk`kk``s``si``s
``si`ks``s``si`kk``s``si`ks``s``si`kk`kk``s``si``s``si`ks``s``si`kk``s``si`ks``s
``si`kk`kk``s``si``s``si`ks``s``si`kk``s``si`ks``s``si`kk`kk``s``si``s``si`ks``s
``si`kk`ks``s``si``s``si`ks``s``si`kk``s``si`ks`ki``s``si``s``si`ks``s``si`kk``s
``si`ks``s``si``s``si`ks`ki``s``si`kk`ks``s``si`ks``s``si``s``si`ks`ki``s``si``s
``si`ks``s``si``s``si`ks`ki``s``si`kk`ks``s``si`kk`ki``s``si``s``si`ks``s``si`kk
``s``si`ks`ki`kk``s``si`kk``s``si``s``si`ks``s``si`kk``s``si`ks`ki`kk``s``si`kk`
`s``si`kk``s``si``s``si`ks``s``si``s``si`ks``s``si``s``si`ks``s``si``s``si`ks``s
``si``s``si`ks`ki``s``si`kk``s``si`kk`ki``s``si`kk``s``si`kk``s``si`kk``s``si``s
``si`ks`ki``s``si`kk`ks``s``si`kk``s``si`kk``s``si``s``si`ks`ki``s``si`kk`ki``s`
`si`kk``s``si``s``si`ks`ki``s``si`kk`kk``s``si`kk``s``si``s``si`ks``s``si`kk``s`
`si`ks``s``si``s``si`ks`ki``s``si`kk`kk`kk``s``si`kk`ki``s``si`kk`ki``s``si`kk`k
i``s``si`kk`ki``s``si`kk`ki``s``si`kk``s``si`kk`kii
</code></pre>

Line breaks added for clarity.

This program is written in, and is capable of parsing, only the Unlambda-syntax subset of Lazy K; that is:

```
program ::= "s" | "k" | "i" | "`" program program.

```

It expects input to be encoded in the standard format for Lazy K: an input stream is a pair whose first element is a Church numeral, representing the first byte of the stream, and whose second element is the remaining input stream. However, the *output* is expected to be only a single Church numeral rather than a full output stream.

## The parsing part

If we look at the character codes for the relevant bits of Lazy K syntax, we notice something interesting:

* `s` is 115, or 1 mod 6;
* `k` is 107, or 5 mod 6;
* `i` is 105, or 3 mod 6;
* ``` is 96, or 0 mod 6.

If we assume the input program is part of the relevant subset, we can distinguish application using only a parity test, and then distinguish the combinators from each other using remainder mod 3.

Doing these tests effectively in combinatory logic requires a little cleverness, though.

* **mod 2**: the idea is to find terms `a`, `b`, and `f` such that `f a = b` and `f b = a`, and then call `N f a` and examine the result. Traditionally the Church booleans are used for `a` and `b` and `f` is `not`, but `not` is annoyingly difficult to encode in SKI. Instead, I did an automated search for terms that would work, and it came up with this:
    + `S I K I = I (K I) = K I`;
    + `S I K (K I) = K I (K (K I)) = I`.
* **mod 3**: similarly, we find distinct terms `a`, `b`, `c`, `f` with `f a = b`, `f b = c`, `f c = a`. A search yielded:
    + `S (S I I) K I = I I (K I) = K I`;
    + `S (S I I) K (K I) = K I (K I) (K (K I)) = K (K I)`;
    + `S (S I I) K (K (K I)) = K (K I) (K (K I)) (K ...) = I`.

Given these, we can write a fairly conventional recursive-descent parser:

```
parse : stream -> (term, stream)
parse (c, rest) =
  match (c mod 2)

    0 -> let (f, rest') = parse rest
         let (x, rest'') = parse rest'
         (f x, rest'')

    1 -> ((match (c mod 3)
           0 -> I
           1 -> S
           2 -> K), rest)

```

## The quining part

This is the fun part. One of the most important parts of any quine is figuring out a data format to represent the encoded form of the program. This ends up being the largest source of overhead since it essentially multiplies the program's length.

The representation I went with involves a lambda that substitutes its argument for every application in the encoded term, but leaves combinators unchanged. For example, the SKI-term `(S S) (K I)` would be encoded as:

```
λf. f (f S S) (f K I)

```

In terms of SKI, the encoding looks like this:

```
encode(S) = (K S)
encode(K) = (K K)
encode(I) = (I I)
encode(f x) = S (S I (encode(f))) (encode(x))

```

This encoding introduces 3x overhead for combinators and 7x overhead for applications. There are about half many applications as combinators in any Lazy K term, so this encoding has ~5x overhead. There are other encodings which are more efficient than this. For example, @msullivan's quine uses a representation which exploits the fact that top-level terms are applied together to have just 1.5x overhead. However, this approach has several disadvantages. It supports only the S and K combinators, making the body of the quine more verbose. It relies on going outside of the Unlambda subset of the syntax, so I would need to make the parser more complex. Finally, it lacks a very useful feature of my representation: it can be trivially "interpreted" into the term it represents by passing `I` as the argument, avoiding the need to store both the encoded and decoded form of the quine payload. Nevertheless, the savings from using a more efficient representation like this are so large that it would probably be worth doing.

Finally there is the task of stringifying the encoded quine to obtain the source code and passing it to the parsed input term. For this we need to construct the Church numerals 96, 105, 107, and 115. For golfing purposes I was able to find terms which are much more efficient than the constructions given in the standard library: `96` is reduced from 63 bytes to 45, `105` is reduced from 81 bytes to 49, `107` is reduced from 91 bytes to 65, and `115` is reduced from 89 bytes to 55. I obtained these using alternative representation of numbers which can be easily converted to and from Church numerals. This representation admits much more compact definitions of `succ` and `+`, and only slightly less compact definitions of `*` and `^`.

Also, there is the problem of traversing the encoded form of the program to build up the stringified form. For this, we effectively need `f x y` to be able to distinguish the cases when its arguments are combinators and when its arguments are further applications of `f`. We accomplish this using a helper function:

```
helper(x) = x (K I) (K (K (λt. t foo))) (K (λt. t baz)) (λt. t bar) t

```

This evaluates to `t foo`, `t bar`, and `t baz` when passed `S`, `K`, and `I` as arguments respectively, but you can also pass `(λ a b c d e. something else)` to distinguish applications. This kind of function is unfortunately relatively cumbersome when encoded in SKI, but I haven't found anything better. We use a difference list to accumulate the stringified representations, since it makes it very cheap to append (just function composition) and doesn't require modification to work with infinite streams.

## Further golfing

How to improve this:

* Use a better data representation, even though this comes at the cost of easy interpretation.
* Find a more efficient way to distinguish the `S`, `K`, and `I` combinators. If a better way exists, it's too large for my search program to find it as-is, so I would need to make it more efficient somehow or make assumptions to reduce the search space.
* Find more efficient representations of each of the numbers. 96 in particular feels like it could be improved a lot, although it's probably also too large for the search program.
* Better optimize `parse`, since it has some room for improvement.

The Lazier code used to generate this program can be found here.
> 4 votes

---
Tags: popularity-contest, quine, halting-problem
---