title: Output a Super Mario Image

text:
# Question
Title: Output a Super Mario Image
This is a problem on Luogu OJ. I decided to post it here because on Luogu OJ, many people, including me and my friend, are interested about how to solve this problem within the fewest characters.

Your task is to output the following ASCII-art:

```
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############

```

This is code-golf, so shortest program wins.

# Answer
# Brainfuck, 1347 bytes

Why do i do this to myself

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

```

Try it online!

The "readable" version :

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

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

```
> 26 votes

# Answer
# T-SQL, ~~322 298~~ 288 bytes

```
SELECT CONCAT('',DECOMPRESS(CAST('H4sIAAAAAAACA6WRQYrEIBQF955CqJ0wdf/jjehM2rwOdofUQvIoHj9f65m2UMLRsYNng/4ZQU0NThjUtBFLDXwRBpWIWYfGpCaIRCy5cZswuFVX6U3bOAA73/+8nXYw2368uWwfj3r5MKzfq4W0UHhEQcUBsk0/b9yafllX9P/YpeDu7rVDTF6226WoPpy6bMUmPZ66UH4BHz4rVE8EAAA='as XML).value('.','varbinary(max)')))

```

Uses G-Zip compression built into SQL 2016 and later, along with Base64 encoding, see this tips post for details.

In SSMS, you'll either have to output as text after fiddling with SSMS character limits in settings, or just copy-and-paste the output to the code window:

**EDITS**: Saved 24 bytes with a better compressed string, thanks to @someone; saved 10 bytes with an implicit conversion using `CONCAT`, thanks to @digscoop.
> 16 votes

# Answer
# MarioLANG, ~~3287 3286 3285~~  1771 Bytes

I had to do this for the theme.

```
+>+>.>.>.>.>.>.>.>)>(>.>.>.
+"+".".".".")")".")".".".".
+++........)..).....)......
+++.(.........)...)...(....
+++.......)...)...)).......
+++.(...)...((.......).....
+++.(.....)..(....(...)()..
+++.(.).....)(....((((.()..
+++.....).(.)(.............
+++..(..).....(.....)..))..
+)+)....).).(.(.........)..
+++)..(..(..(..............
+++)...((.(.(......)..(.(..
+++)...((..(.).......)..(..
+++....((.(..).....((.)(...
+++........(.........(..)..
+++..(.)......)......(.....
+++....)................(..
+++......(....(......)...(.
+++....(.(.).)(....).)..)(.
+++......(...)(..(.........
+++........).....(.(.)(..).
+++.....(............)..().
+++.)..)...................
+++..)).....)....(.)..).)).
+++....)..).)............).
+++..............)........(
+++.......)....(...(.......
+++.)))..).....(.(.........
+++(..)..)(.............(..
+++(.....)..)..)......(....
+++(..(...).)..)........).)
+++(..(....(.(.....)..)....
++++(.(...((.(.......(.....
++++.........()....(.(..(..
++++)....))......).........
++++...(..)..)......))...(.
++++)........)..)(..)...)(.
++)+...(..()...))..........
++++(.....(...(....)(.(.().
++++(...).(.....(...(......
++++(........)..().(.((.)..
++++.(.))..((..............
++++.(.....((...)..........
++++.(.)(..((....(.)....((
)+++......................
+)++.)..)..).....).(..).)(
++++.......))..((..(......
++++....((....)..(....(...
++)+.....(.(....)..)..(..)
++++..).((.(.......)......
++++.))...........(.....((
++++.....)).......()......
++++.....)).(.)....)....).
++++.(......(())..........
++++)....(.).....)........
++++.......)..(.(.......()
++++)....)(...(..(.....(..
++++.......(.)(.)......(.(
++++.....()(............).
++++().(..).....(.....))..
++++...()))......)....))()
+!+!.!.!.!.!.!.!.!.!.!.!.!
=#=#=#=#=#=#=#=#=#=#=#=#=#

```

Try it online!

I managed to save 1514 bytes by converting it from the simple straight code below to the 27x64 block above using elevators

```
+++++++++++++++++++++++++++++++++++++++++++++)++++++++++++++++++++++++++++++++)+++++++++++++++++++++++++++++++++++)++++++++++++++++++++++++++++++++++++++++++++++)++++++++++)++++++++++++++++++++++++++++++++++++++++++((((...............))))...........(.(((...............)....)....(.).).(((.............).)..(...).....(..)....).(((.............)...).......(......(..............)...(............)...)).(((................))...........((...............).)...(.(..........).)...(.)).(((...............)..))).(((.......(.................).).(.).(.(..........).).(.).(.)).(((............)....))).......(((......(.............).).(.).(.(..........).).(.).(.)).(((...........))...(.)))...((.))....((.)).(((...)....((..........).)...(.(..........).)...(.)).(((...........))....))..........(((..).....((...........)...(............)...)).(((...........))....))....((((....))))....((.....).(((.............)....(........)....)).(((...........)......(........)......)).((..............................................................)).((.)...(.)......(.).(..)...(.)......(.).(..)...(.)......(.).(..((..................)).)).((...........................................((..................)).)).((.)..(.)....(.)....(..)..(.)....(.)....(..)..(.)....(.)....(.....................)).((..........................................(....).((..........)).)).((.).....(.)......(..).....(.)......(..).....(.)......(.(....).((..........)).)).((..........................................(....).((..........)).)).((.).(.)..(.)....(.)..(..).(.)..(.)....(.)..(..).(.)..(.)....(.)..(.(....).((..........)).)).((..........................................(....)...........
=========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================.

```

Try it online!

~~This is horrible and I'm very sorry.~~ Loops can get really expensive (bytes wise) in MarioLANG if you're not smart about them and also I'd almost lost the will to live by the time I'd got this far so Mario literally just runs in a straight line, first setting 6 memory cells to the correct ASCII values, then switching between them to output in the right order. This can definitely be golfed down further and if you really hate yourself I highly suggest you give it a go.

(Saved one byte by deleting last equals (floor character) since Mario hits the last instruction as he falls even without it and another by realising that he could actually hit two instructions in the fall.)

# 5413 Bytes

```
+++++>)+++++++++)+++++++)++++++)++++++++)+++++++++)++((((((-[!)+))++)++(()...............)............)).(((...............(....(....).(.))))).(((.............(.(..)...(.....)..(....))))).(((.............(...(.......)......)..(((++>-)))............(...(([!)))))).(((................((...........)).....(((++>-)))..........(.(...).(([!)))))).(((...............(..)).((.......).......(((++>-)))..........(.(.).(.).(([!)))))).(((............(....)).......((......)...(((++>-)))..........(.(.).(.).(([!)))))).(((...........((...))(.))...(((.)))....(((.))).((...(....))..........(.(.).(.).)..........(.(.).(.).)))).(((...........((....)))..........((..(.....))...........(...)............(...)))).(((...........((....)))....(....).....(((....))))).(((.....(((++>-)))........(....(([!)))))).(((...(((++>-)))........(......(([!)))))).((((((+++++++>-))........(([!))......)))).((((((+++>-)).(...).(......).(.).(([!)).)))..................(((.)))).((((((+++++++>-))......(([!)).)))..................(((.)))).((((((+++>-)).(..).(....).(....).(([!(+++++>-)))....((([!))))))).((((((+++++++>-))......(([!)))....(.)))..........(((.)))).((((((+++>-)).(.....).(......).(([!)))....(.)))..........(((.)))).((((((+++++++>-))......(([!)))....(.)))..........(((.)))).((((((+++>-)).(.).(..).(....).(..).(([!)))....(.)))..........(((.)))).((((((+++++++>-))......(([!)))....(...........
====="=======================================================#========================================================================================================================================================================="=======================#==================================================="=========================#====================================================="===========================#====================================================="===========================#=================================================================================================================================================================================================================================================================="====================#=================="======================#===================="==============#======================"==========================#=============================================="============#=========================================="==========================#======"============#====================="============#========================================"========================#============================================"============#========================================"============================#============================================"============#==================.
     !                                                       <                                                                                !                       <                                                   !                         <                                                     !                           <                                                     !                           <                                                                                !                    <                  !                      <                    !              <                      !                          <                                              !            <                                          !                          <      !            <                     !            <                                        !                        <                                            !            <                                        !                            <                                            !            <
     #======================================================="                                                                                #======================="                                                   #========================="                                                     #==========================="                                                     #==========================="                                                                                #===================="                  #======================"                    #=============="                      #=========================="                                              #============"                                          #=========================="      #============"                     #============"                                        #========================"                                            #============"                                        #============================"                                            #============"

```

Try it online!

This is a port of The random guy's answer using Dennis's Brainfuck to MarioLANG converter making very minor changes to save a couple of bytes. While it's obviously much longer, it includes more features of the language and better shows how the language works so I thought I'd include it.
> 12 votes

# Answer
# PHP, ~~176~~ 155 bytes

-21 bytes thanks to Ryan Moore's super compressed string.

This version uses raw output of gzdeflate and contains unprintable binary data, so the code itself and TIO link cannot be posted here, but here is a hex dump of it:

```
000000  3c 3f 3d 67 7a 69 6e 66 6c 61 74 65 28 27 a5 91
000010  81 06 04 21 00 44 01 e8 2b e2 01 71 ef ff 3f ef
000020  5c 91 76 f6 64 57 0f 31 c6 98 a6 ea 95 b6 50 c2
000030  03 50 c5 ab 83 0e 47 41 4d 1b 1c d0 a9 e9 86 2c
000040  35 70 62 38 a8 84 cc 38 34 06 35 41 24 64 c9 c5
000050  6d 40 e7 55 5c fd a5 6d fd 00 54 9f 5f 5e b5 4d
000060  40 d5 a7 2f 37 d3 f3 53 ef 1f b3 0e 22 e2 90 2e
000070  14 8e 28 a8 d8 41 b6 ea 73 e3 55 fb df b8 a2 3a
000080  8e ad 4a de 6d ef 0f 16 cd cb ba 9d ca e8 59 eb
000090  b2 8a 9d 3a 6d 5d f8 02 27 29 3b

```

Thanks to @dzaima, here is a TIO which uses bash to create and run this file: Try it online!

This basically reverses the deflate and prints the result. Save it as a binary file then execute it like this: `php mario.php`

---

# PHP, ~~239~~ 216 bytes

-23 bytes thanks to Ryan Moore's super compressed string.

```
<?=gzinflate(base64_decode('pZGBBgQhAEQB6CviAXHv/z/vXJF29mRXDzHGmKbqlbZQwgNQxauDDkdBTRsc0Knphiw1cGI4qITMODQGNUEkZMnFbUDnVVz9pW39AFSfX161TUDVpy830/NT7x+zDiLikC4Ujiio2EG26nPjVfvfuKI6jq1K3m3vDxbNy7qdyuhZ67KKnTptXfgC'));

```

Try it online!

Same as above version, but used base64\_encode on output of `gzdeflate`, so the code is readable and TIO link is available too. This basically reverses the base64 and deflate and prints the result.
> 11 votes

# Answer
# LaTeX, ~~452~~ 448 bytes

Created with bigram replacement (and one trigram) instead of programming a loop to replace multiple consecutive symbols.

```
\newlinechar`+\def~#1{\catcode`#1=13\lccode`~=`#1\lowercase{\def~}}~$#1#2{~#1{#2#2}}~l#1#2#3{~#1{#2#3}}\catcode`#=12$_*$[_$]{ }$^]$!^$<#$><$=>$&=$@.$:@$)-$()$?($/&lx#.$;xl'#@l"<#l`!^l|!]lv#+lc:@lw><lk#:lh`]lg'.lf.#lq#|ld<:lr<@lnfc~s{?)v}la/=li'klj^#l,js\typeout{h [[[+h >:x+` '":.d+` "c.wh"`"+!!:c.h gqgvh <*>"!! ;q;v`>[_*w` ;q;v| @f_*.[.*":|gqgv| :[[_d.| "`"+| :[^[*:+` >!>+| w!w+/&=w+g#cxrnxrnx<?sa"?sikrkkrkk&>va<,kndn<:n#,a<,xi'<.i'<.i'#,a<^=>}

```

# LaTeX, 506 bytes

Most likely there will be a more efficient variant, but this is what I managed to get by hand (no built in compression tools in LaTeX...). I created a small loop to replace consecutive sequences.

```
\def\|{\catcode`}\def~#1{\|#1=13\lccode`~=`#1\lowercase{\def~}}\| =12~@#1#2{\ifnum#1>0#2@{\numexpr#1-1}{#2}\fi}\|#=12~){@3}~({@4}~?{(.}~/{( }~<{@9  }~>{< }~_{>)#}~[{<#).#}~]{<#.#.#}~^{#).#@6.#.#}~!{#@{18}-#}~={@{42}#}~'{?}~&{#..#?#?#}~;{/#@9--#}~:{#@5.#@6.#}~"{#.#..#?#..#}\newlinechar`+\typeout{>/@{12}{*}+>/(#?#.+>  #..)#@5.##?+>  )#@7.@6#) _ _+>@5 @{11}.@5 @2[+>/##*@7#@7 @2]+> (#@7*@6#) @2]+>).#)*.(*.*)#?@2[+>?@9**##@5._ _+>?(*/@5*?+>  (#@8 (#+>@6#@8 @6#+@{62}#+)^!+=!+)&@{20}#+=;+):;+=;+)";+=/@{12}#}

```

Terminal output (of both codes):

```
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdf
latex)
 restricted \write18 enabled.
entering extended mode
(./mariocg.tex
LaTeX2e <2018-12-01>
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
)

```
> 11 votes

# Answer
# Bubblegum, 138 bytes

```
00000000: a591 410a 0321 0003 efbe 6261 6e42 e7ff  ..A..!....banB..
00000010: cf2b b522 6e5a 6cc5 3908 2184 18bd eed4  .+."nZl.9.!.....
00000020: 8912 1e80 2ade 1db4 3b82 9a76 f794 c695  ....*...;..v....
00000030: 6ec8 7205 0e0c 0795 9019 874a 1677 1009  n.r........J.w..
00000040: 5972 717d 4363 2bae bed2 d676 00aa ff5f  Yrq}Cc+....v..._
00000050: 5eb5 0e40 d5df 2f17 e9f1 a99a 1f33 0f22  ^..@../......3."
00000060: e290 2e14 8e28 a8d8 4096 eaf1 c156 fbd7  .....(..@....V..
00000070: b8a2 f663 a992 bded edc1 a279 5ab7 5219  ...c.......yZ.R.
00000080: 3d6b 9d56 b152 a7ad 134f                 =k.V.R...O

```

Try it online!
> 10 votes

# Answer
# Jelly, ~~235~~ 213 bytes

```
“µ!æeıçȷ&#ð%ø&$dɓeñe÷Ɲ$Ƥ&ɓ'¤"' 'dd%dẎeȤdƤƬddƲdƝ‘s2⁴+Ɱ23¤żẎṣjƭƒ“Ç=ÇgƲ'€$fȤeƲ€fƈiÆf¿fÐɦÇ!×Çe2jÑþµþ¿g8i€þµþ½%4Ɲ5Ɲ2fƲ××½Ʋ;#½f¿f½Ʋ5¤6Ʋ€g¬g½i¬ⱮvØØØḳƁḳÞÞÞⱮpœßßßdœ⁾œŒŒŒdœ⁾¤o‘b50U+Ø0U‘Œṙṁ1xⱮ“&ðẏṪ¶ẏ×Ṙ⁷Ƈ⁾1Ẓṁn#’b64¤¤ị“ *#.-”Y

```

Try it online!

Uses a combination of run-length encoding and replacement of common length-2 sequences with a single digit. Does not use any standard compression library like gzip. Overall has 169 bytes of compressed data and 44 of code.

## Explanation

### Step 1: replace values in the data between 17 and 39 with prestored pairs of bytes

```
“µ...Ɲ‘                     | Base-250 integer list 9, 33, 22, 101, 25, 23, 26, 38, 35, 24, 37, 29, 38, 36, 100, 155, 101, 27, 101, 28, 150, 36, 151, 38, 155, 39, 3, 34, 39, 32, 39, 100, 100, 37, 100, 209, 101, 154, 100, 151, 152, 100, 100, 153, 100, 150
       s2                   | Split into twos
             ¤ż             | Zip the following as a nilad with this:
         ⁴                  | - 16
          +Ɱ23               | - Add this to implicit range from 1 to 23
             Ẏ              | Tighten (join outermost lists)
                   ƒ“Ç...o‘ | Reduce using the following, and starting with the base-250 integer list 14, 61, 14, 103, 153, 39, 12, 36, 102, 154, 101, 153, 12, 102, 156, 105, 13, 102, 11, 102, 15, 160, 14, 33, 17, 14, 101, 50, 106, 16, 31, 9, 31, 11, 103, 56, 105, 12, 31, 9, 31, 10, 37, 52, 150, 53, 150, 50, 102, 153, 17, 17, 10, 153, 59, 35, 10, 102, 11, 102, 10, 153, 53, 3, 54, 153, 12, 103, 7, 103, 10, 105, 7, 149, 118, 18, 18, 18, 217, 143, 217, 20, 20, 20, 149, 112, 30, 21, 21, 21, 100, 30, 142, 30, 19, 19, 19, 100, 30, 142, 3, 111
                  ƭ         | - Alternate between:
                ṣ           |   - Splitting
                 j          |   - And joining

```

### Step 2: Run-length decode and convert to string

```
b50                                 | Convert to base 50
   U                                | Reverse order of bytes
    +Ø0                             | Add 0,0
       U                            | Reverse order again (effectively the last three links add in leading zeros where needed)
        ‘                           | Increment by 1
         Œṙ                         | Run length decode
           ṁ            ¤           | Mould like the following as a nilad:
            1xⱮ        ¤            | - 1 repeated each of the following as a nilad:
             “&...#’                |   - Base-250 integer 36418435425519061363927141799858777786
                    b64             |   - Convert to base 64
                         ị“ *#.-”   | Index into " *#.-"
                                 Y  | Join ith newlines

```
> 8 votes

# Answer
# Bash + coreutils + xz, ~~243~~ ~~242~~ 240 bytes

```
base64 -d<<<4AROAJpdABBtAVsJZEAxAEVT46Z4yzQSDRh1V2s3yKKQ3CiFBCqNr55BVH/f7Qz/mkCIrVe+i4qcFSY5BEjUGbKH55TbsFibiXAoQ8LLpf0KeeR/Qj+UVG3Y3+Xx/Xt+0BI+rKPZCnr2NYt5PB4YsQBJeHbN+TCDB9VxVA5l2MZerD23kdk9GwTt9T7j2LGzPwyNGnq9XrJxWS3PWQOEtp8A|xz -qdFraw

```
> 5 votes

# Answer
# JavaScript (Node.js),  ~~265~~  264 bytes

*Saved 1 byte thanks to @Night2*

Deflated.

```
_=>require('zlib').inflateRawSync(Buffer('pVJbDoAwCPvfKZb0b4nc/3jCRAWGOrN+qNiV8litDs2geKqCQQyQZ/inMnS8SpQRKSsYkoYw2la6ESuSpCEcq27IjPt5eDmCXFQ6jCTFl1yqYSW1/tAxzBcvp+9l6BCnJ3eqr6Wmi4H9LoHzLPNYQukd6k04bspjtA345Z7K1QDnPX2O0uKn0QcWnE13b9EoXXE1XeEtWnU12AE','base64'))+''

```

Try it online!

---

# JavaScript (Node.js), 318 bytes

Consecutive string substitutions.

```
_=>[...`L=J00BP
FM1A46E.##3B
2G@;<9#7#:7#8.653*42-1.0 #`].reduce((s,c,i)=>s.split(Buffer([94-i])).join(c+`A= >9SOKQ< <N0#0H<> ?0C5;D3
13:498#653*42-1.0 #`[i]),`?T]=JT29#.\\A[O9\\[3.I?10#?0C779D.?TSYJT0*I#77 UBUJ2=8*I? UBUW3<8*.=.*[YYW9]8Z.K0#?0CK9=4=*9\\272WI7I
F;6I
AX3X3X@HV#@HA>>0L>0L>;2CVR>EZEZPRVRM^0<^0<^#RV462`)

```

Try it online!

---

# JavaScript (ES7), 340 bytes

Crushed.

```
_=>[...'[{+SUPER~Mario!}]'+2**29].reduce((s,c)=>(l=s.split(c)).join(l.pop()),`U15555
U13#9#.~o#739}9~o397.28+S
18PP7.1ii
U13*2#18 a 335E28oa7}5.E.*39ii~P55E#9.8S~PEooE*P~o331+33~21+26r
#RRR00#6#00#
#[3[3[r#6]
9!9!9!]6]
#M3M3M#]6oor331o+9#P0{{{7..8U 6
2222r##E**]oo#0-#}.#!.97#+ iU#7}r2223a#}}U#}}~M}79#7~
8R7!.3E5*P77U11S3#8 3#+o {---[799`)

```

Try it online!

Or here:

```
console.log((

_=>[...'[{+SUPER~Mario!}]'+2**29].reduce((s,c)=>(l=s.split(c)).join(l.pop()),`U15555
U13#9#.~o#739}9~o397.28+S
18PP7.1ii
U13*2#18 a 335E28oa7}5.E.*39ii~P55E#9.8S~PEooE*P~o331+33~21+26r
#RRR00#6#00#
#[3[3[r#6]
9!9!9!]6]
#M3M3M#]6oor331o+9#P0{{{7..8U 6
2222r##E**]oo#0-#}.#!.97#+ iU#7}r2223a#}}U#}}~M}79#7~
8R7!.3E5*P77U11S3#8 3#+o {---[799`)

)())
```
> 4 votes

# Answer
# Keg, ~~2204~~ ~~1012~~ ~~745~~ 722 bytes

```
(35*| )(34*|\*)
(35*| )(4|\#)(4|\.)\#\.
(35*| )\#\.\.(3|\#)(5|\.)\#\#(4|\.)
(76+| )(3|\#)(7|\.)(6|\#)  (2|(34*| )(3|\#))
(82*| )(65+|\.)(5| )(2|(
| )\#(3|\.)\#)
(35*| )\#\#\*(7|\#)(7| )(2|(91+| )\#\.\#\.\#)
(34*| )(4|\#)(7|\*)(6|\#)   (2|(91+| )\#\.\#\.\#)
(65+| )(3|\.)\#(3|\*)\.(4|\*)\.\*(3|\#)(4|\.)(2|(91+| )\#(3|\.)\#)
(65+| )(4|\.)(91+|\*)\#\#(5|\.)(65+| )(3|\#)(34*| )(3|\#)
(65+| )(4|\.)(4|\*)    (5|\*)(4|\.)
     (2|(8| )(4|\#))
   (2|(8| )(6|\#))
(88*2-|\#)
(3|\#(3|\.)\#(6|\.)\#\.\#)\#(92*|\-)\#
(67*1+|\#)(92*|\-)\#
(3|\#\.\.\#(4|\.)\#(4|\.)\#)(54*|\#)
(67*|\#)    \#(91+|\-)\#
(3|\#(5|\.)\#(6|\.)\#)    \#(91+|\-)\#
(67*|\#)    \#(91+|\-)\#
(3|\#\.\#\.\.\#(4|\.)\#\.\.\#)    \#(91+|\-)\#
(67*|\#)    (34*|\#)

```

Try it online!

*Saved 267 bytes thanks to @Sriotchilism O'Zaic, -23 thanks to a bug fix.*

## 1012 byte program

```
(35*| )(34*|\*)\
(35*| )(4|\#)(4|\.)\#\.\
(35*| )\#(2|\.)(3|\#)(5|\.)(2|\#)(4|\.)\
(76+| )(3|\#)(7|\.)(6|\#)(72*| )(3|\#)(34*| )(3|\#)\
(82*| )(65+|\.)(35*| )\#(3|\.)\#(91+| )\#(3|\.)\#\
(35*| )(2|\#)\*(7|\#)(98+| )\#\.\#\.\#(91+| )\#\.\#\.\#\
(34*| )(4|\#)(7|\*)(6|\#)(76+| )\#\.\#\.\#(91+| )\#\.\#\.\#\
(65+| )(3|\.)\#(3|\*)\.(4|\*)\.\*(3|\#)(4|\.)(91+| )\#(3|\.)\#(91+| )\#(3|\.)\#\
(65+| )(4|\.)(91+|\*)(2|\#)(5|\.)(65+| )(3|\#)(34*| )(3|\#)\
(65+| )(4|\.)(4|\*)(4| )(5|\*)(4|\.)\
(67+| )(4|\#)(8| )(4|\#)\
(65+| )(6|\#)(8| )(6|\#)\
(88*2-|\#)\
\#(3|\.)\#(6|\.)\#\.(2|\#)(3|\.)\#(6|\.)\#\.(2|\#)(3|\.)\#(6|\.)\#\.(2|\#)(92*|\-)\#\
(67*1+|\#)(92*|\-)\#\
\#(2|\.)\#(4|\.)\#(4|\.)(2|\#)(2|\.)\#(4|\.)\#(4|\.)(2|\#)(2|\.)\#(4|\.)\#(4|\.)(37*|\#)\
(67*|\#)(4| )\#(91+|\-)\#\
\#(5|\.)\#(6|\.)(2|\#)(5|\.)\#(6|\.)(2|\#)(5|\.)\#(6|\.)\#(4| )\#(91+|\-)\#\
(67*|\#)(4| )\#(91+|\-)\#\
\#\.\#(2|\.)\#(4|\.)\#(2|\.)(2|\#)\.\#(2|\.)\#(4|\.)\#(2|\.)(2|\#)\.\#(2|\.)\#(4|\.)\#(2|\.)\#(4| )\#(91+|\-)\#\
(67*|\#)(4| )(34*|\#)

```

Try it online!

This is just a run-length encoding of the ascii picture but implemented in Keg

## Old program

```
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \*\*\*\*\*\*\*\*\*\*\*\*\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\#\#\#\.\.\.\.\#\.\
\ \ \ \ \ \ \ \ \ \ \ \ \ \#\.\.\#\#\#\.\.\.\.\.\#\#\.\.\.\.\
\ \ \ \ \ \ \ \ \ \ \ \ \ \#\#\#\.\.\.\.\.\.\.\#\#\#\#\#\#\ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\#\#\ \ \ \ \ \ \ \ \ \ \ \ \#\#\#\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \.\.\.\.\.\.\.\.\.\.\.\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\.\.\.\#\ \ \ \ \ \ \ \ \ \ \#\.\.\.\#\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\#\*\#\#\#\#\#\#\#\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \#\.\#\.\#\ \ \ \ \ \ \ \ \ \ \#\.\#\.\#\
\ \ \ \ \ \ \ \ \ \ \ \ \#\#\#\#\*\*\*\*\*\*\*\#\#\#\#\#\#\ \ \ \ \ \ \ \ \ \ \ \ \ \#\.\#\.\#\ \ \ \ \ \ \ \ \ \ \#\.\#\.\#\
\ \ \ \ \ \ \ \ \ \ \ \.\.\.\#\*\*\*\.\*\*\*\*\.\*\#\#\#\.\.\.\.\ \ \ \ \ \ \ \ \ \ \#\.\.\.\#\ \ \ \ \ \ \ \ \ \ \#\.\.\.\#\
\ \ \ \ \ \ \ \ \ \ \ \.\.\.\.\*\*\*\*\*\*\*\*\*\*\#\#\.\.\.\.\.\ \ \ \ \ \ \ \ \ \ \ \#\#\#\ \ \ \ \ \ \ \ \ \ \ \ \#\#\#\
\ \ \ \ \ \ \ \ \ \ \ \.\.\.\.\*\*\*\*\ \ \ \ \*\*\*\*\*\.\.\.\.\
\ \ \ \ \ \ \ \ \ \ \ \ \ \#\#\#\#\ \ \ \ \ \ \ \ \#\#\#\#\
\ \ \ \ \ \ \ \ \ \ \ \#\#\#\#\#\#\ \ \ \ \ \ \ \ \#\#\#\#\#\#\
\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\
\#\.\.\.\#\.\.\.\.\.\.\#\.\#\#\.\.\.\#\.\.\.\.\.\.\#\.\#\#\.\.\.\#\.\.\.\.\.\.\#\.\#\#\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\#\
\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\#\
\#\.\.\#\.\.\.\.\#\.\.\.\.\#\#\.\.\#\.\.\.\.\#\.\.\.\.\#\#\.\.\#\.\.\.\.\#\.\.\.\.\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\
\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\ \ \ \ \#\-\-\-\-\-\-\-\-\-\-\#\
\#\.\.\.\.\.\#\.\.\.\.\.\.\#\#\.\.\.\.\.\#\.\.\.\.\.\.\#\#\.\.\.\.\.\#\.\.\.\.\.\.\#\ \ \ \ \#\-\-\-\-\-\-\-\-\-\-\#\
\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\ \ \ \ \#\-\-\-\-\-\-\-\-\-\-\#\
\#\.\#\.\.\#\.\.\.\.\#\.\.\#\#\.\#\.\.\#\.\.\.\.\#\.\.\#\#\.\#\.\.\#\.\.\.\.\#\.\.\#\ \ \ \ \#\-\-\-\-\-\-\-\-\-\-\#\
\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\ \ \ \ \#\#\#\#\#\#\#\#\#\#\#\#

```

Try it online!

I know this probably won't win any competitions, but hey, it looks nice. Literally just escaping every character and printing it. I mean, it could be golfed, but don't you just love ascii art programs?
> 4 votes

# Answer
# Pyth, 211 bytes

```
Xr9.HC.Z"xÚ]Á	Â@E%Q‚².NŠ[@‚^LI¦°Šñ¾$æ>A¼Ûƒx]Ð£cô 2Ìÿæ?&°sT	M3«DÊÇ‰bÝ/É¬}Ì ÏÞ‘L¦&›¡%®R$èW+…mö>3Ž`!Wr¢“ê0-ü
{*÷KšjÎÇËáÂÏÒm*üúYÓ^	. Õ¯ŽÎ´Ó,æ†]ó« –ÎRäP¨ïB#ª5Cø®Þš?ÇÇ¸z-vxË"<G6"
 .-*#

```

Try it online!

Compression method: Since there's only 6 characters, the space, newline as well as `#.-*`, replace each of these with a letter from `a-f`. Afterwards, run-length encode the whole thing (`aaaaaccc` -\> `5a3c` etc.), then compress using zlib.

```
Xr9.HC.Z"..."<G6"\n .-*#"  # Complete program (last " is implicit)
        "..."              # zlib-compressed string
      .Z                   # decompress
     C                     # read that as a base 256 integer
   .H                      # convert to hex string
 r9                        # run-length decode
X            <G6"\n .-*#"  # translate "abcdef" to "\n .-*#"

```

The compressed string is

```
      _0 _1 _2 _3  _4 _5 _6 _7  _8 _9 _a _b  _c _d _e _f

000_  78 da 5d 8d  c1 09 c2 40  10 45 0b 10  25 51 82 b2
001_  2e 4e 01 8a  5b 40 82 0b  5e 13 4c 01  49 07 a6 07
002_  0b b0 8a 05  f1 be 24 e6  3e 41 bc db  83 78 1f 5d
003_  d0 a3 63 f4  20 32 cc ff  1f e6 3f 26  b0 73 11 54
004_  0e 09 4d 08  33 9d ab 44  0c ca c7 89  62 dd 2f c9

005_  ac 7d cc 20  02 cf de 91  4c a6 26 9b  a1 25 ae 52
006_  07 24 8f e8  57 8f 2b 85  6d f6 3e 07  33 8e 60 21
007_  57 72 a2 93  16 ea 30 2d  fc 0a 7b 2a  f7 4b 9a 6a
008_  ce c7 cb e1  c2 cf d2 6d  2a fc fa 59  d3 5e 09 2e

009_  15 20 d5 af  8e ce b4 d3  2c e6 86 0e  5d f3 ab 20
00a_  96 ce 52 17  04 e4 50 a8  ef 42 0c 1e  23 aa 35 43
00b_  f8 ae de 9a  3f c7 0f c7  b8 7a 01 2d  76 78 cb

```
> 4 votes

# Answer
# Python3, 921 916 752 751 539 534 476 bytes

And here's a mandatory fair version. I used a script to count the individual characters, should be identical:

```
w,s,d,r=' *.#'
m='--'
n=m*5
A=d*2
B=d*3
C=d*4
D=d*5
E=d*6
F=r*2
G=r*3
H=r*4
I=r*6
J=r*42
K=w*10
L=K+w
M=L+w
N=M+w
O=w*15
P=w*4
Q=w*8
R=d+r
S=r+R+R
T=B+r
U=r+T
V=r+A
W=r+d+F+T+E
X=r+C
Y=r+E+F+D
Z=R+A+X+V
a=r+P+r+n+r
b=J+P+r
c=F+A+X+X
e=b+n+r
f=s*12
g=d*7
h=s*3
j=s*4
k=r*62
l=m*9
o=r*11
p=r*21
z='\n'
for i in"OfzOHCrdzNVGDFCzNGgINwGMGzOwDEOUKUzOFsGHNPSKSzMHhjINSKSzLThdjdsGCKUKUzLCjhhFDLGMGzLCjPjsCzNHQHzLIQIzkzUEWWrdFlrzJrlrzVXXccpzezrDYYrEazezrZFZFZazboz":print(end=eval(i))

```

Try it online!

**Courtesy of the awesome guys in the comments that are much better than me!**

And here's the (python3) script for any others who might want to generate some code and are too lazy/efficient to count manually:

```
mario = '''
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
'''

curr_char = ""
count = 0
for i in mario:
    if i == curr_char:
        count += 1
    else:
        if curr_char != '\n':

            if curr_char == ' ':
                curr_char = 'w'
            elif curr_char == '#':
                curr_char = 'r'
            elif curr_char == ".":
                curr_char = "d"
            elif curr_char == "-":
                curr_char = "m"
            elif curr_char == '*':
                curr_char = 's'

            print(curr_char + '*' + str(count), end="+")
        else:
            print(",", end="")

        curr_char = i
        count = 1

```

# Python3 loophole abused, 167 bytes

Since nothing was said about standard loopholes, I'll sneak this one in here while I can. TIO doesn't like urllib for some reason, if anyone knows a site to host the script on please tell me to. Obviously a link shortener could save some bytes, but I didn't want to go down that rabbit-hole any further.

```
from urllib.request import *
import re
print(re.split("</?code>",str(urlopen("https://codegolf.stackexchange.com/q/192715/85978").read()))[1].replace("\\n","\n")[:-1])

```
> 4 votes

# Answer
## Bash + coreutils, ~~269~~ ~~262~~ 261 Bytes

```
base64 -d <<<H4sICLN9e10CA01BUklPAKVSWw6AMAj73ymW9G+J3P94wkQFhjqzfqjYlfJYrQ7NoHiqgkEMkGf4pzJ0vEqUESkrGJKGMNpWuhErkqQhHKtuyIz7eXg5glxUOowkxZdcqmEltf7QMcwXL6fvZegQpyd3qq+lpouB/S6B8yzzWELpHepNOG7KY7QN+OWeytUA5z19jtLip9EHFpxNd2/RKF1xNV3hLVp1tWPaAR8+K1RPBAAA|gunzip

```

A bit trivial - nothing clever happening here. I'm not sure if I'm allowed to use gzip like this. If I'm not I have no doubt someone will shout at me.

(better if I remove pointless spaces/quotes)

Thanks to @manatwork for saving a byte

Try it online!
> 4 votes

# Answer
# C (gcc), ~~322~~ ~~320~~ ~~318~~ 316 bytes

-2 bytes thanks to ceilingcat.

```
f(i,c){for(i=0;c="/<q/TDQAq-QBSERDq-SGV.S,Sq/!K/QCQ*QCQq/R1W/\"QAQAQ*QAQAQq,T7V-QAQAQ*QAQAQq+CQ3A4A1SD*QCQ*QCQq+D:RE+S,Sq+D4$5Dq-T(Tq+V(Vq____RqQCQFQARCQFQARCQFQARocQq__]ocQqQBQDQDRBQDQDRBQDQD_Vq__\\$QjQqQEQFREQFREQFQ$QjQq__\\$QjQqQAQBQDQBRAQBQDQBRAQBQDQBQ$QjQq__\\$\\"[i++];)for(;c--%16;)printf(L" *.#-\n"+c/16-2);}

```

Try it online!
> 4 votes

# Answer
# Perl, ~~422~~ ~~396~~ ~~370~~ ~~366~~ 365 characters

```
print"f c*
f 4#4.#.
d #..3#5.##4.
d 3#7.6#e 3#c 3#
10 b.f #3.#a #3.#
f ##*7#11 2<#.>#a 2<#.>#
c 4#7*6#d 2<#.>#a 2<#.>#
b 3.#3*.4*.*3#4.2<a #3.#>
b 4.a*##5.b 3#c 3#
b 4.4*4 5*4.
d 4#8 4#
b 6#8 6#
3e#
3<#3.#6.#.#>#12-#
2b#12-#
2<#..#4.#4.#>#.2<.#4>.15#
2a#4 #a-#
3<#5.#6.#>4 #a-#
2a#4 #a-#
3<#.#..#4.#..#>4 #a-#
2a#4 c#"=~s/.<(.+?)>/$1x$&/ger=~s/\w+(.)/$1x hex$&/ger;

```

Run-length encoded in 2 steps: consecutive characters and consecutive patterns of multiple characters.

Try it online!
> 3 votes

# Answer
# Bash, 486 bytes

```
a=#.#.#O#.#.#
b=#e#O#e#
c=I#w#
S="Tb
T3f#.
R#d2g1f
R2i5S2Q2
UmT$b
T1*6V$a
Q3]5R$a
Pe#Y.Z.*2fO$b
Pf\`1gP2Q2
PfZI[f
R3M3
P5M5
EEA
#e#h#.1e#h#.1e#h#.1wu#
EDwu#
#d#f#f1d#f#f1d#f#fD
EC$c
#g#h1g#h1g#h#$c
EC$c
#.#d#f#d1.#d#f#d1.#d#f#d#$c
ECI;"
p(){
for((i=$[d-$2];i>0;i--)){ printf "$1";}
}
IFS=
while read -r -d '' -n1 c;do
printf -vd %d "'$c"
[ $d -le 47 ]&&printf "$c"||[ $d -le 69 ]&&p '#' 47||[ $d -le 86 ]&&p ' ' 69||[ $d -le 98 ]&&p '*' 86||[ $d -le 109 ]&&p '.' 98||p '-' 109
done<<<$S

```

Try it online!

The Run-Length Encoded string $S generated by the non-golfed program here: Try it online!

Then variables $a,$b,$c in $S were substituted by manual inspection, and a single back-tick had to be escaped in $S to allow variables to be used.
> 3 votes

# Answer
# PowerShell \+ tar, 265 = 9+256 bytes

This script works with Windows and Linux. The script extracts the output from the tar archive `t` (256 bytes). The `t` should be placed in the same directory as the script.

```
tar xOf t

```

Try it online!

The powershell script to create the tar archive `t`:

```
(@"
               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############
"@) | Set-Content f -Force
tar zcfo t f

```
> 3 votes

# Answer
# Python 3, 551 bytes

```
[print(" *#.-\n"[ord(x[1])-35]*(ord(x[0])-35),end="")for x in ["2#/$$(2#'%'&$%$&$(0#$%%&&%(&%%'&$(0#&%*&)%1#&%/#&%$(3#.&2#$%&&$%-#$%&&$%$(2#%%$$*%4#$%$&$%$&$%-#$%$&$%$&$%$(/#'%*$)%0#$%$&$%$&$%-#$%$&$%$&$%$(.#&&$%&$$&'$$&$$&%'&-#$%&&$%-#$%&&$%$(.#'&-$%%(&.#&%/#&%$(.#'&'$'#($'&$(0#'%+#'%$(.#)%+#)%$(a%$($%&&$%)&$%$&%%&&$%)&$%$&%%&&$%)&$%$&%%5'$%$(N%5'$%$($%%&$%'&$%'&%%%&$%'&$%'&%%%&$%'&$%'&8%$(M%'#$%-'$%$($%(&$%)&%%(&$%)&%%(&$%)&$%'#$%-'$%$(M%'#$%-'$%$($%$&$%%&$%'&$%%&%%$&$%%&$%'&$%%&%%$&$%%&$%'&$%%&$%'#$%-'$%$(M%'#"[x:x+2]for x in range(0,454,2)]]

```

First code golf!

Try it online!
> 3 votes

# Answer
# PHP, ~~608~~ ~~565~~ 557 bytes

Uses GMP, the `5kJvr...` string was created by first using substitutions to convert the original to base ~~5~~ 6, then GMP to convert to base 62.

```
<?=str_replace(range(0,5),str_split("\n-.#* "),gmp_strval(gmp_init('5kJvrGbxP8CrM96cfgUaH1i7H5NT19NW3eSlwbRNO6MzND4omDb8BkvVwnTb1bQtCr6pet0EVt9BQnTuRSwcrL1Gnzs6dMEKAPctFQDrnbXv3eIzlyPYhZpGTwostpxBRJa7bvJvVVgoVjErM9sLKVxa0YkOaOUgMAP6orzz4ZGzb5iQ4qGDDuUOEiKmrcGTHp58srEheAqQSRQE4dOMlauXH4i06DY6tY8gu4maD2BFa68FA7s9sQG9VplFHpecaduYnzLoZgz18xwunIlSkFyIFCUyVMgVxvN7wxtyFZZSAli6DRyV1EobXZtiRa60mYyIZTYL79x190EjhCRAlBM1Lk11FJCeOFkKpAYW8M1hzUpghKA07J31gHpvlkFFKA4dSXvoZwGPbcrGOsmcsi5GAbhB2MIJe9XJGrA7KcSeMfOdxany7HEcesx8oewhtlRHnwxmG8qu8WwA8fjm1S82LMGrq3t',62),6));

```

Run online.
> 2 votes

# Answer
# C, ~~1142~~ ~~1068~~ 1044 bytes

It's not very good, but I made it. Basically, I went line by line and any place one function plus two or more function calls was shorter than the original text, I replaced the text with a function.

```
s=32;a=42;h=35;d=46;m=45;p(c,n){while(n--){putchar(c);}}n(){puts("");}c(){printf("#.#.#");}o(){printf("#...#");}z(){p(m,18);p(h,1);n();}x(char*c){printf("%s",c);}y(){p(h,42);x("    #----------#\n");}main(){p(s,15);p(a,12);n();p(s,15);x("####....#.\n");p(s,13);x("#..###.....##....\n");p(s,13);p(h,3);p(d,7);p(h,6);p(s,14);p(h,3);p(s,12);p(h,3);n();p(s,16);p(d,11);p(s,15);o();p(s,10);o();n();p(s,15);p(h,2);p(a,1);p(h,7);p(s,17);c();p(s,10);c();n();p(s,12);p(h,4);p(a,7);p(h,6);p(s,13);c();p(s,10);c();n();p(s,11);x("...#***.****.*###....");p(s,10);o();p(s,10);o();n();p(s,11);x("....**********##.....");p(s,11);p(h,3);p(s,12);p(h,3);n();p(s,11);x("....****    *****....\n");p(s,13);p(h,4);p(s,8);p(h,4);n();p(s,11);p(h,6);p(s,8);p(h,6);n();p(h,62);n();o();x("......#.##...#......#.##...#......#.##");z();p(h,43);z();x("#..#....#....##..#....#....##..#....#....");p(h,21);n();y();x("#.....#......##.....#......##.....#......#    #----------#\n");y();x("#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#\n");p(h,42);p(s,4);p(h,12);n();}

```

It saves 99 bytes over just using straight printf.

Saved 69 bytes by removing *int* and *void* specifiers, and the *#include \<stdio\>*. Saved another 2 bytes by declaring *i* as global instead of in the *for* loop. Saved another 3 bytes changing printf to putchar in two places. Removed another 21 bytes with changes suggested by @Christian Gibbons: Removed variable declarations at the beginning, changed the *for* loop to a decrementing *while* loop, changed '\n' to 10 in the *n()* function. Saved another 3 bytes changing *putchar(10)* to *puts("")*, courtesy of this answer.

### 1143 bytes

```
main(){printf("               ************\n               ####....#.\n             #..###.....##....\n             ###.......######              ###            ###\n                ...........               #...#          #...#\n               ##*#######                 #.#.#          #.#.#\n            ####*******######             #.#.#          #.#.#\n           ...#***.****.*###....          #...#          #...#\n           ....**********##.....           ###            ###\n           ....****    *****....\n             ####        ####\n           ######        ######\n##############################################################\n#...#......#.##...#......#.##...#......#.##------------------#\n###########################################------------------#\n#..#....#....##..#....#....##..#....#....#####################\n##########################################    #----------#\n#.....#......##.....#......##.....#......#    #----------#\n##########################################    #----------#\n#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#\n##########################################    ############\n");}

```

Try it online here.

### Ungolfed (ish)

```
s=32;a=42;h=35;d=46;m=45; // ASCII indices of (space) * # . - symbols.
p(c,n){ // Prints c, n times.
    while(n--){
        putchar(c);}}
n(){ // Prints a newline.
    puts("");}
c(){ // Prints a piece of the coins. Used 4 times.
    printf("#.#.#");}
o(){ // Prints a piece of the coins, and the ground. Used 5 times.
    printf("#...#");}
z(){ // Prints a piece of the ground. Used twice.
    p(m,18);;p(h,1);n();}
x(char*c){ // Wrapper for printf. Used 10 times.
    printf("%s",c);}
y(){ // Prints a piece of the ground. Used twice.
    p(h,42);x("    #----------#\n");}
main(){
    p(s,15);p(a,12);n();
    p(s,15);x("####....#.\n");
    p(s,13);x("#..###.....##....\n");
    p(s,13);p(h,3);p(d,7);p(h,6);p(s,14);p(h,3);p(s,12);p(h,3);n();
    p(s,16);p(d,11);p(s,15);o();p(s,10);o();n();
    p(s,15);p(h,2);p(a,1);p(h,7);p(s,17);c();p(s,10);c();n();
    p(s,12);p(h,4);p(a,7);p(h,6);p(s,13);c();p(s,10);c();n();
    p(s,11);x("...#***.****.*###....");p(s,10);o();p(s,10);o();n();
    p(s,11);x("....**********##.....");p(s,11);p(h,3);p(s,12);p(h,3);n();
    p(s,11);x("....****    *****....\n");
    p(s,13);p(h,4);p(s,8);p(h,4);n();
    p(s,11);p(h,6);p(s,8);p(h,6);n();
    p(h,62);n();
    o();x("......#.##...#......#.##...#......#.##");z();
    p(h,43);z();
    x("#..#....#....##..#....#....##..#....#....");p(h,21);n();
    y();x("#.....#......##.....#......##.....#......#    #----------#\n");
    y();x("#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#\n");
    p(h,42);p(s,4);p(h,12);n();}

```
> 2 votes

# Answer
# Python3, 557 bytes

Run length encoded, then a few repeated substrings (spaces then three "#", "-" surrounded by blocks, etc) manually extracted. Definitely room for improvement

```
u,v,w,x,y,z="*.-#\n "
t=z*4
s=x+w*18+x
r=t+x+w*10+x+y
q=x+v*3+x+v*6+x+v+x
p=x+v*2+x+v*4+x+v*4+x
o=x+v*5+x+v*6+x
n=x+v+x+v*2+x+v*4+x+v*2+x
m=z*10+x+v+x+v+x
l=z*10+x+v*3+x
print(t*4+u*12+y+z*15+x*4+v*4+x+v+y+z*13+x+v*2+x*3+v*5+x*2+v*4+y+z*13+x*3+v*7+x*6+z*14+x*3+t*3+x*3+y+t*4+v*11+z*5+l*2+y+z*15+x*2+u+x*7+z*7+m*2+y+t*3+x*4+u*7+x*6+z*3+m*2+y+z*11+v*3+x+u*3+v+u*4+v+u+x*3+v*4+l*2+y+z*11+v*4+u*10+x*2+v*5+z*11+x*3+t*3+x*3+y+z*11+v*4+u*4+t+u*5+v*4+y+z*13+x*4+t*2+x*4+y+z*11+x*6+t*2+x*6+y+x*62+y+q*3+s+y+x*42+s+y+p*3+x*20+y+x*42+r+o*3+r+x*42+r+n*3+r+x*42+t+x*11)

```

---

# Python3, 789 bytes

Fun with random number generators. The image is run length encoded, then broken into chunks of 6. The first chunk (indices for the symbol to print) is generated from a pseudo-random number generator. The second is a base64 encoding of the 6 numbers.

```
from random import*
for a,b in zip([24743,129678,6328,31748,115,39591,43781,6080,105810,23721,53737,47694,64624,41381,26725,50462,13767,37213,119081,62980,29054,29054,29054,88178,27000,29054,29054,22423,17293,29054,53737,4887,17293,29054,29054,29054,53737,4887],[4366013200,2167672897,13976478019,12938928579,1328349251,1124376643,18371322817,10754461761,1090785345,1293447436,1241780289,11828203585,1141125187,3240640705,1091310209,11895611659,4479791875,13976490244,6627279364,1106776456,2164547651,2164547651,2164547651,1387008082,1141121089,1141121156,1141121156,1151866180,1157894218,2248429702,1141137477,1151864906,1090785354,2181316674,1141121089,1107562626,1141121092,11889283146]):
    seed(a)
    while b:
        b,i=divmod(b,64)
        print(" \n#-.*"[randrange(6)]*i,end="")

```
> 2 votes

# Answer
# Python, ~~340~~ 378 bytes

I messed up the encoding in the original answer, here's one based on LZW compression. Might revisit my original answer at some point.

```
n=0
for c in'"/AVHF`N.o,>D\\5:{/RD?{C._Q\\%r7,SUOXGh8<}nA^Qddb<=Vb7;L@QPi[XJ65W=p|@<fxMl2+C1gro(x%m"Iz0+B?9d</tYaj.!:6(T#_/5el1Hl{[W&g*A.Oc1*4zf#[{WfLr@Km_jgFkg#1D`&Ik9r\'{M]7c&# X1,U#]=>}JFwVexi7nzbKnS-@-y{IA=l#="EVj=8L`%"9w@zoc9!:q/rT\\OMd]/p^ksiT?P_yj,':n=n*94+ord(c)-32
d=[*' *\n#.-']
s=c=' '
while n:i=n%202;d+=[c+(i>=len(d)and c[0]or d[i][0])];c=d[i];s+=c;n//=202
print(s)

```

Try it online!
> 2 votes

# Answer
## Pure JavaScript 419 bytes (no lib)

Compression (1 step: count each char in hex e.g. `**********` gives `*a`, 2 step: convert two chars like \*1 or #4 to single char witch free ascii code)

```
let d=`               ************
               ####....#.
             #..###.....##....
             ###.......######              ###            ###
                ...........               #...#          #...#
               ##*#######                 #.#.#          #.#.#
            ####*******######             #.#.#          #.#.#
           ...#***.****.*###....          #...#          #...#
           ....**********##.....           ###            ###
           ....****    *****....
             ####        ####
           ######        ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
##########################################    #----------#
#.....#......##.....#......##.....#......#    #----------#
##########################################    #----------#
#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#
##########################################    ############`
c=d.replace(/(.)\1*/g,(m, g)=>g+m.length.toString(16)).replace(/(.)([1-6])/g,(m,g,e)=>  String.fromCharCode(' .#-*'.indexOf(g)*6- -(e-1)+58))

console.log(c.length,c);
```

Decompression

```
c=` f*c
 fICF@
 dFAHDGC
 dH.7K eH cH
:0.b fFBF aFBF
 fGR#7:1F@F@F aF@F@F
 cI*7K dF@F@F aF@F@F
 bBFT@U@RHC aFBF aFBF
 bC*aGD bH cH
 bCU=VC
 dI 8I
 bK 8K
He
FBFEF@GBFEF@GBFEF@GL2F
GbL2F
FAFCFCGAFCFCGAFCFCF5
Ga=F-aF
FDFEGDFEGDFEF=F-aF
Ga=F-aF
F@FAFCFAG@FAFCFAG@FAFCFAF=F-aF
Ga=#c`
console.log(c.replace(/[:-Z]/g,m=>(z=m.charCodeAt(0)-58,' .#-*'[z/6|0]+(1+z%6))).replace(/([ #.\-*])([0-9a-f]+)/g,(m,g,e)=>g.repeat('0x'+e)))
```
> 2 votes

# Answer
# SOGL V0.12, 971 bytes

I simply copied the whole string to the compressor. I realized that the string wasn't compressed a lot.

```
"ξ↔⁴‚σ╔↔æz½↓«ļ;¾⅝↑¶q$+ξρI#↔@≥Β⁄,;∆n2BΡ¾~«n▼og╤iCΘ⌠δZ░∑℮E3č─æ`⅓+↑žS]ķø 'αN²'Q-ω⅞±ž<e⁴Κ№6‼Dfθ∫⅞)i≠Ph╗8B‽`HΔ→┘↓d5∑∫h╤kΖΜY⅞|⌡Σχ¡GΥq«≡─ηe→°~⁹*░κRΝycč□±H⅔b¾℮╗↕Θ*ζΜ9⁵Dæqēυ¦Jn|¼▲ū-⁹¡╗;g²T℮F6u*ε¤3⅜v■└$}Q;▒MKηBqο⁰X╬/Lβ┌I╬č¤¾►'█p¹A0E∑QXγ9§čΡT▒ξ⁾n‚Υ∫æ¤3I-↕æA⁄gTq√šk3>‼μσ¤j:Zk►↓σ¾ņ*∑*╤ΚPn׀æS~3j‚~█fo╔Ε‼■¤υ ρ{¦Oτ◄μ`]ŗS▓κΜ4y║6AΨū0⁽:uMφ^υκ≤&/═;Ο≠№3→⁄Θ±ū<R°ω.cģ²⁴׀Kē~Θ60Εθ^Ε½rA┼═◄⅞║⁶jH²βX8ΓMOšι≤9#$XΚƨ]¶ļA¾⅛x▲Ε|F■¾ƨ(Υ5ΨB[↑√℮⅔α@↓ļ\TB⌠w⅝³βšīηo¤Ω¦∑CTΕņžAh′DαψH?¡ΙO‽HωΕ?○Æ¦Ζ`∙²u   ⁶¾╚iļ⁶Π7⁾ρ℮░;(Ο²9⅔v○⌡⁽¾‽↑┼ξjƧ¬h¼┌Y▲¹ēhμΞ*⁴ā≠cmeeW℮ADC═¬[9išE⅛~№k⅔№lķ¼⅛∆$qΒR┐Γ¦⅔}\Φ‼ΩxøG⁾ΓOŗ⅟zψ;¹]m║░↔═;↑τΩÆΘχW»G∞ΧQT_L  Δ   nē‼№>ζƧρΕ↔Λλ↑EīšÆ↑gWIμū█⁹└Ιf⌡EΘ⁶cυ═<⅜LjΤlτ⅞⅟ΟB╚@░⁽ič-|dΘž⁽Υ■tPp⁵θ╝│⅜v+M8³Τ╝ι░╬¶ū¾oī⅜o╥\VΨΖ6±≡∆hl?ΦģīX╚æ→#%C\aG‛Ι⌠?ΞJ⁄═⁴v°±∫⁸dy►īι׀ģ&χeģ ~xš/L»ψ(Ξ]δ‛ģæ─╗ƨ╚a*‰■Υ□L$.Λ└≈′9ν‚v░¦+ΛξƧΟļBKγ÷Π*IΝ‚ρTGΜ-^gΗ?Æ[ā╤⅓c&►δæ↓°√>R%┘⁵ī╥$J▲kψβ▲Χ╝0ψγαp¾‼~γ!ι⅔_γψ⁄⅝┼═ģÆ⁴A»┼Jλ∆≤š'ΣRΡΩd4¬hAVb¬zbH⁸ωθyV»⁹№ξ╤*°Kν-G[═ζ∙εY↔⁾Xp⁷χ<⁹≈≈┐>°(Æ#¼i┌γδ∫+ευļDET⌡∆═ν<xzΘ⁰⌡hS»ΚKļ⁰G*mε▲GΖλDΗ_Ηx╝⁴ΘλLσ╝ψB~χ[Ν#ΗhΡ\λ2Y∙ψ¤i⌠}λ▒│αξqzP⅜¶²‘

```

Try it Here!
> 2 votes

# Answer
# Vyxal, 368 bytes

```
»æl⟨Ė"†ꜝ¯⅛±ʀ|⟩nǎ@•‛b⇧ǒḞŻḋ⟇P:₇bj⌊Ż↵⌐D:Jẏɖƒ)e⋏&ƈƈ⋎ĖXε4⟇ß„¹≤9=↲tẇ₀†°nẊF°q⋏~kƈxḟ√ẇjaK↔?÷∴4ɽġ⋎?ṅṅ…‹%⅛↵•«⌈0Ǎm ≬Ǎa≠‹E√℅λ'9ø!‟.7¨∴ṗpλ↔3ḋ~€¼↳Ǔ≬⌐p⋎Ȯβε ⁰A:M@ṙR√hŀ⟑$~y?ṫL∩¹W"⌈«½*;⟩↓!j₁½›ȯḢXṀ₆∪ʀ‹≈I∨⁽3Oǔ⟇⁽¬∧0ßṡ₃∵GB÷ɾ‡ḋ5<‛t½«s≬≠꘍‛#‡↑≬Kg`ZµƈÞḂV↑ɾ↑ȯẋ¯⊍CḞ(∵j⌈Ṁ⟇∷⁺ƈġ↓ u₌□⇩ḃ↑↲f⅛:¯J¾ƒl₈€FK≈ĊḢƈεC¹9ΠVG¶Ṡ‟~R∵ĠaBI∆ḃg2eṀ¡Ǒ8µEtṫy+¹₆C3g*/ė¬u
⁽ǐ≠MḊ•T⟇€•sṗSŻjJ₌∴¹Jƛǒ₃uṫż‹↔C∆%ẏ¶⟨⌈"(ṅ∑∆*$Ġ»`#.* -
`τ

```

Try it Online!

Losing to... A lot of stuff.
> 2 votes

# Answer
# Perl with Filter:sh module, 672 bytes

It's long but it is also rather unreadable so I thought it qualifies as a golfing answer...

```
use Filter::sh 'sed "s/S/\" \"/g"';
use Filter::sh 'sed "s/\([0-9]\+\)/x\1 ./g"';
$e="....";$a="#...#$e..#.#";$b="#..#$e#$e#";$c="#$e.#$e..#";$d="#.#..#$e#..#";$f="###";$g="#...#";$h="#.#.#";
print S16"*"12"\n".S16'#'4'.'4"#.\n".S14"#..$f$e.##$e\n".S14$f."."7$f.$f.S13$f.S12"$f\n".S17"."11S14$g.S10"$g\n".S16"##*"."#"7S16$h.S10"$h\n".S13"$f#"."*"7"#"6S12$h.S10"$h\n".S12"...#***.****.*###$e".S9$g.S10"$g\n".S12$e."*"10"##$e.".S10$f.S12"$f\n".S12"$e****    ****$e\n".S14"$f#".S8"$f#\n".S12$f.$f.S8"$f$f\n"."#"62"\n$a$a$a#"."-"18"#\n"."#"43"-"18"#\n$b$b$b"."#"20"\n"."#"42S4"#"."-"10"#\n$c$c$c".S4"#"."-"10"#\n"."#"42S4"#"."-"10"#\n$d$d$d".S4"#"."-"10"#\n"."#"42S4"#"12"\n";

```

Explanation: the filter replaces `S` with `" "` and a number with `x(num) .`, so for example `S14` becomes `" "x14` . In Perl this means "print a space 14 times". Furthermore there is some manual compression for sequences that occur often using variables `$a`-`$h`.
> 1 votes

# Answer
# ///, 363 bytes

```
/~/\/\///J/  ~I/#3~H/#
~G/66~F/EE~E/JJ~D/##~C/55~B/
2~A/BJ~0/93~9/.#~8/D#~7/***~6/#.~5/8#~4/---------~3/...~2/FJ ~1/CCCCCD/2E7777AJ53.6A6.83.9I.A833.5D2J 82 8AJ 333..2EI#FJI#AJD*582EJG#FJG#B 577*5D2JG#FJG#B3#7.7*.*83.FJI#FJI#B3.777*D3..282 8B3.7*E7**3.A5F5B5DF5D
1CC5
II36D3I36D3I36D44H1#44H60096009600.CC5H1E#4-HI.03D3.03D3.03#E#4-H1E#4-HG0.69G0.69G0.69E#4-H1EC5

```

Try it online!

`///` has great string compression capabilities.

`/~/\/\//` from Tips for golfing in ///.
> 1 votes

# Answer
# TlanG ~~528~~ 527 bytes

```
( *11\n)*11'*10>*11>*4\**12,<*13\#*4....\#.,<*12\#..\#*3.*5\#\#.*4#,>*12\#*3.*7\#*6 *13\#*3 *11\#*3#,>*15.*11 *14\#.*3\# *9\#.*3\##,>*14\#\#\*\#*7 *16\#*5<<.<*3.>*5 *7\#*5<<.<*3.#,>*11\#*4\**7\#*6 *12\#*5<<.<*3.>*5 *7\#*5<<.<*3.#,>*10...\#\**10<*7.>*4.>\#*3.*4 *9\#.*3\# *9\#.*3\##,>*10.*4\**10\#\#.*5 *10\#*3 *11\#*3#,>*10.*4\**4 *4\**5.*4#,>*12\#*4 *8\#*4\n>*10\#*20<*14 *8\n\#*62\n(\#.*3\#.*6\#.\#)*3\#\-*18\#\n\#*43\-*18\#\n(\#..\#.*4\#....\#)*3\#*20\n(\#*42 *4\#\-*10\#\n\n)*2'''(\#.*5\#.*6\#)*3 *4\#\-*10\##,,\#*58<*16 *4

```

yay own lang

This is how it works:

```
  <any char>
    - print
  <any char>*<number smaller than 512>
    - print multiple
  (<any string (can contain commands, but no other loops>)*<number smaller than 512>
    - print string multiple times
  \<any command>
    - print the command, dont execute it
  '
    - go up in terminal (must be compatible with terminal, any linux terminal works)
  ,
    - go down in terminal (must be compatible with terminal, any linux terminal works)
  <
    - go left in terminal (must be compatible with terminal, any linux terminal works)
  >
    - go right in terminal (must be compatible with terminal, any linux terminal works)
  #
    - go to start of line in terminal (must be compatible with terminal, any linux terminal works)
  -
    - delete everything behind the cursor (must be compatible with terminal, any linux terminal works)
  \n
    - line break (program line breaks are ignored)

```
> 1 votes

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


title: Turtles All the Way Down

text:
# Question
Title: Turtles All the Way Down
Write a program or function that takes in a positive integer and prints or returns a stack of that many ASCII-art turtles, where each turtle is larger than the one above it.

Specifically, if the input is `1`, the output should be:

```
 __
/,,\o

```

If the input is `2`:

```
  __
o/,,\
 ____
/,__,\o

```

If the input is `3`:

```
   __
  /,,\o
  ____
o/,__,\
 ______
/,____,\o

```

If the input is `4`:

```
    __
  o/,,\
   ____
  /,__,\o
  ______
o/,____,\
 ________
/,______,\o

```

If the input is `5`:

```
     __
    /,,\o
    ____
  o/,__,\
   ______
  /,____,\o
  ________
o/,______,\
 __________
/,________,\o

```

And so on in the same pattern for larger inputs.

**Note that:**

* The head (the `o`) of the bottom turtle is always on the right. The heads of the turtles above then alternate back and forth.
* No lines may have trailing spaces.
* Superfluous leading spaces are not allowed. (i.e. the back of the bottom turtle should be at the start of the line.)
* A single optional trailing newline is allowed.

**The shortest code in bytes wins.**

# Answer
## Batch, 256 bytes

```
@set i=echo
@%i%off
set u=
for /l %%j in (2,2,%1)do call set i=%%i%%
set/af=%1^&1
if %f%==1 %i% __&%i%/,,\o&set u=__
for /l %%j in (2,2,%1)do call:l
exit/b
:l
set i=%i:~0,-2%
%i%  _%u%_
%i%o/,%u%,\
%i% __%u%__
%i%/,_%u%_,\o
set u=__%u%__

```

Note that line 1 has a trailing space and line 4 has two trailing spaces. `i` therefore contains an `echo` command with the appropriate amount of indentation for each turtle. Meanwhile `u` contains the number of underscores in alternate turtles. A leading odd turtle is special-cased and then the rest of the turtles are output in pairs.
> 32 votes

# Answer
# C, 131 bytes

```
i,j;f(n){char _[3*n];memset(_,95,3*n);for(i=n;i--;printf("%*.*s\n%*s/,%.*s,\\%s\n",j+n+1,j+j,_,i,"o"+1-i%2,j+j-2,_,"o"+i%2))j=n-i;}

```

Try it online.

Defines a function that prints the turtles.

Heavily abuses printf's width and precision specifiers to get the spacing and repeating the underscores. Each turtle is printed using a single `printf` call:

```
printf("%*.*s\n%*s/,%.*s,\\%s\n",j+n+1,j+j,_,i,"o"+1-i%2,j+j-2,_,"o"+i%2)

```

I also have a different version that's 144 bytes with whitespace removed:

```
c,i;f(n){for(i=n;i--;){
    char*p=" _\n o/,_,\\o\n";
    int C[]={i+1,c=n+n-i-i,1,i&~1,i%2,1,1,c-2,1,1,1-i%2,1};
    for(c=0;p[c];)C[c]--?putchar(p[c]):++c;
}}

```
> 23 votes

# Answer
# Ruby, 100 bytes

Recursive solution. Try it online!

```
f=->n,i=1{f[n-1,i+1]if n>1;puts' '*i+?_*n*2,"%#{i-1}s/,#{?_*2*~-n},\\"%(i<2?'':'o '[i%2])+' o'[i%2]}

```
> 14 votes

# Answer
# , ~~57, 53~~ 49 bytes

```
i ³_
/,_,\oÀñHyjí_/___
ëPhjI ñdjí___
òkk$x^PXkk

```

Since this contains unprintable characters, here is a hexdump:

```
00000000: 6920 b35f 0a2f 2c5f 2c5c 6f1b c0f1 4879  i ._./,_,\o...Hy
00000010: 6aed 5f2f 5f5f 5f0a eb50 1668 6a49 20f1  j._/___..P.hjI .
00000020: 646a ed5f 5f5f 0af2 6b6b 2478 5e50 586b  dj.___..kk$x^PXk
00000030: 6b                                       k

```

Try it online!

Explanation:

```
i ³_\n/,_,\o<esc>       "Insert the original turtle with one extra underscore

Àñ                      "Arg1 times:
  Hyj                   "  Go the the beginning of the file, and yank a turtle
     í_/___             "  Extend the lenght of every turtle by two
ëP                      "  Move to the beginning of the file again, and paste the turtle we yanked
  <C-v>hjI              "  Move this turtle one to the right
           ñ            "Stop looping.

dj                      "Delete a turtle (since we have one too many)
  í___                  "Make every turtle shorter (since they are all too long)

ò                       "Recursively:
 kk                     "  Move up two lines
   $x                   "  Delete the last character on this line (an 'o')
     ^P                 "  And paste this 'o' at the beginning of the line
       X                "  Remove one space
        kk              "  Move up two lines again

```
> 12 votes

# Answer
## 05AB1E, 45 bytes

```
Lvð¹y-©>×„__y×UXJ,„/,X¨¨„,\J'o®ÉiìëJ}ð®®É-×ì,

```

Try it online
> 12 votes

# Answer
## Perl, 92 bytes

**91 bytes code +1 for `-n`.**

Requires `-E` at no extra cost.

```
for$i(1..$_){say$"x$_._,$v=_ x(--$i*2),_.$/.$"x(--$_-1),$_%2?o:$"x!!$_,"/,$v,\\",$_%2?"":o}

```

### Usage

```
perl -nE 'for$i(1..$_){say$"x$_._,$v=_ x(--$i*2),_.$/.$"x(--$_-1),$_%2?o:$"x!!$_,"/,$v,\\",$_%2?"":o}' <<< 3
   __
  /,,\o
  ____
o/,__,\
 ______
/,____,\o

```

Thanks to @Dada for -9 bytes with his re-work!
> 11 votes

# Answer
# Cheddar, 105 bytes

```
n->(|>n).map(i->(1-i%2)*"o"+"\\,"+(n-i-1)*"__"+",/"+i%2*"o"+i/2*"  "+"\n"+(n-i)*"__"+(i+1)*" ").vfuse.rev

```
> 10 votes

# Answer
## Retina, ~~97~~ ~~91~~ 88 bytes

Byte count assumes ISO 8859-1 encoding.

```
.+
  $&$*_$&$*_o
+`^( *?)(.)__(_+)(.)
$1 $4$3$2¶$&
 (.)__(_*) ?
  __$2¶$%`$1/,$2,\
Rm`^

```

Try it online!
> 10 votes

# Answer
# C, ~~328~~ ~~238~~ ~~234~~ 215 bytes:

```
B;M(w,j,R){j=w;if(j<=B){char b[j*2-1],k[j*2+1];b[j*2-2]=k[j*2]=0;memset(b,95,j*2-2);memset(k,95,j*2);R=(B+1-j)%2;printf("%*s\n%*s/,%s,\\%s\n",j*2+B+1-j,k,B-j,R?"":"o",b,R?"o":"");j++;M(j);}}main(){scanf("%d",&B);M(1);}

```

A recursive implementation using a lot of string formatting and the builtin `memset` function. Will try and golf this more over time as much as I can.

C It Online! (Ideone)
> 6 votes

# Answer
# Python 2, 116 Bytes

```
m=input()
for i in range(m):r=m-i;b=r%2;h='o';a='__';u=i*a;s=' '*r;print s+u+a+'\n'+s[:b-2]+h*-~-b+"/,"+u+",\\"+b*h

```
> 6 votes

# Answer
# TSQL, 189 bytes

Now with input acceptance - thanks to @PatrickRoberts

```
DECLARE @i INT=##i##,@ INT=0a:PRINT SPACE(@i-@)+REPLICATE('__',@+1)+'
'+SPACE((@i-@-1)/2*2)+IIF((@i-@-1)%2=1,'o/,','/,')+REPLICATE('__',@)+IIF((@i-@-1)%2=0,',\o',',\')SET
@+=1IF @i>@ GOTO a

```

**Fiddle**
> 6 votes

# Answer
# **R**, 150 bytes

```
a=function(x,y=1){d=x-y;t=d%%2;cat(rep(" ",d+1),rep("_",2*y),"\n",rep(" ",d-t),"o"[t],"/,",rep("_",2*y-2),",\\","o"[!t],"\n",sep="");if(y<x)a(x,y+1)}

```

more cleanly (adds a byte)

```
a=function(x,y=1){
     d=x-y
     t=d%%2
     cat(rep(" ",d+1),rep("_",2*y),"\n",rep(" ",d-t),"o"[t],"/,",rep("_",2*y-2),",\\","o"[!t],"\n",sep="")
     if(y<x)a(x,y+1)
}

```

Basic structure recursively calls itself --telling itself both the final number to be called and the current level. Starts with a default for y=1, so it only needs one variable for initial call. Quickly defines two values that are frequently used. Then it just repeats everything the necessary number of times.

```
"o"[t],"o"[!t]

```

Each of these implicitly test whether to add the head to right or left and place it appropriately.
> 6 votes

# Answer
# Python, ~~137~~ ~~120~~ ~~113~~ 110 bytes

```
m=input()
for i in range(m):p=m-i;b=p%2;print' '*p+'__'*-~i+'\n'+' '*(p-2+b)+'o'*-~-b+'/,'+'__'*i+',\\'+'o'*b

```

Ungolfed:

```
m=input()
for i in range(m):
  p=m-i                              // Abstract m-i for a few bytes
  b=p%2                              // Determines every other turtle from bottom

  print' '*p + '__'*-~i + '\n' +    // The top of the turtle
       ' '*(p-2+b) +                // Leading spaces (-1 for every other turtle)
       '0'*-~-b +                   // Add a leading head to every other turtle
       '/,'+'__'*i +                // Body of the turtle
       ',\\'+'0'*b                  // Add a trailing head to every other turtle

```

The heads were hard.
> 4 votes

# Answer
## Java 1.7, 238 bytes

A set of two functions: first iterates over input (# of turtles), second facilitates in constructing a sequence of repeated characters recursively (i.e. the leading spaces, the back and belly of the turtles).

```
String f(int n){String s="";for(int i=-1,x=-2;++i<n;){int m=(i+n)%2;s+=r(' ',n-i)+r('_',i*2+2)+"\n"+r(' ',n-i-(m==1?1:2))+(m==0?"o":"")+"/,"+r('_',x+=2)+",\\"+(m==1?"o":"")+"\n";}return s;}String r(char c,int n){return n>0?c+r(c,--n):"";}

```

Ungolfed:

```
class C {
    public static void main(String[] a) {
        System.out.println(new T().f(1));
        System.out.println(new T().f(2));
        System.out.println(new T().f(3));
        System.out.println(new T().f(4));
        System.out.println(new T().f(5));
    }

    static class T {

        String f(int n) {
            String s = "";
            for (int i = -1, x = 0; ++i < n; x+=2) {
                int m = (i + n) % 2;
                s += r(' ', n - i) + r('_', i * 2 + 2) + "\n" + r(' ', n - i - (m == 1 ? 1 : 2)) + (m == 0 ? "o" : "") + "/," + r('_', x) + ",\\" + (m == 1 ? "o" : "") + "\n";
            }
            return s;
        }

        String r(char c, int n) {
            return n > 0 ? c + r(c, --n) : "";
        }

    }

}

```

Run it! (Ideone)

I've assumed it's okay to exclude the class definition from the byte count.

I may be able to golf this a little further by reversing the iteration order of the loop (build from bottom turtle up) and/or by going fully recursive like some of the other answers.

*Note to self: Java really lacks a built-in shorthand to repeat n characters...*
> 4 votes

# Answer
# F#, ~~218~~ ~~207~~ ~~202~~ ~~196~~ 187 bytes.

Shaved most of these bytes by inlining variables

```
let R=String.replicate
let t n=let rec L i r k=if i<n then L(i+1)(R(k+i%2+1)" "+R((n-i)*2)"_"+"\n"+R k" "+R(i%2)"o"+"/,"+R(n*2-i*2-2)"_"+",\\"+R(1-i%2)"o"+"\n"+r)(k+i%2*2)else r in L 0""0

```

The logic is shamelessly stolen from this Python answer

Try it online.
> 3 votes

# Answer
# CJam, 88 bytes

```
ri_[S\_'_*_+N+\O\"/,"\('_*_++','\+'o]\({_[(S+\(2>\(S\+)'O^c+\(-2<\(\('o\{;O}&\;]}*]-1%N*

```

Makes the biggest turtle first (because otherwise what would every other turtle stand on?), then gradually reduces the size until the smallest one is made. Works for any integer larger than 0.

Try it online!
> 3 votes

# Answer
## Python 2, 147 bytes

```
n=input()
s=' ';r=[];i=k=0
while i<n:a=i%2;r=[s*k+s*a+s+'_'*(n-i)*2+s,s*k+'o'*a+'/,'+'_'*(n-i-1)*2+',\\'+'o'*(1-a)]+r;k+=a*2;i+=1
print'\n'.join(r)

```

Try it online
> 2 votes

# Answer
## Python 2.7, ~~255~~ ~~238~~ 236 bytes

Even though this loses to both of the other Python 2 solutions, I liked my recursive approach:

```
def r(s,p):
 for(a,b)in p:s=a.join(s.split(b))
 return s
def t(w):
 i='_'*2*w;s='\n __%s\n/,%s,\o'%(i,i)
 if w:s=r(t(w-1),[('\n ','\n'),('Z/',' /'),('\\Z\n','\\\n'),(' /','o/'),('\\','\\o'),('o','Z')])+s
 return s
print t(input()-1)[1:]

```

edit1: dropped a few bytes by eliminating some replacements

edit2: shaved 2 bytes by saving the underscores as a variable
> 2 votes

# Answer
## Python 2.7, ~~139~~ ~~114~~ ~~113~~ 130 bytes

I also liked Iguanodon's recursive approach so here's a slightly shorter attempt.

```
def t(n):
 if n>1:t(n-1)
 a=i-n;b=(a+1)%2;print' '*(a+1)+'__'*n+'\n'+' '*(a-1+b)+'o'*(not b)+'/,'+'__'*(n-1)+',\\'+'o'*b
i=input()
t(i)

```

**EDIT**

A mighty ~~25~~ ~~26~~ 9 bytes golfed due to some fantastic tips from Destructible Watermelon. Many thanks! ~~Think it may be the shortest Python answer now :-)~~

```
def t(n):
 if n>1:t(n-1)
 a=i-n;b=-~a%2;print' '*-~a+'__'*n+'\n'+' '*(a-1+b)+'o'*-~-b+'/,'+'__'*~-n+',\\'+'o'*b
i=input()
t(i)

```
> 1 votes

# Answer
# PowerShell, ~~105~~ ~~100~~ ~~97~~ ~~87~~ ~~85~~ 84 bytes

<sup>-21 bytes thanks to mazzy, the mad man</sup>

```
"$args"..1|%{' '*$_--+($m='__'*$i++)+'__'
' '*($_-$_%2)+("/,$m,\o","o/,$m,\")[$_%2]}

```

Try it online!

Cleverly shifts variables using `$_--` to avoid using repeated `($_+1)` blocks to save several bytes. It also converts the single argument to a string which is then cast to an int when used in a range to iterate over through the number of turtles. Biggest trick is now having the 2nd level of a turtle's spacing only increase every other row by subtracting `$_%2` (i.e. 0 if even, 1 if odd) from the current row\_count.

Otherwise, it's a lot of index math to get proper `_` and  counts, including a lag counter in the form of `$i++`, and now only a single list index to put the head on the correct side.
> 1 votes

# Answer
# ES6 (JavaScript), 140 bytes

**Code**

```
T=(i,h=0,p=1,R="repeat")=>(i>1?T(i-1,~h,p+1)+"\n":"")+" "[R](p)+'--'[R](i)+"\n"+" "[R](p-1+h)+(h?"o":"")+"/,"+'__'[R](i-1)+",\\"+(!h?"o":"")

```

**Test**

```
console.log(T(5));

     --
    /,,\o
    ----
  o/,__,\
   ------
  /,____,\o
  --------
o/,______,\
 ----------
/,________,\o

```
> 0 votes

# Answer
# Canvas, 26 bytes

```
╷_×,×ｌ_×∔/×║o×⇵↔⁸¹－［  ×↔｝］

```

Try it here!
> 0 votes

# Answer
# Vyxal, 62 bytes

```
(⁰nεð*nd⇧\_*+,⁰nε⇩ð*⁰nε₂[\o|⁰‹n=[¤|ð]]‛/,nd\_*‛,\⁰nε₂[|\o+]Wṅ,

```

Try it Online!

Many turtles.
> 0 votes

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


title: Convert Gemtext to HTML

text:
# Question
Title: Convert Gemtext to HTML
Gemtext is a very simple markup format used by the alternative web protocol Gemini. Write a Gemtext to HTML converter.

From the Wiki:

> A line of text is a paragraph, to be wrapped by the client. It is is independent from the lines coming before or after it.
>
> A list item starts with an asterisk and a space. Again, the rest of the line is the line item, to be wrapped by the client.
>
> A heading starts with one, two, or three number signs and a space. The rest of the line is the heading.
>
> A link is never an inline link like it is for HTML: it’s simply a line starting with an equal-sign and a greater-than sign: “=\>”, a space, an URI, and some text. It could be formatted like a list item, or like a paragraph. Relative URIs are explicitly allowed.
>
> Example:
>
> ```
> # This is a heading
> This is the first paragraph.
> * a list item
> * another list item
> This is the second paragraph.
> => http://example.org/ Absolute URI
> => //example.org/ No scheme URI
> => /robots.txt Just a path URI
> => GemText a page link
>
> ```

This should produce this HTML tree (just the equivalent tree, not the exact formatting):

**EDIT** you don't need the `<ul>` tags to produce valid HTML

```
<h1>This is a heading</h1>
<p>This is the first paragraph.</p>
<li>a list item</li>
<li>another list item</li>
<p>This is the second paragraph.</p>
<a href="http://example.org/">Absolute URI</a>
<a href="//example.org/">No scheme URI</a>
<a href="/robots.txt">Just a path URI</a>
<a href="GemText">a page link</a>

```

All text must pass through. All of `<>"&` should be converted to HTML entities, even if they don't confuse browsers, to be safe

**EDIT**: For the sake of this question, you don't have to do 2nd and 3rd level headings

This is so the shortest code in bytes wins

# Answer
# Perl 5 (`-p`), 132 bytes

```
s,^((#)|(\*)|=> (\S+)|) *(.*?) *$,$t=$2?h1:$3?li:$4?a:p;"<$t".($4&&qq( href="$4")).">".($5=~s~[<>"&]~"&#".(ord$&).";"~ger)."</$t>",e

```

Try it online!

Another 132 bytes

```
s-^([#*]|=> (\S+)|) *(.*?) *$-"<".($t=(p,a,li,h1)[ord($1)%4]).($2&&qq( href="$2")).">".($3=~s~[<>"&]~"&#".(ord$&).";"~ger)."</$t>"-e

```
> 3 votes

# Answer
# Java + Android, ~~227~~ 206 bytes

```
l->l.map(s->android.text.Html.escapeHtml(s).replaceAll("^# (.*)","<h1>$1</h1>").replaceAll("^\\* (.*)","<li>$1</li>").replaceAll("^=> (.*?) (.*)","<a href='$1'>$2</a>").replaceAll("^[^<].*","<p>$0</p>"))

```

Accepts a `Stream` of lines as input and returns a `Stream` of lines.

Try it online!

*Saved 21 bytes thanks to Olivier Grégoire*

## Explanation

```
l->l.map(
   s->android.text.Html.escapeHtml(s) //Escape line using Android utility class
   .replaceAll("^# (.*)","<h1>$1</h1>")
   //Match headers
   .replaceAll("^\\* (.*)","<li>$1</li>")
   //Match list items
   .replaceAll("^=> (.*?) (.*)","<a href='$1'>$2</a>")
   //Match links (> is > after being escaped)
   .replaceAll("^[^<].*","<p>$0</p>")
   //If string does not start with <, then nothing has been replaced,
   //so enclose entire line in paragraph element
)

```
> 3 votes

# Answer
# Retina 0.8.2, ~~104~~ 103 bytes

```
&
&
"
"
>
>
<
<
m`^
<p>
p>(#+)
h$.1>
p>\*
li>
p>=> (\S+)
a href="$1">
<(\w+).*
$&</$1>

```

Try it online! Works with multiple headers. Edit: Saved 1 byte thanks to @OlivierGrégoire. Explanation:

```
&
&
"
"
>
>
<
<

```

HTML encode everything.

```
m`^
<p>

```

Assume each line is a paragraph.

```
p>(#+)
h$.1>
p>\*
li>
p>=> (\S+)
a href="$1">

```

Fix up headings, lists and links.

```
<(\w+).*
$&</$1>

```

Add closing tags.
> 3 votes

# Answer
# sed 4.2.2, 160 bytes

```
s!&!&!g
s!<!\<!g
s!>!\>!g
s!"!\"!g
ta
:a
s!^*\(.*\)!<li>\1</li>!
s!^#\(.*\)!<h1>\1</h1>!
s!=> \([^ ]*\)\(.*\)!<a href="\1">\2</a>!
t
i<p>
a</p>

```

Try it online!
> 1 votes

# Answer
# JavaScript (Node.js), ~~243 215 210 194 193~~ 191 bytes

```
n=>n.split`
`.map(e=>`<${t={'#':'h1','*':'li','=>':'a'}[(s=e.split` `)[0]]||'p'}${a=t<'b'?` href="${s[1]}"`:''}>${s.slice(2-!a).join` `.replace(/./g,c=>`&#${Buffer(c)[0]};`)}</${t}>`).join`
`

```

Try it online!

As with most of my longer answers, I will golf this gradually.

Produces unreadable HTML, but still containing the same text. If this is disallowed, let me know and I will roll it back.

*-16 bytes thanks to @A Username*
> 1 votes

# Answer
# AWK, 171 bytes

```
awk '{if($1=="#"){$1="<h1>";$0=$0"</h1>"}else if($1=="*"){$1="<li>";$0=$0"</li>"}else if($1=="=>"){$1="<a href=\""$2"\">";$0=$0"</a>"}else{$1="<p>";$0=$0"</p>"}{print$0}}'

```

I'm learning AWK so probably can be done better.
Bugs:

* There are spaces after the opening tags
* Doesn't remove the URL (I've tried doing `$2=""`, but it breaks the lines)
> 0 votes

---
Tags: code-golf, string
---