title: Print the Periodic Table

text:
# Question
Title: Print the Periodic Table
Your challenge is to print/output/return this text:

```
 _____                                                                                _____
|  1  |                                                                                |  2  |
|  H  |                                                                                |  He |
|_____|_____                                                             _____________________________|_____|
|  3  |  4  |                                                           |  5  |  6  |  7  |  8  |  9  |  10 |
|  Li |  Be |                                                           |  B  |  C  |  N  |  O  |  F  |  Ne |
|_____|_____|                                                           |_____|_____|_____|_____|_____|_____|
|  11 |  12 |                                                           |  13 |  14 |  15 |  16 |  17 |  18 |
|  Na |  Mg |                                                           |  Al |  Si |  P  |  S  |  Cl |  Ar |
|_____|_____|___________________________________________________________|_____|_____|_____|_____|_____|_____|
|  19 |  20 |  21 |  22 |  23 |  24 |  25 |  26 |  27 |  28 |  29 |  30 |  31 |  32 |  33 |  34 |  35 |  36 |
|  K  |  Ca |  Sc |  Ti |  V  |  Cr |  Mn |  Fe |  Co |  Ni |  Cu |  Zn |  Ga |  Ge |  As |  Se |  Br |  Kr |
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
|  37 |  38 |  39 |  40 |  41 |  42 |  43 |  44 |  45 |  46 |  47 |  48 |  49 |  50 |  51 |  52 |  53 |  54 |
|  Rb |  Sr |  Y  |  Zr |  Nb |  Mo |  Tc |  Ru |  Rh |  Pd |  Ag |  Cd |  In |  Sn |  Sb |  Te |  I  |  Xe |
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
|  55 |  56 |  57 \  72 |  73 |  74 |  75 |  76 |  77 |  78 |  79 |  80 |  81 |  82 |  83 |  84 |  85 |  86 |
|  Cs |  Ba |  La /  Hf |  Ta |  W  |  Re |  Os |  Ir |  Pt |  Au |  Hg |  Tl |  Pb |  Bi |  Po |  At |  Rn |
|_____|_____|_____\_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
|  87 |  88 |  89 / 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 |
|  Fr |  Ra |  Ac \  Rf |  Db |  Sg |  Bh |  Hs |  Mt |  Ds |  Rg |  Cn |  Nh |  Fl |  Mc |  Lv |  Ts |  Og |
|_____|_____|_____/_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|

                  ____________________________________________________________________________________
                  \  58 |  59 |  60 |  61 |  62 |  63 |  64 |  65 |  66 |  67 |  68 |  69 |  70 |  71 \
                  /  Ce |  Pr |  Nd |  Pm |  Sm |  Eu |  Gd |  Tb |  Dy |  Ho |  Er |  Tm |  Yb |  Lu /
                  \_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____\
                  /  90 |  91 |  92 |  93 |  94 |  95 |  96 |  97 |  98 |  99 | 100 | 101 | 102 | 103 /
                  \  Th |  Pa |  U  |  Np |  Pu |  Am |  Cm |  Bk |  Cf |  Es |  Fm |  Md |  No |  Lr \
                  /_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____/

```

### Rules:

* The empty line count between the two parts can be any amount (including 0)
* Each line can have prepending and appending spaces as long as the two parts look correctly and the second part is indented at least one space more than the first one.
* You may have appending/prepending newlines and/or spaces.
* You may not use tabs for spacing (as long as there isn't an interpreter which replaces them correctly with spaces).
* Because of a mistake of mine, you can choose to use  `______ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____`  as the 1st line of the second part.

### Data:

you can use this text as a reference (but not as input):
Contents: symbol, atomic number, group, period groups 8 & 9 and periods 4-17 are used for the second part.

```
H 1 1 1
He 2 18 1
Li 3 1 2
Be 4 2 2
B 5 13 2
C 6 14 2
N 7 15 2
O 8 16 2
F 9 17 2
Ne 10 18 2
Na 11 1 3
Mg 12 2 3
Al 13 13 3
Si 14 14 3
P 15 15 3
S 16 16 3
Cl 17 17 3
Ar 18 18 3
K 19 1 4
Ca 20 2 4
Sc 21 3 4
Ti 22 4 4
V 23 5 4
Cr 24 6 4
Mn 25 7 4
Fe 26 8 4
Co 27 9 4
Ni 28 10 4
Cu 29 11 4
Zn 30 12 4
Ga 31 13 4
Ge 32 14 4
As 33 15 4
Se 34 16 4
Br 35 17 4
Kr 36 18 4
Rb 37 1 5
Sr 38 2 5
Y 39 3 5
Zr 40 4 5
Nb 41 5 5
Mo 42 6 5
Tc 43 7 5
Ru 44 8 5
Rh 45 9 5
Pd 46 10 5
Ag 47 11 5
Cd 48 12 5
In 49 13 5
Sn 50 14 5
Sb 51 15 5
Te 52 16 5
I 53 17 5
Xe 54 18 5
Cs 55 1 6
Ba 56 2 6
La 57 3 6
Hf 72 4 6
Ta 73 5 6
W 74 6 6
Re 75 7 6
Os 76 8 6
Ir 77 9 6
Pt 78 10 6
Au 79 11 6
Hg 80 12 6
Tl 81 13 6
Pb 82 14 6
Bi 83 15 6
Po 84 16 6
At 85 17 6
Rn 86 18 6
Fr 87 1 7
Ra 88 2 7
Ac 89 3 7
Rf 104 4 7
Db 105 5 7
Sg 106 6 7
Bh 107 7 7
Hs 108 8 7
Mt 109 9 7
Ds 110 10 7
Rg 111 11 7
Cn 112 12 7
Nh 113 13 7
Fl 114 14 7
Mc 115 15 7
Lv 116 16 7
Ts 117 17 7
Og 118 18 7
Ce 58 4 8
Pr 59 5 8
Nd 60 6 8
Pm 61 7 8
Sm 62 8 8
Eu 63 9 8
Gd 64 10 8
Tb 65 11 8
Dy 66 12 8
Ho 67 13 8
Er 68 14 8
Tm 69 15 8
Yb 70 16 8
Lu 71 17 8
Th 90 4 9
Pa 91 5 9
U 92 6 9
Np 93 7 9
Pu 94 8 9
Am 95 9 9
Cm 96 10 9
Bk 97 11 9
Cf 98 12 9
Es 99 13 9
Fm 100 14 9
Md 101 15 9
No 102 16 9
Lr 103 17 9

```

Built-ins that give any info about the periodic table of elements are allowed but should be viewed separately from non-built-in solutions.
The shortest code per language wins!

# Answer
> 12 votes
# Bubblegum, 535 bytes

```
0000000: e0 0c 4a 02 0f 5d 00 10 17 f0 84 1b a9 df 70 5a  ..J..]........pZ
0000010: a9 c3 a0 9d ad 4f 8b 91 5d a2 33 5c b1 1d 4d 48  .....O..].3\..MH
0000020: 0d 80 c4 80 7f da b5 6f 8a 4a 45 20 34 51 d7 2c  .......o.JE 4Q.,
0000030: bc 47 4c ea c5 45 24 db a1 3d 46 42 e0 c8 51 ed  .GL..E$..=FB..Q.
0000040: b6 b8 2b fb 42 dd 7b 44 bc e2 bf a8 c8 80 be 8a  ..+.B.{D........
0000050: 30 2b e1 c7 39 c6 41 30 36 c6 c2 93 0b b2 ac 42  0+..9.A06......B
0000060: 06 5b bd b7 f9 40 11 9e 57 78 ff 0f 8a 45 f8 d7  .[...@..Wx...E..
0000070: b9 ea 6c 8a 6c e5 bf bb 9c f5 18 db 98 85 13 cc  ..l.l...........
0000080: d3 a8 38 9c 55 fe b2 f1 31 1d e0 0e 67 84 b6 48  ..8.U...1...g..H
0000090: 8e 68 2a 8a c6 99 0a 13 1b 10 f0 b5 e2 e0 43 02  .h*...........C.
00000a0: 6f 52 b0 3e d5 27 a9 eb a4 99 4e b2 c2 8b 51 49  oR.>.'....N...QI
00000b0: 9b 7e 46 99 22 31 4f 8c 70 6d 16 b4 a7 79 01 08  .~F."1O.pm...y..
00000c0: 42 01 a8 af 98 d1 38 d3 77 35 c9 3f fc f5 ae 88  B.....8.w5.?....
00000d0: 47 be 91 a0 ab ac ab b7 04 9a fc 81 60 92 61 a1  G...........`.a.
00000e0: 54 f9 92 46 2f bd 70 20 ba dc 29 63 35 29 c4 48  T..F/.p ..)c5).H
00000f0: be ee 7f 3d d6 8c 1e b9 f3 ab 17 23 0e 1d 86 2c  ...=.......#...,
0000100: d4 28 ce 4a 46 df 6e 3a c3 25 7d 3f 1b e4 3c 03  .(.JF.n:.%}?..<.
0000110: c9 1f 38 96 30 1e c9 6e de fa 26 8f a1 59 18 69  ..8.0..n..&..Y.i
0000120: 68 9a 35 c4 42 56 2a 6f b2 3b 3f b3 ae 60 96 a8  h.5.BV*o.;?..`..
0000130: 5d c4 9d 0d cc 0b d6 ec b9 58 28 d3 3c bb 0d f3  ]........X(.<...
0000140: b6 56 1d b2 f8 da 3b f1 3c 11 9e e7 56 c8 20 27  .V....;.<...V. '
0000150: 76 65 3e d9 1e 17 e5 d2 4f 65 8e 83 c2 27 5a bf  ve>.....Oe...'Z.
0000160: 1f 80 bf f4 4b 78 b0 0e 3f 1e 4d 96 63 b9 65 5a  ....Kx..?.M.c.eZ
0000170: 34 43 c8 9a a9 8e 62 5a cc af ab 10 ff 26 1f ae  4C....bZ.....&..
0000180: 03 ef 4c 8f ba 09 b8 1e 7a 1e bb 5d 77 d3 f8 06  ..L.....z..]w...
0000190: 71 53 67 60 26 91 28 81 2e 5e bc 84 9f 48 cc ce  qSg`&.(..^...H..
00001a0: 60 ec b4 b3 fa 27 32 60 27 98 63 a3 80 66 65 d2  `....'2`'.c..fe.
00001b0: ed 0b af e7 ba d1 d8 85 d3 af 93 7f a2 48 15 68  .............H.h
00001c0: a8 78 74 f8 ed 6f 6b 25 5f ca 7d 28 fb 0c 94 ce  .xt..ok%_.}(....
00001d0: 7a fc 6e b6 32 88 6a 62 b3 84 b8 98 d3 b9 01 73  z.n.2.jb.......s
00001e0: e4 76 07 3e 4e a0 15 82 1b 4a e1 89 13 75 4c ee  .v.>N....J...uL.
00001f0: 09 06 05 75 cc 0a 51 88 38 31 f6 7e e8 f8 74 b7  ...u..Q.81.~..t.
0000200: 59 9c e6 00 53 4f e7 80 ae 8c a5 85 55 e7 08 ae  Y...SO......U...
0000210: 84 69 18 84 dc c0 00                             .i.....

```

Uses LZMA compression.

Try it online!

# Answer
> 10 votes
## JavaScript (ES6), ~~756~~ 750 bytes

```
j=i=1
r=s=>s[0].replace(/.(\d+)/g,(s,n)=>s[0].repeat(n))
f=s=>[(s=s[0].match(/../g)).map(_=>(i>99?` `:`  `)+i+(i++>9?` `:`  `)),s.map(s=>`  ${s} `),s.map(_=>r`_5`)].map(a=>a.join`|`)
g=(a,b,c)=>a.map((s,i)=>s+b[i]+c[i])
document.write(r`<pre> _5 97_5
|`+[...g(f`H `,[s=r`| 95|`,s,r`|_5 61_29|`],f`He`),...g(f`LiBe`,[s=r`| 59|`,s,s],f`B C N O F Ne`),...g(f`NaMg`,[s,s,r`|_59|`],f`AlSiP S ClAr`),...f`K CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKr`,...f`RbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI Xe`,...g(f`CsBaLa`,(a=f`CePrNdPmSmEuGdTbDyHoErTmYbLu`,`\\/\\`),f`HfTaW ReOsIrPtAuHgTlPbBiPoAtRn`),...g(f`FrRaAc`,(a=[...a,...f`ThPaU NpPuAmCmBkCfEsFmMdNoLr`],`/\\/`),f`RfDbSgBhHsMtDsRgCnNhFlMcLvTsOg`)].join`|
|`+r`|

 18_84
 `+a.map(s=>r` 17`+`\\/`[j^=1]+s+`\\/`[j]).join`
 `)
```

Explanation:

* `a` contains the (formatted) Lanthanides and Actinides
* `j` is used to track which character is used to draw the zigzag of the Lanthanides and Actinides
* `i` is simply the number of the next element to be formatted. Although it's not strictly necessary to format the elements in order, I think there's a small byte saving in doing so.
* `r` is a run-length decoding function. It expects to be called using a template string parameter. Any number in the string causes the preceding character to be repeated that many times, e.g. `r`_5`` is the same as ``_____`` (but 2 bytes shorter of course). I did originally have a more sophisticated version that could handle `r`${i<100} `+i+r`${i++<10} `` but it turned out to be shorter to keep that as a special case.
* `f` is an element formatting function. It expects to be called using a template string parameter that contains the elements as pairs of characters (space padded out for single-character element names). An array of three strings is returned, one for the element numbers, one for the element names, and one for the underlines. If more than one element is formatted, they are joined with a `|` separator.
* `g` is a glue function. It expects to be called with three arrays (the second and third parameters can be strings if only one character is needed) and returns a single array with all the corresponding strings concatenated together.

The first three rows of elements are handled by gluing the formatted elements from each side with an appropriate amount of space. The fourth and fifth rows need no glue. The sixth and seventh rows are handled by gluing the formatted elements from each side with the appropriate zigzag. The 21 rows are then joined together with `|` borders and newlines. Meanwhile the 6 rows of the Lanthanides and Actinides are given their padding and zigzag and joined together with newlines. Finally the pieces are concatenated with the necessary remaining formatting elements. Edit: Saved 6 bytes because I forgot to substitute literal newlines after developing the code.

If a full table with the Lanthanides and Actinides in situ is acceptable, then for 556 bytes:

```
document.write(`<pre>`+[[/\w./g,`|  $& |`],[/\|\|/g,`|`],[/(.*)-(.*)/g,(_,l,r)=>l+` `.repeat(193-r.length-l.length)+r],[/\n.*/g,s=>s.replace(/ \w./g,_=>(++i<100?` `:``)+i+(i<10?` `:``))+s+s.replace(/  \w. /g,`_____`)],[/ {5}(?=[^]{191}\d)/g,`_____`],[/_ _/g,`___`]].reduce((s,[r,t])=>s.replace(r,t),`-
H -He
LiBe-B C N O F Ne
NaMg-AlSiP S ClAr
K CaSc-TiV CrMnFeCoNiCuZnGaGeAsSeBrKr
RbSrY -ZrNbMoTcRuRhPdAgCdInSnSbTeI Xe
CsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRn
FrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg`,i=0))
```

Explanation: A string contains the list of elements with `-` and newline added as formatting elements. A number of replacements are used to transform the list of elements into the desired table.

1. Each element is padded inside a pair of `|`s.
2. Consecutive `|`s are then deleted.
3. `-`s are replaced with enough padding to result in a width of 193 characters.
4. Each line after the first is then replaced with three lines:
    1. A line with all the elements replaced with consecutive integers
    2. The original line of elements
    3. A line with all the elements replaced with `_`s.
5. Each integer then has `_`s placed above it (if it doesn't already have them)
6. Space-separated `_`s are joined with `_`s.

I could probably save a few more bytes using the widely available padStart and padEnd methods.

# Answer
> 10 votes
# 05AB1E, ~~517~~ ~~500~~ ~~494~~ ~~459~~ 458 bytes

```
¾36×•=∊à¢[ΔζÃΓÖoÂÂ›àƶØ4.æßðùùO∊ŸßeÑΘ²9Êλ*βUθÇΔn4üÁ¬₁÷6öć®λJƒÐtvý¢ƶ³≠qΣĆ}εùeÆv]_|ˆ±q₅yÜƵтY¿в{àéÙ•4B«S2ôvyć'#×s'@×})˜2ôvyDJ'@åi'_©5×ëð5×}‚˜.C.B}})18ôvyøvy'|ý2F'|3úûð7×:}D4£ð4×Êi'|ëð}.ø}})ø„ #„_#:ø»…  _û®5×:…__ 2ú®5×:„_ û®3×:.•$›“₄≠÷/¤¿M5PËð—ΓY¢ö>7*ƒße∞™¶£nˆU‘´¾Ã‹Š\S¬ǝüÑ;:œ η|9HœÇâ`η_т<%£¾ÉöJ₄ª"eÄŸµ2ƶ3^_Ω~Ç∍”pgH¤δ%6ΣŽΔΔ9üηΩ+₃¹ºι"¤Qy¶O£ÄˆU«AJdc=ûö÷O´η,lð¢ʒƵy•v'@y.;}57L72 89Ÿ«Ƶ3ƵHŸ«58 71Ÿ«90Ƶ2Ÿ«Jv'#y.;}"57 |""57 $":¶¡ø'$'|6×2úRû©¦«„/\3×2úR.∞:®'|6×„\/3×3ú«:ø»™

```

Try it online!

*-10ish thanks to Emigna*

*Lets out a long guttural victory screech... Will golf more, but since it's still the shortest...*

---

# The Basic Idea

```
11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12
12 12 00 00 00 00 00 00 00 00 00 00 11 11 11 11 11 22
22 22 00 00 00 00 00 00 00 00 00 00 22 22 21 21 22 22
21 22 22 22 21 22 22 22 22 22 22 22 22 22 22 22 22 22
22 22 21 22 22 22 22 22 22 22 22 22 22 22 22 22 21 22
22 22 22 22 22 21 22 22 22 22 22 22 22 22 22 22 22 22
22 22 22 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 22 22 22 22 22 22 22 22 22 22 22 22 22 22 00
00 00 00 22 22 21 22 22 22 22 22 22 22 32 32 32 32 00

```

I mapped out each of the squares with the first digit being the length of the number and the second digit being the length of the element name. Used this to create the skeleton (if `.C` and `.B` didn't exist this would easily be 300-400 bytes):

```
 _____                                                                                _____
|  #  |                                                                                |  #  |
|  @  |                                                                                |  @@ |
|_____|_____                                                             _____________________________|_____|
|  #  |  #  |                                                           |  #  |  #  |  #  |  #  |  #  |  ## |
|  @@ |  @@ |                                                           |  @  |  @  |  @  |  @  |  @  |  @@ |
|_____|_____|                                                           |_____|_____|_____|_____|_____|_____|
|  ## |  ## |                                                           |  ## |  ## |  ## |  ## |  ## |  ## |
|  @@ |  @@ |                                                           |  @@ |  @@ |  @  |  @  |  @@ |  @@ |
|_____|_____|___________________________________________________________|_____|_____|_____|_____|_____|_____|
|  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |
|  @  |  @@ |  @@ |  @@ |  @  |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
|  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |
|  @@ |  @@ |  @  |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @  |  @@ |
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
|  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |
|  @@ |  @@ |  @@ |  @@ |  @@ |  @  |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
|  ## |  ## |  ## | ### | ### | ### | ### | ### | ### | ### | ### | ### | ### | ### | ### | ### | ### | ### |
|  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|

                   ___________________________________________________________________________________
                  |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |
                  |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |
                  |_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
                  |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## |  ## | ### | ### | ### | ### |
                  |  @@ |  @@ |  @  |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |  @@ |
                  |_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|

```

This is what the first half of the code accomplishes...

# 05AB1E, 229 bytes

```
0 36×•=∊à¢[ΔζÃΓÖoÂÂ›àƶØ4.æßðùùO∊ŸßeÑΘ²9Êλ*βUθÇΔn4üÁ¬₁÷6öć®λJƒÐtvý¢ƶ³≠qΣĆ}εùeÆv]_|ˆ±q₅yÜƵтY¿в{àéÙ•4B«S2ôvyć'#×s'@×})˜2ôvyDJ'@åi'_5×ëð5×}‚˜.C.B}})18ôvyøvy'|ý2F"   |"ûð7×.:}D4£ð4×Êi'|ëð}.ø}})ø„ #„_#:ø»…  _û'_5×:"  __ "'_5×:„_ û'_3×:

```

Try it online!

Through ugly one-off manipulation and other bullshit that shouldn't exist, I manage to piece together the entire skeleton.

---

The next part is basically "insert the massive string of letters and numbers that represent the elements". I essentially just compressed, sequentially, all of the letters:

```
.•$›“₄≠÷/¤¿M5PËð—ΓY¢ö>7*ƒße∞™¶£nˆU‘´¾Ã‹Š\S¬ǝüÑ;:œ η|9HœÇâ`η_т<%£¾ÉöJ₄ª"eÄŸµ2ƶ3^_Ω~Ç∍”pgH¤δ%6ΣŽΔΔ9üηΩ+₃¹ºι"¤Qy¶O£ÄˆU«AJdc=ûö÷O´η,lð¢ʒƵy•

```

To get:

```
hhelibebcnofnenamgalsipsclarkcasctivcrmnfeconicuzngageassebrkrrbsryzrnbmotcrurhpdagcdinsnsbteixecsbalahftawreosirptauhgtlpbbipoatrnfrraacrfdbsgbhhsmtdsrgcnnhflmclvtsogceprndpmsmeugdtbdyhoertmybluthpaunppuamcmbkcfesfmmdnolr

```

You then see me iterate replacing all @ symbols with the appropriate letter (at the end, after placing them all in their appropriate positions, it allows me to use "Title Cased" for the capitals, as each element is separated by whitespace).

---

Next I make the number string and do the same thing (thanks Emigna):

```
57L72 89Ÿ«Ƶ3ƵHŸ«58 71Ÿ«90Ƶ2Ÿ«J

```

Results in:

```
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657727374757677787980818283848586878889104105106107108109110111112113114115116117118585960616263646566676869707190919293949596979899100101102103

```

Which I then iterate and replace each # with.

---

After this, the final annoyance was the slashes... My god...

```
"57 |""57 $":¶¡ø'$'|6×2úRû©¦«"\/\/\/  ".∞.;®'|6×"   \/\/\/"«.;ø»

```

This 50 byte monstrosity is what I want to fix, along with multiple other small things... So I'll continue to golf, and until I fix the things I want to this will be the informal explanation.

# Answer
> 9 votes
# Ruby, ~~567~~ 558 bytes

```
a=[?|]*21
j=r=0
118.times{|i|a[r]+="%4s |"%("%-2d"%-~i)
a[r+1]+="  #{'H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg'[i*2,2]} |"
a[r+2]+=?_*5+?|
i>j&&(j+=(r/6+2)**2*2;r+=3)}
a<<' '+?_*84
6.times{|r|a[r+3][13]=' _'[r/5]*59+?|+d='  _'[r%3]
r<3&&a[r][7]=d*5+' '*61+d*29+?|+d
a[r+=15][18]=a[r][102]='/\\'[r%2]
a<<' '+a[r][18,85]
a[r][18,84]=''}
puts ' _____'+' '*97+?_*5,a

```

Try it online!

Brought the La/Ac series closer to the main table (re reading of the rules suggests it's allowed; rearranged formatting section so `d` is used immediately when calculated; and next row calculated mathematically instead of by regex.

# Ruby, 587

score excludes 3 unnecessary newlines added for clarity

```
a=[?|]*21
r=0

118.times{|i|
a[r]+="%4s |"%("%-2d"%(i+1))
a[r+1]+="  #{e='H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg'[i*2,2]} |"
a[r+2]+="_____|"
"HeNeArKrXeRn"=~/#{e}/&&r+=3}

6.times{|r|d='  _'[r%3]
r<3&&a[r][7]=d*5+' '*61+d*29+?|+d
a[r+3][13]=' _'[r/5]*59+?|+d
a[r+15][18]=a[r+15][102]='\//'[r%2]
a[r+23]=' '*18+a[r+15][18,85]
a[r+15][18,84]=''}

a[22]=' '*18+?_*84
puts ' _____'+' '*97+?_*5,a

```

**Explanation**

The idea is to produce the following, then modify it by adding the correct padding and formatting, and moving the lanthanides and actinides to the bottom.

```
|  1  |  2  |
|  H  |  He |
|_____|_____|
|  3  |  4  |  5  |  6  |  7  |  8  |  9  |  10 |
|  Li |  Be |  B  |  C  |  N  |  O  |  F  |  Ne |
|_____|_____|_____|_____|_____|_____|_____|_____|
|  11 |  12 |  13 |  14 |  15 |  16 |  17 |  18 |
|  Na |  Mg |  Al |  Si |  P  |  S  |  Cl |  Ar |
|_____|_____|_____|_____|_____|_____|_____|_____|
|  19 |  20 |  21 |  22 |  23 |  24 |  25 |  26 |  27 |  28 |  29 |  30 |  31 |  32 |  33 |  34 |  35 |  36 |
|  K  |  Ca |  Sc |  Ti |  V  |  Cr |  Mn |  Fe |  Co |  Ni |  Cu |  Zn |  Ga |  Ge |  As |  Se |  Br |  Kr |
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
|  37 |  38 |  39 |  40 |  41 |  42 |  43 |  44 |  45 |  46 |  47 |  48 |  49 |  50 |  51 |  52 |  53 |  54 |
|  Rb |  Sr |  Y  |  Zr |  Nb |  Mo |  Tc |  Ru |  Rh |  Pd |  Ag |  Cd |  In |  Sn |  Sb |  Te |  I  |  Xe |
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
|  55 |  56 |  57 |  58 |  59 |  60 |  61 |  62 |  63 |  64 |  65 |  66 |  67 |  68 |  69 |  70 |  71 |  72 |  73 |  74 |  75 |  76 |  77 |  78 |  79 |  80 |  81 |  82 |  83 |  84 |  85 |  86 |
|  Cs |  Ba |  La |  Ce |  Pr |  Nd |  Pm |  Sm |  Eu |  Gd |  Tb |  Dy |  Ho |  Er |  Tm |  Yb |  Lu |  Hf |  Ta |  W  |  Re |  Os |  Ir |  Pt |  Au |  Hg |  Tl |  Pb |  Bi |  Po |  At |  Rn |
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
|  87 |  88 |  89 |  90 |  91 |  92 |  93 |  94 |  95 |  96 |  97 |  98 |  99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 |
|  Fr |  Ra |  Ac |  Th |  Pa |  U  |  Np |  Pu |  Am |  Cm |  Bk |  Cf |  Es |  Fm |  Md |  No |  Lr |  Rf |  Db |  Sg |  Bh |  Hs |  Mt |  Ds |  Rg |  Cn |  Nh |  Fl |  Mc |  Lv |  Ts |  Og |
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|

```

**Commented code**

```
a=[?|]*21                                #setup array with |s for left hand side
r=0                                      #row counter

118.times{|i|                            #For each element add to the correct row
a[r]+="%4s |"%("%-2d"%(i+1))             #the atomic number
a[r+1]+="  #{e='H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg'[i*2,2]} |"
a[r+2]+="_____|"                         #the element symbol and the blank space at the bottom.
"HeNeArKrXeRn"=~/#{e}/&&r+=3}            #If it is element from last column, increment r

6.times{|r|d='  _'[r%3]                  #What symbol (_ or space)do we need to pad?
r<3&&a[r][7]=d*5+' '*61+d*29+?|+d        #Move He to the right
a[r+3][13]=' _'[r/5]*59+?|+d             #Move row 2&3 elements to the right
a[r+15][18]=a[r+15][102]='\//'[r%2]      #Draw breaks for La and Ac series
a[r+23]=' '*18+a[r+15][18,85]            #Copy La and Ac series
a[r+15][18,84]=''}                       #Delete original La and Ac series from main table

a[22]=' '*18+?_*84                       #Draw top on La and Ac series
puts ' _____'+' '*97+?_*5,a              #Output top of row 1, followed by array containing the rest of the table.

```

# Answer
> 8 votes
# C, ~~1415~~ ~~1401~~ ~~1395~~ ~~1367~~ ~~1345~~ ~~1277~~ ~~1159~~ ~~1052~~ 1043 bytes

```
#define P printf(
#define L;P"|\n")
#define M;p(18," ")
#define D L;B
#define K;P"\\\n")M;P
#define Q;P"|%59c",32)
char*l="HHeLiBeBCNOFNeNaMgAlSiPSClArKCaScTiVCrMnFeCoNiCuZnGaGeAsSeBrKrRbSrYZrNbMoTcRuRhPdAgCdInSnSbTeIXeCsBaLaTaWReOsIrPtAuHgTlPbBiPoAtRnFrRaAcDbSgBhHsMtDsRgCnNhFlMcLvTsOgPrNdPmSmEuGdTbDyHoErTmYbLuPaUNpPuAmCmBkCfEsFmMdNoLr",U[]="|_____",*u=U+1;a;p(n,s)int*s;{while(n--)P s);}A(n){for(n+=a;a<n;++a)P a>9?"%c%4d ":"%c%3d  ",a^72*a^58?a^90*a^104?'|':47:92,a);}B(n){for(;n--;P"%c ",*l>96?*l++:32))P"|%3c",*l++);}N(){A(18)D(18)L;p(18,U)L;}f(){P" %s%102s\n",u,u);A(a=1);P"|%95c",32);A(1)D(1);P"|%95c",32);B(1)L;P"%s%-67s",U,U);p(5,u);P"____%s|\n",U);A(2)Q;A(6)D(2)Q;B(6)L;p(2,U)Q;p(6,U)L;A(2)Q;A(6)D(2)Q;B(6)L;P"|%s|%s|",u,u);p(11,u);P u+1);p(6,U)L;N(N());A(3);a=72;A(15)D(3);P"/  Hf ");B(14)L;p(3,U);P"\\%s",u);p(14,U)L;A(3);a=104;A(15)D(3);P"\\  Rf ");B(14)L;p(3,U);P"/%s",u);p(14,U)L;P"\n")M;p(84,"_");P"\n")M;a=58;A(14)K"/  Ce ");B(13);P"/\n")M;P"\\%s",u);p(13,U)K"");a=90;A(14);P"/\n")M;P"\\  Th ");B(13)K"/%s",u);p(13,U);P"/");}

```

*Thanks to @Conor O'Brien for saving 6 bytes!*

*Thanks to @Zacharý for saving ~~22~~ 90 bytes!*

*Thanks to @gastropner for saving ~~118~~ 225 bytes!*

*Thanks to @ceilingcat for saving ~~8~~ 9 bytes!*

Try it online!

**Unrolled (1159 bytes version):**

```
#define P printf(
#define L;P"|\n")
#define M;p(18," ")
#define D L;B
#define N(n)A(n,n+18)D(18)L;p(18,U)L;
#define K;P"\\\n")M;P
#define C char
#define Q;P"|%*c",59,32)
C*u,
*l,
*U="|_____",
S[4];

p(n,s)C*s;
{
    P s,
    --n&&p(n,s));
}

b(k)
{
    k=P"|  %s",S);
    P"%*c",6-k,32);
}

e(s)C*s;
{
    *s++=*l++;
    *s=*l>96?*l++:0;
}

A(a,n)
{
    for(;a<n;++a)
        P a>9?"|%4d ":"|%3d  ",a);
}

B(n)
{
    for(;n--;)
        b(e(S));
}

f()
{
    u=U+1;
    l="HHeLiBeBCNOFNeNaMgAlSiPSClArKCaScTiVCrMnFeCoNiCuZnGaGeAsSeBrKrRbSrYZrNbMoTcRuRhPdAgCdInSnSbTeIXeCsBaLaTaWReOsIrPtAuHgTlPbBiPoAtRnFrRaAcDbSgBhHsMtDsRgCnNhFlMcLvTsOgPrNdPmSmEuGdTbDyHoErTmYbLuPaUNpPuAmCmBkCfEsFmMdNoLr";
    P" %s%*s\n",u,102,u);
    A(1,2);
    P"| %*c",94,32);
    A(2,3)
    D(1);
    P"| %*c",94,32);
    B(1)L;
    P"%s%s%*c",U,U,61,32);
    p(5,u);
    P"____%s|\n",U);
    A(3,5)Q;
    A(5,11)
    D(2)Q;
    B(6)L;
    p(2,U)Q;
    p(6,U)L;
    A(11,13)Q;
    A(13,19)
    D(2)Q;
    B(6)L;
    P"|%s|%s|",u,u);
    p(11,u);
    P u+1);
    p(6,U)L;
    N(19)
    N(37)
    A(55,58);
    P"\\  72 ");
    A(73,87)
    D(3);
    P"/  Hf ");
    B(14)L;
    p(3,U);
    P"\\%s",u);
    p(14,U)L;
    A(87,90);
    P"/ 104 ");
    A(105,119)
    D(3);
    P"\\  Rf ");
    B(14)L;
    p(3,U);
    P"/%s",u);
    p(14,U)L;
    P"\n")M;
    p(84,"_");
    P"\n")M;
    P"\\  58 ");
    A(59,72)
    K"/  Ce ");
    B(13);
    P"/\n")M;
    P"\\%s",u);
    p(13,U)
    K"/  90 ");
    A(91,104);
    P"/\n")M;
    P"\\  Th ");
    B(13)
    K"/%s",u);
    p(13,U);
    P"/");
}

```

# Answer
> 6 votes
# PowerShell, 1562 bytes

```
cls
nal w write-host
$u="_"
$q=" "
$a=@('','H','He','Li','Be','B','C','N','O','F','Ne','Na','Mg','Al','Si','P','S','Cl','Ar','K','Ca','Sc','Ti','V','Cr','Mn','Fe','Co','Ni','Cu','Zn','Ga','Ge','As','Se','Br','Kr','Rb','Sr','Y','Zr','Nb','Mo','Tc','Ru','Rh','Pd','Ag','Cd','In','Sn','Sb','Te','I','Xe','Cs','Ba','La','Ce','Pr','Nd','Pm','Sm','Eu','Gd','Tb','Dy','Ho','Er','Tm','Yb','Lu','Hf','Ta','W','Re','Os','Ir','Pt','Au','Hg','Tl','Pb','Bi','Po','At','Rn','Fr','Ra','Ac','Th','Pa','U','Np','Pu','Am','Cm','Bk','Cf','Es','Fm','Md','No','Lr','Rf','Db','Sg','Bh','Hs','Mt','Ds','Rg','Cn','Nh','Fl','Mc','Lv','Ts','Og')
function b($s,$x,$y){[console]::setcursorposition($x,$y);w $s -n}
function v($n,$m,$i,$p){$x=$n;$i..$p|%{$y=$m;b $_ $x $y;$y++;if($_-gt99){$x++};b $a[$_] $x $y;if($_-gt99){$x--};$x=$x+6}}
w (($u*6)*18)-n;w""
0..8|%{if($_-eq7){w"";w (($u*6)*18)-n;w""}w ("|     "*18)-n;w "|";w ("|     "*18)-n;w "|";w ("|_____"*18)-n;w "|"}
$y=0;0..2|%{7..101|%{b $q $_ $y};$y++};$x=12;$t=$q;0..84|%{if($_-eq61){$t="_"}b $t $x 3;$x++};4..9|%{$y=$_;$t=$q;if($_-eq9){$t=$u};13..71|%{b $t $_ $y}}
$y=23;0..6|%{$x=0;0..18|%{b $q $x $y;$x++};$x=103;0..5|%{b $q $x $y;$x++};$y++}
$x=18;$y=16;0..6|%{b "\" $x $y;$y++;b "/" $x $y;$y++}
$x=102;$y=24;0..2|%{ b "\" $x $y;$y++;b "/" $x $y;$y++}
0,6,102|%{b $q $_ 0}
22,23|%{b $q 18 $_}
b $q 102 23
v 3 10 19 36;v 3 13 37 54;v 3 16 55 57;v 21 16 72 86;v 3 19 87 89;v 20 19 104 118;v 21 24 58 71;v 21 27 90 99;v 80 27 100 103;v 3 1 1 1;v 105 1 2 2;v 3 4 3 4;v 75 4 5 9;v 105 4 10 10;v 3 7 11 12;v 75 7 13 18
b "" 0 30
pause

```

This approach is not optimal. Can't use tio since this leverages `[console]::setcursorposition`.

# Answer
> 5 votes
# SOGL V0.11, 311 bytes

```
f¤o3,hģ_lμgΣ│Τ┐xC‚¦⁽?%□f⁵↕υ/gκ÷⌠‚ξ#.ν⁵‰↕¦δ┌_jυ1ιīΒ=λ←ļ,ξ╚Ƨu≡ā⁄b⅔►<≡7⅛±√‽ε¶&⁶7zV¾UΥY○ΝΚq╬#∫⅜āΡ⁴7‼%Æ«∑+‼Ψ_№QΕ¦→3γ:Ηρ':υy7▒Ξυσ╤ņcΗOī{═─⁷׀Uγlλ№γjΒ%G≤§┐⌠≈δ{oR{ΘKUƨA▒V⁶ ³‘2n '`Δ"²zōdΕ«⅝←╝⅔πφ“'³─◄"³υ≥τk┐?№L‚↑γ°“'³─6«{K;K;A{:I}a}X¹¹Hā;{⁾J6*;J3*;Jl1=@*+l3κ@*ΚΚ"<Ψ:$ō∫ΣO±>⁄‘7nž}"‛‽‛№l№’2n{_"□׀⁵‘čž}"O⁶‛±0±‛¤3¤M¤’2n{_"Ρ8‘ž

```

This took a while. To make this that compact, I've implemented many things into SOGL (most of which were already documentated). Most notably,

* "ž", which places an array inside another array at specific coordinates, and
* "►" and "◄" - run-length encode and decode. I really thought I had documentated them, but I guess I hadn't.

Try it Here! (compression (lazily) updated to comply with 0.12)

So, overly long explanation ahead:

### First part: setup

```
f¤o3,hģ_lμgΣ│Τ┐xC‚¦⁽?%□f⁵↕υ/gκ÷⌠‚ξ#.ν⁵‰↕¦δ┌_jυ1ιīΒ=λ←ļ,ξ╚Ƨu≡ā⁄b⅔►<≡7⅛±√‽ε¶&⁶7zV¾UΥY○ΝΚq╬#∫⅜āΡ⁴7‼%Æ«∑+‼Ψ_№QΕ¦→3γ:Ηρ':υy7▒Ξυσ╤ņcΗOī{═─⁷׀Uγlλ№γjΒ%G≤§┐⌠≈δ{oR{ΘKUƨA▒V⁶ ³‘2n

...‘    push "h helibeb c n o f nenamgalsip s clark casctiv crmnfeconicuzngageassebrkrrbsry zrnbmotcrurhpdagcdinsnsbtei xecsbalaceprndpmsmeugdtbdyhoertmybluhftaw reosirptauhgtlpbbipoatrnfrraacthpau nppuamcmbkcfesfmmdnolrrfdbsgbhhsmtdsrgcnnhflmclvtsog"
    2n  split into an array with items of length 2
These are the element names, conveniently already shaped how they should be.

'`Δ
'`   push 118
  Δ  range - all numbers from 1 to 118
These are atomic numbers

"²zōdΕ«⅝←╝⅔πφ“'³─◄
"...“      push 794198124771504466790502538
     '³    push 19
       ─   base [19] decode - resulting to array [1, 2, 2, 8, 3, 8, 4, 18, 5, 18, 6, 3, 9, 14, 6, 15, 7, 3, 10, 14, 7, 15]
        ◄  run-length decode
Final result: [1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]
These are the periods, with 9 and 10 for lanthanides and actinides respectively.

"³υ≥τk┐?№L‚↑γ°“'³─6«{K;K;A{:I}a}X¹

"...“                     push 270687554118568732622432847987
     '³─                  base 19 decode, resulting in [1, 0, 18, 0, 1, 1, 13, 5, 1, 1, 13, 5, 1, 17, 1, 17, 1, 16, 4, 14, 1, 16, 4, 14]
        6«{          }    repeat 12 times
           K;K;             get the 1st 2 items of the array below the array (e. g:      ..., 13, 5, [1, 1, 13, 5, 1, 17, 1, 17, 1, 16, 4, 14, 1, 16, 4, 14])
               A            save the array on variable A (so it doesn't get in the way)  ..., 13, 5
                {  }        repeat POP times                                             ..., 13
                 :            duplicate the number                                       ..., 13, 13
                  I           increase it                                                ..., 13, 14
                              and so on (e.g. 5 times, resulting in 6 numbers)           ..., 13, 14, 15, 16, 17, 18, [1, 1, 13, 5, 1, 17, 1, 17, 1, 16, 4, 14, 1, 16, 4, 14]
                    a       load back the array
                            repeating that all 12 times
                      X   remove the array off of the stack
                       ¹  wrap all of those numbers in an array
Final result: [1, 18, 1, 2, 13, 14, 15, 16, 17, 18, 1, 2, 13, 14, 15, 16, 17, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
These are the periods, which could be so nicely compressed, because if the atomic numbers are sorted, these are too.

```

### Second part: loop

```
¹Hā;{
¹      wrap all those 4 arrays into one big array
 H     rotate it left
            [[a, b, c],         [["c", 3, 6]
         So  [1, 2, 3], becomes  ["b", 2, 5] . Now the sub-array structure is [name, atomic number, group, period]
             [4, 5, 6]]          ["a", 1, 4]]
         A couple important things about this:
           - it makes each new sub-array contain all the data from all the arrays at a constant index
           - it reverses the indexes - a,b,c were given in, but now, in each sub-array, the first items are c, b, a.
             This is important because the last elements would get drawn first, so everything would appear correctly. See https://gist.github.com/dzaima/221d1792e03d0429e3403cf255c66926 for what would happen if it didn't get reversed.
  ā;   push an empty array below that big array
    {  for each sub-array

⁾J6*;J3*;
⁾          sentence-case the items in the array, ignoring the numbers. Capitalizes the 1st letter of the name
 J         pop get the last item of the array               [["Au", 79, 6], 11]
  6*       multiply it by 6 - the X coordinate              [["Au", 79, 6], 66]
    ;      swap, geting the array above                     [66, ["Au", 79, 6]]
     J     pop get the last item of the array               [66, ["Au", 79], 6]
      3*   multiply it by 6 - the Y coordinate              [66, ["Au", 79], 18]
        ;  swap, geting the array above                     [66, 18, ["Au", 79]]

Jl1=@*+l3κ@*ΚΚ"<Ψ:$ō∫ΣO±>⁄‘7nž}
J                        get the 1st item of the array               [84, 6, ["C "], 6]             [66, 18, ["Au"], 79]            [96, 21, ["Lv"], 116]
 l                       get length                                  [84, 6, ["C "], 6, 1]          [66, 18, ["Au"], 79, 2]         [96, 21, ["Lv"], 116, 3]
  1=                     push if [length] = 1                        [84, 6, ["C "], 6, 1]          [66, 18, ["Au"], 79, 0]         [96, 21, ["Lv"], 116, 0]
    @*                   get that many spaces                        [84, 6, ["C "], 6, " "]        [66, 18, ["Au"], 79, ""]        [96, 21, ["Lv"], 116, ""]
      +                  join                                        [84, 6, ["C "], "6 "]          [66, 18, ["Au"], "79"]          [96, 21, ["Lv"], "116"]
       l                 get length                                  [84, 6, ["C "], "6 ", 2]       [66, 18, ["Au"], "79", 2]       [96, 21, ["Lv"], "116", 3]
        3κ               do 3-[length]                               [84, 6, ["C "], "6 ", 1]       [66, 18, ["Au"], "79", 1]       [96, 21, ["Lv"], "116", 0]
          @*             get that many spaces                        [84, 6, ["C "], "6 ", " "]     [66, 18, ["Au"], "79", " "]     [96, 21, ["Lv"], "116", ""]
            Κ            prepend those                               [84, 6, ["C "], " 6 "]         [66, 18, ["Au"], " 79"]         [96, 21, ["Lv"], "116"]
             Κ           prepend that in the array                   [84, 6, [" 6 ", "C "]]         [66, 18, [" 79", "Au"]]         [96, 21, ["116", "Lv"]]
              "...‘      push " _____ | ŗ ||  ŗ ||_____|", replacing ŗ with the correspoding item form the array  [66, 18, " _____ |  79 ||  Au ||_____|"]
                   7n    split that into an array of items of length 7                                            [66, 18, " _____ ", "|  79 |", "|  Au |", "|_____|"]
                     ž   set that array at the positions [66, 18] in the array below
                      }  end the for-each loop

```

So now the output looks like this.

### Third part: Add-ons

```
"‛‽‛№l№’2n{_"□׀⁵‘čž}
"...’           }  push code page indexes of the chars          [24, 19, 24, 28, 108, 28]
     2n            split into an array of items of length 2     [[24, 19], [24, 28], [108, 28]]
       {           for each sub-array
        _            push all the arrays contents on the stack  [24, 19]
         "...‘       push "\/\/\/"                              [24, 19, "\/\/\/"]
              č      split into a char-array                    [24, 19, ["\", "/", "\", "/", "\", "/"]]
               ž     replace in the mother array at coordinates [e.g. 24, 19] with those chars

"O⁶‛±0±‛¤3¤M¤’2n{_"Ρ8‘ž
"...’           push code page indexes of the chars          [79, 6, 24, 12, 48, 12, 24, 27, 51, 27, 77, 27]
     2n         split into an array of items of length 2     [[79, 6], [24, 12], [48, 12], [24, 27], [51, 27], [77, 27]]
       {        for each sub-array (implicitly closed)
        _         push all the arrays contents on the stack  [79, 6]
         "Ρ8‘     push "_____________________________"       [79, 6, "_____________________________"]
             ž    replace in the mother array at coordinates [e.g. 79, 6] with that string

```

# Answer
> 4 votes
# Bash, 728 bytes

Tested on **Ubuntu**, requires **base64** and **xz** programs

```
echo "XQAAgAD//////////wAQF/CEG6nfcFqpw6CdrU+LkV2iM1yxHU1IDYDEgH/atWuFbJGeeBZu5o8S+/6JEYEvLgTKL3JLS1cREFe2iyLK+lMZU9vuTOkuUG6NIz7n9f+iz8j4iMrKqTRVBrSzmeiXXQJA2EEOcgg/Y7Cb6ZjVoTXmo4dAV4bjgMUS0paPWZHNKKZ101VPerG6mof4Rv8UrX/CNmkvxSGG0GKHhaWpHsM6WnTzEU2L8BbDQjYsHlSUzsLj0JdMO8SFR1mlbNtyxZej1s7c4eGy2jBUCq+dCMxFt5W0AOoEHIGKy3zsmqcrJqTnKXVHOUKDiDTel3GaRm3+5fBEc1lXeN1nPli3Id6D1hzIN92eYP4JSrgyrp4t142mJ3U22iTdzO4mctwmjbmdAmFqp8hwIHM4M1n0F6DgfF0bNkROTMRWJC/CQBAkJHARwwol3z2lFsjaReJnTr0rvDvkBfuIPgzjNhFPR2xT55MaN1DKZbPOSsd1r+zZre+XSZD9ViDuGq5xlpmOyiIPRcbNJWpwo7s5mjGkDGtu6+FHygaV5bmTnnGTV0uKtxpSn1MdttXh9CRWTMXBVaIT6RllKQhzgoSUMFbrVQBqKJ/7t7fNouBxhORQRb4DmZJbZ5A1cFhvQflxdHxNkdzZDs7U4DE31j96IhXbO5MirWl2ENWMO1s//QpX8w=="|base64 -d|xz -d

```

## Explanation

**LZMA** (Lempel-Ziv-Markov chain-Algorithm) produced about **0,5K archive** with periodic table.

It contains **unprintable symbols**, and can't be used directly in console. To use it i encoded it by Base64

```
echo "base64_string" | base64 -d | xz -d

```

Stream redirection is used to decode and uncompress archive.

## Tricks

To **save** about **30 bytes** i deleted newline and some spaces

# Answer
> 3 votes
# Bubblegum, 600 bytes

```
00000000: c4d5 4572 e430 0040 d17d 4ea1 1bb4 d9ee  ..Er.0.@.}N.....
00000010: 5d98 9999 9b86 990f 3ff6 cb2e 1546 2f5e  ].......?....F/^
00000020: a94c 8abe d595 70d4 1ce1 b90f b30c fd0b  .L....p.........
00000030: 210e a1f6 190f ef4f 6a9b d9a6 5f64 b6e9  !......Oj..._d..
00000040: 4e33 9b25 5ef8 f854 d71d ff68 6da9 b933  N3.%^..T...hm..3
00000050: 3ee6 afcf 59b0 64c5 36e3 48c9 303f 08b5  >...Y.d.6.H.0?..
00000060: a39d c7ce 36ca 312e 7289 935c bc5c f251  ....6.1.r..\.\.Q
00000070: b379 c32d da93 b195 268f 5d5b 9c32 63ce  .y.-....&.][.2c.
00000080: 8225 2b25 c3e2 49a8 5de8 3d76 b691 778d  .%+%..I.].=v..w.
00000090: 6bbe cb72 30e6 d83b 57bf 5c2a c907 1e77  k..r0..;W.\*...w
000000a0: 2fd9 f6eb 8b18 3361 ca8c 390b 96ac e8d9  /.....3a..9.....
000000b0: 3462 cc84 2933 e62c 940c 73c1 7af5 5c3b  4b..)3.,..s.z.\;
000000c0: 6b5c 5763 3338 ff45 e70f 7657 c799 8ff6  k\Wc38.E..vW....
000000d0: d8c0 f87b e3ae ab53 27ec e8f6 d5db 8c47  ...{...S'......G
000000e0: bd61 ee72 c967 d7af 5b99 b4a2 3259 c498  .a.r.g..[...2Y..
000000f0: 0953 66cc 59b0 6445 cfe6 1163 264c 9929  .Sf.Y.dE...c&L.)
00000100: 1956 4fad da7a 7782 32c6 8bce 2fe8 b6ae  .VO..zw.2.../...
00000110: f0ea 77f6 edba 73c5 7a7a 1acf e8b9 76a1  ..w...s.zz....v.
00000120: 67d7 3bce 7be7 76e7 354a e6ca e405 cbb0  g.;.{.v.5J......
00000130: 1f42 a940 9932 63ce 8225 2baa 5745 8c99  .B.@.2c..%+.WE..
00000140: 3065 c69c 8592 61cc fe19 b5a3 e64f 422b  0e....a......OB+
00000150: 84e9 ae0e ce6c 05f5 3459 faaa cc17 25bf  .....l..4Y....%.
00000160: 29a9 edb4 9eeb ef9c d770 7460 fcd1 3dee  )........pt`..=.
00000170: 5cfd 7065 c9fd e72d 5929 5355 6cd7 6b8b  \.pe...-Y)SUl.k.
00000180: a3ba 406d ce82 252b b61b e388 3113 a6cc  ..@m..%+....1...
00000190: 98b3 60c9 4ac9 30a9 ccea 8955 9f35 df6d  ..`.J.0....U.5.m
000001a0: 55c9 714d d654 1aed 2ba6 e4c2 3757 8d57  U.qM.T..+...7W.W
000001b0: 5d1d b30f 17dd 33a9 e782 3d3c ff43 6177  ].....3...=<.Caw
000001c0: 2ef5 ae2c d97a c692 43d7 fdcf 0f4f eb15  ...,.z..C....O..
000001d0: f3d4 1173 9f2f b7b1 8b88 3113 a6cc 98b3  ...s./....1.....
000001e0: 60c9 8a9e 2d23 c661 ff8a 795a 75fc 8e4d  `...-#.a..yZu..M
000001f0: eb23 2e9e 1bbf f7e1 3861 ab4f 39bf 7eea  .#......8a.O9.~.
00000200: c3fd f629 3fba fac5 7977 eeb8 3aff 3db4  ...)?...yw..:.=.
00000210: ae98 e739 36fc 35eb 695b 6f3b 66c2 9419  ...96.5.i[o;f...
00000220: 7316 2c59 d14f 208a 1833 617a f57a ea55  s.,Y.O ..3az.z.U
00000230: f7b5 b2ed 3782 7a9f 9c51 6c44 9331 8ebe  ....7.z..QlD.1..
00000240: 35ee 2af6 d526 777e 41d5 4525 e7ff af08  5.*..&w~A.E%....
00000250: 7bfc d020 dcf4 b900                      {.. ....

```

Try it online!

You can reverse this hexdump with `xxd -r`.

This is the result of Zopfliing the text 747 times in DEFLATE format.

# Answer
> 3 votes
# PHP, 758 Bytes

After very little chance to golf down my array approach I decide to work only with strings

Online Version

```
$p=($d=str_pad)("",3410,$d("",109)."\n");foreach(str_split("H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg",2)as$k=>$v){!in_array($k,$b=[2,10,18,36,54,86])?:$c++;foreach([" _____ ","| ".$d($k+1,3," ",$k<9?2:0)." |","|  $v |",$o="|_____|"]as$m=>$n)$p=substr_replace($p,$m<1&substr($p,-110+$q=(($i=($k>70&$k<86|$k>102?$k-14:$k)-$b[$c-1])+($k!=1?$c<3&$i>1?10:0:16))*6+110*$m+330*($k>56&$k<71|$k>88&$k<103?$c+3:$c),1)=="|"?$o:$n,$q,7);}$p[342]=" ";for($w=5;$w<9;$w++)for($u=0;$u<3;){$p[$l=($w>6?$w+1:$w)*330+128+$u*110]=$j=($w+$u++)%2?"\\":"/";if($w>6)$p[$l+84]=$j;}echo$p;

```

Expanded

```
$p=($d=str_pad)("",3410,$d("",109)."\n");
foreach(str_split("H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg"
,2)as$k=>$v){
!in_array($k,$b=[2,10,18,36,54,86])?:$c++;
foreach([" _____ ","| ".$d($k+1,3," ",$k<9?2:0)." |","|  $v |",$o="|_____|"]as$m=>$n)
$p=substr_replace($p,
$m<1&substr($p,-110+$q=(($i=($k>70&$k<86|$k>102?$k-14:$k)-$b[$c-1])+($k!=1?$c<3&$i>1?10:0:16))*6+110*$m+330*($k>56&$k<71|$k>88&$k<103?$c+3:$c),1)=="|"?$o:$n
,$q,7);
}
$p[342]=" ";
for($w=5;$w<9;$w++)for($u=0;$u<3;){
$p[$l=($w>6?$w+1:$w)*330+128+$u*110]=$j=($w+$u++)%2?"\\":"/";
if($w>6)$p[$l+84]=$j;}
echo$p;

```

# PHP, 892 Bytes

First working solution that is under the byte count of the compress version a solution with arrays

Online version

```
$p=array_fill(0,9,($z=($d=str_pad)("",109)."\n").$z.$z);foreach(str_split("H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg",2)as$k=>$v){if(array_search($k,$b=[0,2,10,18,36,54,86]))$c++;$g=$k>56&$k<71|$k>88&$k<103?$c+2:+$c;$x=$k>70&$k<86|$k>102?$k-14:$k;foreach(["| ".$d($k+1,3," ",$k<9?2:0)." |","|  $v |","|_____|"]as$m=>$n)$p[$g]=($r=substr_replace)($p[$g],$n,(($i=$x-$b[$c])+($c<3&$i>1?10:(!$c&$i>0?16:0)))*6+110*$m,7);}for($w=5;$w<9;$w++)for($u=0;$u<3;$u++){$p[$w][18+$u*110]=($w+$u)%2?"\\":"/";if($w>6){$p[$w][102+$u*110]=($w+$u)%2?"\\":"/";}}echo$d(" _____",103)."_____\n";$p[0]=$r($p[0],_____,227,5);$p[0]=$r($p[0],$d("",29,"_____ "),293,29);$p[2]=$r($p[2],$d("",59,"_____ "),233,59);echo join($p);

```

## PHP, 783 Bytes

Try it online!

Only using compressing

```
<?=bzdecompress(base64_decode("QlpoNDFBWSZTWYVVkt4AAXB/gCATACBAAP/gP+/f/r/v3yRAAlyZOzuIImgm0BNCJp6T0yQyaAeo000aNqYQrVMU895VSANAAAAAAGmnpAhqoB+1U9QaDQGgAA0ADQAESiieo/SgAAAAAAAANOlBWqLi6XHyC67CCYFu36ImFcCYYSqFERuisi0SA3RCkEKQBkUSsQARADINCeNmOimrFjyW6NWiy7Vp78ujxo434qwygFgmA4mABAxjGA1f9k1pmrrQfSjNsDbvcgetiknNCks756IrcRERRYABMoAAqAEzczMzKCqgAACqgTMzMoaftix6GTLlyYsd92rSy+qyuyu38Ja5t2r3njIeaoULsW+FtUVTKXFADFjUAp1EHjMhLOQkUqZJhPNPGSkUz0IbVHm+kYpfJF1111ttttpERXMYxjQ+QENZxYzMzM5zmVUdJjEkkkzCAqoAioAAAAAEC4AAVRiKVVKqrLEUtqAAGWIpgAVVGIpYVqqtzEUtqkAVliI9MFVFcOHDfffZStrWta1rWsKJfEUyYZUIUpUEVOelAgBgA2nYcAOIHEABglv/sNt+u/gI3pwL6w4LQTEk79PxgktzXtEWfjlwmU9zEyStSha5DECpMVMdyJe5cHqWeGEIzOY2PKEx5RlU9sjzoJFDVLzGN1AYAEQ4CI5xMB8VBKRZEaxKQAJBaRJFaRSRlaDSEgkgJIAOADFArBJJJEHCRUaMP8XckU4UJCFVZLeA"));

```

## PHP, 948 Bytes

```
<?=gzinflate(base64_decode("vZbbattAFEXfA/mH+QNrNPdHSb4S35CVtgkGk6ZpWtqmxW0KBX98pTVuKfgCRSh62Mjj2XM4a/aMLTbNI7p+qHJ5sRNCCrHruFi9flor5cYvUm78QDm63LUnujn37KvQnaK6btdj7TWoRR3q0YDKZA9z+rH5mD+0LZejBTpHF+gwjhzAbFXu33VOaUympNm0bXdSoRo1qEUd6vcw53fNx9lj23LZ50ZXbM2SkVXEy3i2PYB5Nl3nn/+AGTiGCQrYFLApcFLgpMBJgZMCJ/UoXoVX4VV4FV6FV+FVdg/zKrYM0tV9oxVAXsXxLaifyBjpLb6SNOYUz43e8u2IFUbMyb6zGu85K1ydgNmhxmMOHAUcBRwNHA0cDRwNHA0cDRwNWI1X49V4DV6D1+A1eI3ewyzf0jgt3wDwlvc54zPQVUAuQVd+IHvvgEaeC94nIF1FxVsBc8Kabw6P+YvANMAxwDFOrOsbDwgOCA6AjjmOOQ6ADoAOgB6AHoAer8fr8Xq8/k8yC1KUk6vpnejVPxbvQcHIa1CUYFkwcwLq5Q9ggncM0orjvARjHg87G5Exs3w6DnPdMUwPHA8cH+ruZNJAkIlBLepQjzYAZfODUqtEU1SheLkzJXem5M6Uf+/MIXBK0GX3zd6VwOzHxAIqJ41jYM6A0+e9jMkkjXPmDEE6I8nTn0Bm5uLxOMxelzAvLw5v900HjzhWqAZp2ENDwC0BtwTcEnBLwC0BtwTccjgs+2/xWrwOr5NifaxQHf+CsC/jjcI9sfzC7qEDIj9ivGJX+7/YT8I+wFUx84Zvp8+id7SjDnbpVEeBlgO4ArgCuAK4ArgCuAK4ArgCRyHhKCQchYSjkKgTHdWNx4uW+F/H/0rfGAFaBpYCzT/xzuEYEOoh4zPAzoE53Z7Yow7Q9X4D"));

```

# Answer
> 3 votes
# GW-Basic, 598 bytes (tokenised file)

Unfortunately GW-Basic's text mode is limited to 80 columns. I tried squishing the table to make it fit, but that didn't look too pleasing so I had to use a graphical mode instead.

Below is the text source, with lines wrapped around at 80 columns for readability; take care that for the program to work it must be saved in code page 437. Should you try it out, you'll find it will flicker **a lot** while it's drawing. Sorry.

```
0 S$="+#zB¢0(Y%5k%2GkCUq*Y$ù╝%65SÅ.5H8ú¿ÅÅxIö}¥6Ç{NMLòΩ/ΘÉ}òY'=zI⌂úÅ8V├)û;tùU2δY
#EJ2$++£╪&Θ}óÉ{,ÇN7àmYƒ+7z)ÆH55<IPmTZ¥KÆûwyHS7┐₧óOk5╕æ┴âTtöPo2KWµÅ[╗%ú##mVWíkàƒ,
£q┘6▌òMso⌂/&#
1 SCREEN 9:DIM A%(169):L%=1:FOR R%=4 TO 314 STEP 35:FOR C%=4 TO 604 STEP 35:GOSU
B 3:IF K%GOTO 5ELSE GOSUB 3:C%=K%*35+C%:IF I%=118 THEN R%=R%+12
2 NEXT:NEXT:FOR R%=1 TO 3:LINE(109-(R%=3)*490,(R%=1)*82+330)-STEP(0,-68),0:FOR C
%=1 TO 3:LINE-STEP(6,12):LINE-STEP(-6,11):NEXT:LINE STEP(0,-35)-STEP(5,0),(R%AND
 1)*15:NEXT:LOCATE 23:END
3 IF L%<36 THEN B%=(ASC(S$)-35)*L%+B%:L%=L%*216:S$=MID$(S$,2)
4 K%=B%MOD 36:B%=B%\36:L%=L%\36:RETURN
5 SCREEN,,1:CLS:I%=ASC(MID$("`nn#r",INSTR("9YvG",CHR$(I%))+1))+I%-95:PRINT RIGHT
$(STR$(I%),3):PRINT" ";CHR$(K%+64);:GOSUB 3:PRINT CHR$((K%=0)*64+K%+96):GET(0,0)
-(23,27),A%:SCREEN,,0:PUT(C%+2,R%+5),A%:LINE(C%,R%)-STEP(35,35),,B:GOTO 2

```

GW-Basic doesn't save its files as efficiently as it could, so to get it down to 660 bytes you need to open the tokenised file in an editor and manually remove all the spaces but one, the end of file character and the garbage character before it. This will reduce its size to 660 bytes and it will still load and run just fine.

**Edit:** Since in this case it doesn't matter that the variables are integers, because the expected error is small and operations like `MOD` and `\` round anyway, we might as well turn them into floating point variables, saving a `%` token on each mention. And I noticed the number `35` occurs often enough that the five bytes it takes to save it into a variable are (just!) worth it. If you've been keeping score, you'll have noticed we saved 43 bytes and the file system agrees: we're down to 617 bytes.

**Edit:** By slightly changing `S$` I was able to shave off six more bytes: `(K=0)*64+` became `AND 127`.

**Edit:** Okay, so I remembered I wanted to change the way I store empty areas. This shaved off seven more bytes, four in `S$` and three more because `GOSUB 3:` was swapped out for `>9`. And I sacrificed some efficiency for another two bytes.

**Edit:** I broke through the 600 byte barrier! It's one thing to get something compact in a golfing language, but another thing to do it in a real-world language. And quite another thing yet if you manage it in GW-Basic of all things. `S$` got five bytes bigger, but I saved nine bytes by replacing `ASC(MID$(...))+I-95` with `I+1` and adding `IF K=1 ... ELSE` on line `1`.

```
0 S$="|R▐CñföfCσé╕»σε¡┤P╝l½║╙τ/a}µS╦┌]èp┼zµkµ\¢°┴+τ_╞E.₧í3?≥≈öéºµ9¬╚O?Ql'zç═┘E}ε
(ùRíHM4╥lΦ≥│6Æäb∞O@╗┘Z¿aú{2╚┤6╪╚M1cf▀ùütóQw»ùmÑíφÖ_0$kLô╩╣└u¥å█3Tìzæd±æñk)τW`╫≈å
¿b0sΓlqùV⌐█Ç8&
1 SCREEN 9:DIM A(180):L=1:W=35:FOR R=4 TO 314 STEP W:FOR C=4 TO 604 STEP W:GOSUB
 3:IF K=1 THEN GOSUB 3:I=K*2+57:C=C-WELSE IF K>9 GOTO 5ELSE C=K*W+C:IF I=118 THE
N R=R+12
2 NEXT:NEXT:FOR R=1 TO 3:LINE(109-(R=3)*490,(R=1)*82+330)-STEP(0,-68),0:FOR C=1
TO 3:LINE-STEP(6,12):LINE-STEP(-6,11):NEXT:LINE STEP(0,-W)-STEP(5,0),(R AND 1)*1
5:NEXT:LOCATE 23:END
3 IF L<36 THEN B=(ASC(S$)-W)*L+B:L=L*216:S$=MID$(S$,2)
4 K=B MOD 36:B=B\36:L=L\36:RETURN
5 SCREEN,,1:CLS:I=I+1:PRINT RIGHT$(STR$(I),3):PRINT" ";CHR$(K+55);:GOSUB 3:PRINT
 CHR$(K+96 AND 127):GET(0,0)-(W,W),A:SCREEN,,0:PUT(C+2,R+5),A:LINE(C,R)-STEP(W,W
),,B:GOTO 2

```

# Answer
> 3 votes
# Kotlin, ~~1688~~ ~~1667~~ 1664 bytes

Probably find some improvements to save bytes. But, got it working so I'm posting it. Thanks mazzy for 21 bytes declaring u. 3 more bytes removing template string and using u directly.

```
data class T(val n:String,val a:Int,val c:Int,val r:Int)
val n="H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg"
val l=List(118){i->T(""+n[i*2]+n[i*2+1],i+1,when(i){0->1;1->18;2,3->i-1;in 4..9->i+9;10,11->i-9;in 12..17->i+1;in 18..35->i-17;in 36..53->i-35;in 54..56->i-53;in 57..70->i-53;in 71..85->i-67;in 86..88->i-85;in 89..102->i-85;else->i-99},when(i){0,1->1;in 2..9->2;in 10..17->3;in 18..35->4;in 36..53->5;in 57..70->8;in 54..85->6;in 89..102->9;else->7})}
val u="_____"
fun Int.c()={val t=this
when {t<10->"  $t  "
t<100->"  $t "
else->" $t "}}()
fun g(r:Int,c:Int)=l.find{t->t.r==r&&t.c==c}
fun b(r:Int,c:Int)={val e=g(r,c)
val n=g(r+1,c)
if(e==null)Array(3){if(c<2)if(n==null||it<2)"       "
else " $u "
else if(g(r,c+1)!=null)if(n==null||it<2)if(r>7&&c==3)if((r+it)%2<1)"     \\"
else "     /"
else "     |"
else "$u|"
else if(n==null||it<2)"      "
else if((r<2&&c>12)||(r==3&&c>2&&c<12))"_$u"
else "$u "}
else if(c<2)arrayOf("|${e.a.c()}|","|  ${e.n} |","|$u|")
else if(r==6&&c==3)arrayOf("${e.a.c()}\\","  ${e.n} /","$u\\")
else if(r==7&&c==3)arrayOf("${e.a.c()}/","  ${e.n} \\","$u/")
else if(r==8&&c==17)arrayOf("${e.a.c()}\\","  ${e.n} /","$u\\")
else if(r==9&&c==17)arrayOf("${e.a.c()}/","  ${e.n} \\","$u/")
else arrayOf("${e.a.c()}|","  ${e.n} |","$u|")}()
fun p()={val a=Array(30){""}
var s=1
for(r in 0..8){for(c in 1..18){val o=b(r+1,c)
for(i in 0..2)a[r*3+i+s]+=o[i]}
if(r==6)s+=2}
a[0]=" $u"+" ".repeat(97)+u
a[23]=" ".repeat(19)+"_".repeat(83)
a}()

```

Try it online!

# Answer
> 3 votes
# C (gcc), ~~623~~ 610 bytes

```
#define E(a)s[x/18*3+a/7][x%18*6+a%7]
#define e(a,b,c)E(a)=E(b)=E(c)=
x;char*p="H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg",s[999][110];P(x){e(14,28,42)47,e(7,21,35)92;}main(i){for(memset(s,32,4e3);*p;E(17)=*p++,E(18)=*p++,sprintf(&E(9)," %-2d "+i/100,i),s[i++][-1]=10,e(7,14,21)e(13,20,27)'|',x+=x?i-5&~8?i-58&~32?i-72&~32?1:-67:55:11:17)e(1,2,3)e(4,5,22)e(23,24,25)e(26,(i<6|E(0)&4),1)P(P(P(147)+1)+69)+3;puts(s);}

```

Try it online!

Thank gastropner for 2 bytes(and more the thought) and cailingcat for 7 bytes

# Answer
> 2 votes
# Bash + openssl + bzcat, 787 bytes

```
echo 'QlpoOTFBWSZTWU4gJ1IAAWJ/gCARACBAAP/gP+/f/r/v3yRAAlzt0bO4giaaJsgT
Uymg0PKAADRpoM00IVqnqhn7ypRAaBkAABpo0AACMqQHtU9QaPUDJoGjQAAAACJR
RlH6oAAAAA0AAANMSCuPE35BdLsIJgW7goiXLgTDCVQoiN8VkWiQG+IUghSAMiiV
iBIIJQbSowuqP1azrEUckcN2TFkgjzP/NbraQIlwhHiEQoAFArk2cXwzozZiX2Fd
oDTrgQ9SNYtUrT6Y12TdAzMzmiIiBMoAAqAEzeZmZlBVQAABV70RDMzM3olunLqr
w27cODVi7KDMVsJhVbEN5HVmxiudB3tlkdzOjK62bamumQDNHkDYZJRGomJuEzpZ
Rkq6q50aVleQn2z3xsGbI0K++++66664zM70REeHz9AsBWiIiMY1rWAI2Y8qqqqq
z1JAQlAhJJJJJQgsYwFUYilaqqrLEUu1AAGWIpcAVVGIpnmcqq3mIpdrIArLER43
K0Vta1rWVK2ta1rWtawomVEUy4ZkIUpUEVMfJWACgBXdpWALEFiAAgnr2YfmfRnx
Ec7MD/cMXEaMOGC9smHqfF4imuDpVNjBGUY5rRfAkIWsm1IbjdqdKLXLljKdUEfP
dKpdJ0ti+i6yMsj2u51K5QUACIYCI9AqBe9YKKRZEaxKQAJBaRJFaRSRlaDSEgkg
JIAOADHArBJJJEHCRUaMP8XckU4UJBOICdSA'|openssl enc -d -base64|bzcat

```

The newlines are required. Outputs the periodic table to `stdout`.

# Answer
> 2 votes
# Powershell, bytes ~~1077~~ ~~937~~ ~~934~~ ~~906~~ ~~902~~ ~~888~~ ~~878~~ ~~842~~ ~~784~~ ~~688~~ ~~677~~ ~~673~~ ~~667~~ ~~651~~ 596 bytes

Port of Neil's Javascript

```
filter l{"{0,5}"-f("{0,-2} "-f$_)}filter m{"|$_|"}$z=(,(' '*95)*2+(($u='_'*5)+' '*61+'_'*29)+,(' '*59)*5+'_'*59|m)+,'|'*6+'\','/'*6
" $u"+' '*97+$u
-split"H,He
LiBe,BCNOFNe
NaMg,AlSiPSClAr
KCaSc,TiVCrMnFeCoNiCuZnGaGeAsSeBrKr
RbSrY,ZrNbMoTcRuRhPdAgCdInSnSbTeIXe
CsBaLa,CePrNdPmSmEuGdTbDyHoErTmYbLu,HfTaWReOsIrPtAuHgTlPbBiPoAtRn
FrRaAc,ThPaUNpPuAmCmBkCfEsFmMdNoLr,RfDbSgBhHsMtDsRgCnNhFlMcLvTsOg"|%{if(($b=$_-split','|%{(($s=$_-csplit'(.[a-z]?)'-ne'')|%{++$i|l}),($s|l),($s|%{$u})|%{$_-join'|'}})[8]){$a+=$b[3..5]}0..2|%{$b[$_]+$z[$j++]+$b[$_-3]}}|m
''
' '*18+'_'*84
$a|%{' '*18+($s=$z[$j++])+$_+$s}

```

Append `rv i,j,a` to the end of the script to able `restart`.

## Ungolfed

```
# return formated label or number
filter l{"{0,5}"-f("{0,-2} "-f$_)}

filter m{"|$_|"}

# fillers
$z=(,(' '*95)*2+(($u='_'*5)+' '*61+'_'*29)+,(' '*59)*5+'_'*59|m)+,'|'*6+'\','/'*6

# output the periodic table rows
" $u"+' '*97+$u

# transform each label row to array of numbers, labels and separators
# insert a filler from $z[$j++] between first and last groups of 3 lines
# return 3 completed lines (left+filler+right)
# append middle group (Lanthanides and Actinides) to $a if the group is specified
-split"H,He
LiBe,BCNOFNe
NaMg,AlSiPSClAr
KCaSc,TiVCrMnFeCoNiCuZnGaGeAsSeBrKr
RbSrY,ZrNbMoTcRuRhPdAgCdInSnSbTeIXe
CsBaLa,CePrNdPmSmEuGdTbDyHoErTmYbLu,HfTaWReOsIrPtAuHgTlPbBiPoAtRn
FrRaAc,ThPaUNpPuAmCmBkCfEsFmMdNoLr,RfDbSgBhHsMtDsRgCnNhFlMcLvTsOg"|%{
    if(($b=$_-split','|%{
        (($s=$_-csplit'(.[a-z]?)'-ne'')|%{++$i|l}),
        ($s|l),
        ($s|%{$u})|%{
            $_-join'|'
        }
    })[8]){
        $a+=$b[3..5]
    }
    0..2|%{
        $b[$_]+$z[$j++]+$b[$_-3]
    }
}|m
''
' '*18+'_'*84
$a|%{' '*18+($s=$z[$j++])+$_+$s}

```

# Answer
> 1 votes
# Retina, 888 bytes

```

 }~~xJ }¶|J1J|~~x>JwHJ|~~x{He@|}|}xJ q____|}w3j4J|x;j6j7j8j9j10 wLi{Be |x{BjCjNjOjFjNe@|}|}|x "w11{12 |x{13{14{15{16{17{18 wNa{Mg |x!l{Si:jSjCl!r@]qq____"w19>0>1>2>3>4>5>6>7>8>9-0-1-2-3-4-5-6 wKjCa{Sc{Ti{VjCr{Mn{Fe{Co{Ni{Cu{Zn{Ga{Ge!s{Se{Br{Kr@"""w37-8-9=0=1=2=3=4=5=6=7=8=9;0;1;2;3;4 wRb{Sr{YjZr{Nb{Mo{Tc{Ru{Rh:d!g{Cd{In{Sn{Sb{Te{IjXe@"""w55;6;7 \J72,3,4,5,6,7,8,9'0'1'2'3'4'5'6 wCs{Ba{La /JHf{Ta{WjRe{Os{Ir:t!u{Hg{Tl:b{Bi:o!t{Rn@]\Q|}w87'8'9 / 104&5&6&7&8&9%0%1%2%3%4%5%6%7%8 wFr{Ra!c \JRf{Db{Sg{Bh{Hs{Mt{Ds{Rg{Cn{Nh{Fl{Mc{Lv{Ts{Og@]/Q|}|¶¶~qqq}____ ¶~\J58;9<0<1<2<3<4<5<6<7<8<9,0,1 \¶~/JCe:r{Nd:m{Sm{Eu{Gd{Tb{Dy{Ho{Er{Tm{Yb{Lu /¶~\Q\¶~/J90#1#2#3#4#5#6#7#8#9&0&1&2&3 /¶~\JTh:a{UjNp:u!m{Cm{Bk{Cf{Es{Fm{Md{No{Lr \¶~/Q/
!
{A
"
]]
#
{9
%
z1
&
z0
'
{8
,
{7
-
{3
:
{P
;
{5
<
{6
=
{4
>
{2
@
 |¶
J

Q
}]]]]|}
j
 {
q
}}}}}
w
|¶|
x
~~~
z
 | 1
]
|}|}|}
{
 |
}
_____
~

```

Try it online!

# Answer
> 1 votes
# C++, 866 bytes

```
#import<bits/stdc++.h>
#define S std::string
#define R .replace
#define F(a,b,c,d)for(a=b;a<c;a+=d)
#define G(b)F(i,b,31,1)
#define a A[i]
int i,j,t;main(){S*A=new S[31];G(0)a="|"+(i%3?S(108,32):S(107,95)+' ');A[0]R(6,95,95,32);A[6]=A[3]R(12,59,59,32);F(j,6,109,6)G(t=1)!t|A[i-1][j-1]^32?t=0,a[j]='|':0;G(22)a=' '+a.substr(0,i<24?j=0:85);F(i,1,31,3)for(t=0;~(t=a.find("|     |",t));j=j^56?j^88?j^117?j^70?j+1:89:57:103:71)A[i+1]R(t+3,2,"H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg",j*2,2),a R(t+2,j>8?3:2,(j>98?"":" ")+std::to_string(j+1));G(25)a[1]=a[85]=A[i-9][18]=i&1?92:47;A[24]=" "+S(84,95);i=0;a[0]=a[101]=a[102]=A[3][71]=A[3][72]=A[6][71]=32;G(0)std::cout<<a<<'\n';}

```

Ungolfed version:

```
#include <bits/stdc++.h>

using namespace std;

string els = "H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg";

int main()
{
    vector<string> ans(31, "|" + string(108, 32));
    for (int i = 0; i < 31; i += 3)
        ans[i] = "|" + string(107, 95)+' ';             // horizontal lines
    ans[0].replace(6,95,95,32);
    ans[3].replace(12,59,59,32);                        // clear some lines
    ans[6].replace(12,59,59,32);
    for (int i = 6; i <= 108; i += 6)
        for (int j = 1, t = 0; j < 31; j++)
            if (t|ans[j-1][i-1]!=32) t=1,ans[j][i]='|'; // vertical lines
    for (int i = 22; i < 31; i++)
        ans[i]=' '+ans[i].substr(0,i<24?0:85);          // remove cells between parts
    for (int i = 1, j = 0; i < 31; i += 3) {
        int t=0;
        while(~(t = ans[i].find("|     |",t))) {        // find a cell
            ans[i+1].replace(t+3,2,els,j*2,2);          // fill name
            ans[i].replace(t+2,j>8?3:2,(j>98?"":" ")+to_string(j+1)); // fill atomic number
            j=j^56?j^88?j^117?j^70?j+1:89:57:103:71;    // next cell
        }
    }
    for (int i = 25; i < 31; i++)
        ans[i][1]=ans[i][85]=ans[i-9][18]=i&1?92:47;    // wavy lines
    ans[24]=" "+string(84,95);                          // reset the first line of the second part
    ans[0][0]=ans[0][101]=ans[0][102]=ans[3][71]=ans[3][72]=ans[6][71]=32; // minor edits
    for (auto i : ans) cout << i << endl;
}

```

---

# Python 3, 730 bytes

```
import lzma,base64
print(lzma.decompress(base64.b85decode("T>t=p0RR90|NsC0{{Rpd@Pr$w-*8%~!=Rn5Pm7UVqBC5v9Zg6LfW&}*+O=ziY>}RL7H;N`68rv%5rHo*1j;XROG{S~5LdQ~BFg$x8B^QtOzAFAZjB>8=k@=h&&c?Q%F3xURR*-Pndp~Y0zlY74sr-TW3Zd)nAM>*=A(x|SBB$&#S+q%k6Dq;D5iDORZn`cx|)ahM*kG8f5J9tFU28-&|-&$rKujnI$Ct|5lxHm7Q;d|EFM&p&cfr+mrOgvg-2PXY}<0hm!sCs+~MJ}+AvfKubl|YMYol-0O|xBfr`s~?3$-5CZy*nbw@cugNQWVmvNd#ZT{u(L~~hJc-?0{ShpeGgVr3#H{G6K{s~IBGOnI2*NvtpbvD{0-OTPLa@;13xt#)GYNyC>Aagh~S@aj6;Cx*hHbhQL#8xCP!axutBybVK3MJn?r54EAMdD{py(_#s<OTbPJ`CeF5l=^KQ|FT!H&DuDv(8G#b+7E%t?!pfko{I5?i#LfmYI&qA`eBz%_VAZqq{kpF{BJ@ZtLMk$_AC?xs#r8lUGZMw;EEPQysR|;q)X{OvS-fq7&&EWhn@Af`pVXR_j#&YAB!kx3|rr;BkcHP({82nUY&)kTq~vZ$bHSbbL*b+}RG!)Zj5U)<1e8727+LBCTn55Y>!3TR;5@SMv")).decode())

```

# Answer
> 1 votes
# ///, ~~987~~ 958 bytes

```
/J/\/\///í/				Jù/____Jú/
x\\Jà/z1Já/\/!JQ/q
J	/ :Jj/  Jq/ |Jx/$^^Jw/$$$$Jz/ | J:/ù_J;áTJ~áSJ`áRJ-áLJ+áHJ=áBJ?áAJ>áNJ<áPJ.áFJ,áMJ"áCJ'á9J]á8J[á7J}á6J{á5J)á4J(á3J*á2J&á1J^/    J%/@@@@@@J$/  ^^J#/|  J@/ù_|/á/ |  /	ww$^j
#1 !ww$j* Q#H !ww$j+eQ|@:w$$	:::ù@@
#3 ) !w$^j{ } [ ] ' &0Q#Li=e!w$^j= " > !O . >eQ|@@wxq%
#11&2!w$^j&3&4&5&6&7&8Q#Na,g!w$^j?l~i< ~ "l?rQ|@@::::::::::ù%@
#19*/§/0*1*2*3*4*5*6*7*8*9/§(0(1(2(3(4(5(6Q#K "a~c;i!V "r,n.e"o>i"u!Zn!Ga!Ge?s~e=r!KrQ|%%%
#37(8(9)/*/)/§{0{1{2{3{4Q#Rb~r!Y !Zr>b,o;c`u`h<d?g"d!In~n~b;e!I !XeQ|%%%
#55{6{7 \\j72[3[4[5[6[7[8[9]0]1]2]3]4]5]6Q#Cs=a-a \/jHf;a!W `e!Os!Ir<t?u+g;l<b=i<o?t`nQ|@@:\\%%@@@
#87]8]9 \/ 104à05à06à07à08à09à10à11à12à13à14à15à16à17à18Q#Fr`a?c \\jRf!Db~g=h+s,t!Ds`g"n>h.l,c-v;s!OgQ|@@:\/%%@@@

x:_ííí	ú\j58{9}/*/}/§[0[1 \\ú/jCe<r>d<m~m!Eu!Gd;b!Dy+o!Er;m!Yb-u \/ú\%%@:\\ú/j9/*/'/§à00à01à02à03 \/ú\jTh<a!U >p<u?m"m=k"f!Es.m,d>o-r \\ú/%%@:\/

```

Try it online!

I tried

# Answer
> 1 votes
# Canvas, 289 bytes

```
ø“^,＞ø0ｐk↶┘？6－ｗF－ｃ⁶DI2Ｅr„‾⁴┬３ｎ０Ｘ｛┤Ｙ┘┘｛┐┌ω＋┤６×ｙ３× ３_×＋|２＊∔┼（ｖ：“ko±╫ＪＨ(:)⇵↙↕ｌ╷-Ｎ6 ↶±A)！|¾ｂｋｉ＃ＬＯiＣ０÷１c─↔k⁵IＹｈ╬%÷╶１B－-uｌ＠%Ａ%⁵KＵ/iＥ╷＠Ｌ0≤｝ｎＪＤ«↑７Ｅ;ｐMＪ2↓Zx^９{t９╴Y０[9◂ ?↙ø╬０N４＠⇵║ＭXh＃Ｈ«；g→zc-X８4］Fk`⁸OＯ^»^Ｌ]U４Ｚ¼e＼０w┤∙ｐjｐ8←|═９±±→╵Mｔ⁵L@|Oｎ !±ｂ⁹2R⁰‟２ｎ├＠ ４×）ｒ３２╋∙╋｝｝“５７ｑ‼(„‾;┬３ｎ｛┤_×╋｝“¾├W↓5„‾X┬２ｎ｛┤/\３×↷╋

```

Try it here!

# Answer
> 0 votes
# Python 3, <sup>815</sup> 768 bytes

```
q=range
u,*D='_'
I={(24,18):u}
for c in q(102):I[(c<73)*6+3,c]=u
i=r=c=0
for Z in('1,c=102,1,,'+'2,c=72,6,,'*2+'18,,'*2+'3,r=%d,14,r=%d,c=18,15,,'*2%(24,15,27,18)).split(','):
 if'1'>Z:r+=3;c=0
 elif'a'>Z:
  for _ in q(int(Z)):D+=[(r,c)];c+=6
 exec(Z)
for R,C in D:
 for X in u*5,str(i+1),'H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg'[2*i:][:2],u*6:
  c=C+1
  for z in X.center(5):I[R,c]=z;c+=1
  if'_'*5!=X:I[R,C]=I[R,C+6]='|'
  R+=1
 i+=1
for r,c in(16,18),(25,18),(25,102):
 for i in q(6):I[r+i,c]='\\/'[i%2]
for r in q(31):print(*(I.get((r,c),' ')for c in q(109)),sep='')

```

Try it online!

I particularly like the magic string `1,c=102,...` encoding the layout of the table.

Commented:

<pre><code>q=range
u,*D='_'

# I is an ascii art "canvas". I[y,x] = character at that location
I={(24,18):u}

# Draw (into I) top lines
for c in q(102):I[(c<73)*6+3,c]=u

i=r=c=0

# Read a magic string '1,c=102...' to construct D.
#
# After the loop, D = [(0, 0), (0, 102), (3, 0), (3, 6), (3, 72), ...]
#
# The i'th item in D gives the y,x coordinates of the top-left corner of the
# i'th element:
#
# [(0, 0), (0, 102), (3, 0), (3, 6), (3, 72), ...]
#  H       He        Li      Be      B
for Z in('1,c=102,1,,'+'2,c=72,6,,'*2+'18,,'*2+'3,r=%d,14,r=%d,c=18,15,,'*2%(24,15,27,18)).split(','):
    if'1'>Z:r+=3;c=0
    elif'a'>Z:
        for _ in q(int(Z)):D+=[(r,c)];c+=6
    exec(Z)

# Draw (into I) the table, excluding slashes
for R,C in D:
    for X in [
         u*5,       # Draw horizontal line (top)
         str(i+1),  # Draw atomic number
         # Draw element symbol
         'H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg'[2*i:][:2],
         u*6        # Draw horizontal line (bottom)
    ]:
        c=C+1
        for z in X.center(5):I[R,c]=z;c+=1
        if'_'*5!=X:I[R,C]=I[R,C+6]='|'  # Draw vertical lines
        R+=1
    i+=1

# Draw (into I) the slashes
for r,c in(16,18),(25,18),(25,102):
    for i in q(6):I[r+i,c]='\\/'[i%2]

# Print the canvas
for r in q(31):print(*(I.get((r,c),' ')for c in q(109)),sep='')
```
</code></pre>

# Answer
> 0 votes
# Python 3.8 (pre-release), 699 bytes

```
U,S,P,*I='_ |'
Q=range
i=0
for N in[2,8,8,18,18,32,32]:
 A,B,*C=[],[],;I+=A,B,C
 for _ in Q(N):B+=P,'H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg'[2*i:][:2].center(5);A+=P,str(i:=i+1).center(5);C+=P,U*5
for i in Q(3):I[i][2:2]=[P+S*95]
for i in Q(3,9):I[i][4:4]=[P+[U,S][i<8]*59]
I+=[S*1+U*84],
for i in Q(15,21):I+=[[S]+I[i][6:34]];I[i][6:34]=[]
I[2][2]=P+U*5+S*61+U*29
for r in I:r+=P
I[21][-1]=''
for r,R in zip(I[15:21],I[22:]):r[6]=R[1]=R[-1]='\\/'[i%2];i+=1
for r in[S+U*5+S*97+U*5]+I:print(*r,sep='')

```

Try it online!

Shortest Python solution! Used a similar approach to the Ruby solution by Lever River St. The first loop generates this output and the rest rearranges it and adds the missing lines and slashes.

```
|  1  |  2
|  H  |  He
|_____|_____
|  3  |  4  |  5  |  6  |  7  |  8  |  9  |  10
|  Li |  Be |  B  |  C  |  N  |  O  |  F  |  Ne
|_____|_____|_____|_____|_____|_____|_____|_____
|  11 |  12 |  13 |  14 |  15 |  16 |  17 |  18
|  Na |  Mg |  Al |  Si |  P  |  S  |  Cl |  Ar
|_____|_____|_____|_____|_____|_____|_____|_____
|  19 |  20 |  21 |  22 |  23 |  24 |  25 |  26 |  27 |  28 |  29 |  30 |  31 |  32 |  33 |  34 |  35 |  36
|  K  |  Ca |  Sc |  Ti |  V  |  Cr |  Mn |  Fe |  Co |  Ni |  Cu |  Zn |  Ga |  Ge |  As |  Se |  Br |  Kr
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____
|  37 |  38 |  39 |  40 |  41 |  42 |  43 |  44 |  45 |  46 |  47 |  48 |  49 |  50 |  51 |  52 |  53 |  54
|  Rb |  Sr |  Y  |  Zr |  Nb |  Mo |  Tc |  Ru |  Rh |  Pd |  Ag |  Cd |  In |  Sn |  Sb |  Te |  I  |  Xe
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____
|  55 |  56 |  57 |  58 |  59 |  60 |  61 |  62 |  63 |  64 |  65 |  66 |  67 |  68 |  69 |  70 |  71 |  72 |  73 |  74 |  75 |  76 |  77 |  78 |  79 |  80 |  81 |  82 |  83 |  84 |  85 |  86
|  Cs |  Ba |  La |  Ce |  Pr |  Nd |  Pm |  Sm |  Eu |  Gd |  Tb |  Dy |  Ho |  Er |  Tm |  Yb |  Lu |  Hf |  Ta |  W  |  Re |  Os |  Ir |  Pt |  Au |  Hg |  Tl |  Pb |  Bi |  Po |  At |  Rn
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____
|  87 |  88 |  89 |  90 |  91 |  92 |  93 |  94 |  95 |  96 |  97 |  98 |  99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118
|  Fr |  Ra |  Ac |  Th |  Pa |  U  |  Np |  Pu |  Am |  Cm |  Bk |  Cf |  Es |  Fm |  Md |  No |  Lr |  Rf |  Db |  Sg |  Bh |  Hs |  Mt |  Ds |  Rg |  Cn |  Nh |  Fl |  Mc |  Lv |  Ts |  Og
|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____

```

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


title: Iteratively delete a list

text:
# Question
Title: Iteratively delete a list
Say I have a ragged list, like:

```
[
  [1, 2],
  [3,
    [4, 5]
  ]
]

```

And I want to iterate over each item and delete it one-by-one. However, I don't know the structure of the list.

So, I have to iterate over the list, with the following algorithm:

* Look at the first item of the list.
* If it's a list, concatenate it to the start of the rest of the list.
* Else, delete it.

For example, with the above example `[[1, 2], [3, [4, 5]]]`:

* `[1, 2]` is a list. Concatenate it - `[1, 2, [3, [4, 5]]]`
* `1` is a number. Delete it - `[2, [3, [4, 5]]]`
* `2` is a number. Delete it - `[[3, [4, 5]]]`
* `[3, [4, 5]]` is a list. Concatenate it - `[3, [4, 5]]`
* `3` is a number. Delete it - `[[4, 5]]`
* `[4, 5]` is a list. Concatenate it - `[4, 5]`
* `4` is a number. Delete it - `[5]`
* `5` is a number. Delete it - `[]`

There are no more items left, so our work is done.

Your challenge is to compute the sizes of the lists resulting from applying this. For example, with the above, the list starts with length 2. It then goes to lengths 3, 2, 1, 2, 1, 2, 1, 0.

Standard rules apply - that is, you may take a list \\$l\\$ and generate all terms, or take a list \\$l\\$ and a number \\$n\\$ and calculate the nth or first n terms. Your results may or may not contain the length of the initial list at the start, and the 0 at the end, and you may take \\$n\\$ 0-indexed or 1-indexed.

Since only the shape of \\$l\\$ matters, you may take it filled with any consistent value instead of arbitrary integers.

\\$l\\$ may contain empty lists. In this case, it's concatenated as normal and the length decreases by 1.

This is , shortest wins!

## Testcases

These include the leading length but not the trailing 0. Reference implementation

```
[[1, 2], [3, [4, 5]]] -> [2, 3, 2, 1, 2, 1, 2, 1]
[[6, 3, [1, 3, 4]], 4, [2, 3, 9, [5, 6]]] -> [3, 5, 4, 3, 5, 4, 3, 2, 1, 4, 3, 2, 1, 2, 1]
[3, 4, 5] -> [3, 2, 1]
[[[[[[[[1]]]]]]]] -> [1, 1, 1, 1, 1, 1, 1, 1]
[] -> []
[1, [], 1] -> [3, 2, 1]
[[],[[[]]],[]] -> [3, 2, 2, 2, 1]

```

# Answer
> 6 votes
# , ~~62~~ 61 bytes

*Edit: -1 byte thanks to pajonk*

```
f=\(l)if(h<-length(l))c(h,f(c(if(is.list(g<-el(l)))g,l[-1])))
```

Attempt This Online!

# Answer
> 5 votes
# Python 2, 44 bytes

```
def f(x,*r):print-~len(r);x>{}<f(*x+r);f(*r)
```

Attempt This Online!

Prints to STDOUT; terminates with an error.

# Whython, 37 bytes

-7 bytes thanks to @ovs

```
def f(x,*r):print(len(r)+1);f(*x+r?r)
```

Attempt This Online!

Despite being Whython, this still also terminates with an error.

# Answer
> 5 votes
# APL (Dyalog Unicode), ~~27~~ 25 bytes

Anonymous prefix lambda.

```
{×⎕←≢⍵:∇((0≠≡⊃⍵)/⊃⍵),1↓⍵}

```

Try it online!

`{``}` "dfn"; argument is :

`≢⍵` tally the argument

`⎕←` print that

`×` signum of that

`:` if 1 (i.e. there's content):

`1↓⍵` drop the first element of the argument

`(``),` prepend:

`⊃⍵` the first element of the argument

`(``)/` replicated by (i.e. if the following holds true):

`⊃⍵` the first element of the argument

`0≠≡` is its depth different from zero? (i.e. a list)

recurse

# Answer
> 5 votes
# JavaScript (Node.js),  ~~55 53~~  52 bytes

*Saved 2 bytes thanks to @pfg*
*Saved 1 more byte thanks to @tsh and @pfg*

```
f=a=>[n=a.length,...n?f(a.shift().concat?.(a)??a):a]

```

Attempt This Online!

### Commented

```
f = a =>           // f is a recursive function taking the input list a[]
[                  // build the output:
  n = a.length,    //   append the length of a[] and save it in n
  ...n ?           //   if a[] is not empty:
    f(             //     do a recursive call:
      a.shift()    //       extract the leading entry and attempt to
      .concat?.(a) //       concatenate it with the remaining entries
      ??a          //       if it fails, just append a[] (the leading entry
                   //       was not an array)
    )              //     end of recursive call
  :                //   else:
    a              //     stop the recursion and return a[] (which is empty)
]                  // end of output

```

# Answer
> 4 votes
# 05AB1E, 10 bytes

```
ΔDg,ćDi\ëì

```

A byte is saved by taking the input filled with `1`s instead of positive integers.
Outputs the lengths on separated newlines to STDOUT, including a trailing 0.

Try it online or verify all test cases.

**Explanation:**

```
Δ      # Loop until the result no longer changes (e.g. until the list is empty):
 D     #  Duplicate the current list
  g    #  Pop and push the length
   ,   #  Pop and output this length with trailing newline to STDOUT
 ć     #  Extract head; pop and push remainder-list and first item separately
  D    #  Duplicate this extracted head
   i   #  If it's a 1:
    \  #   Discard it from the stack
   ë   #  Else (it's a list instead)
    ì  #   Prepend-merge it to the remainder-list

```

# Answer
> 4 votes
# K (ngn/k), 24 bytes

```
#'{$[t~*t:*x;!0;t],1_x}\

```

Try it online!

Output includes the length of the initial list and a 0 at the end.

* `{...}\` set up a scan-converge, seeded with the (implicit) input and run until two successive iterations return the same result
    + `$[t~*t:*x;!0;t]` using `$[c;t;f] cond`, check if the first item is a list or an atom. if it is an atom, return an empty list (`!0`); if it is a list, return the first element of that list
    + `,1_x` append the remainder of the list (dropping the first item)
* `#'` return the number of items in each iteration

# Answer
> 3 votes
# Stax, 15 bytes

```
Ö┬☻╪<æ·ë97╞φº♠B

```

Run and debug it

# Stax, 16 bytes

```
ü╜←Φ■Yxbo╟ⁿ▀í▼ε~

```

Run and debug it

a generator.

# Answer
> 3 votes
# Charcoal, (16) 21 bytes

```
Ｗθ«⟦ＩＬθ⟧≔⁺∨＆⁰§θ⁰υΦθλθ

```

Try it online! Link is to verbose version of code. Explanation:

```
Ｗθ«

```

Repeat until the input list is empty.

```
⟦ＩＬθ⟧

```

Output its length on its own line.

```
≔⁺∨＆⁰§θ⁰υΦθλθ

```

Add the tail of the list to the first element.

* This would be three bytes shorter if the list was to be iteratively deleted from the end rather than the start.
* This would be four bytes shorter if Charcoal's vectorising `Add` worked properly, but unfortunately it only vectorises to depth 1. (Other operators, such as `BitwiseAnd`, do vectorise correctly, so I'm assuming this is an oversight. Edit: Ironically, `Times` also doesn't vectorise correctly, so I needed to replace it with `BitwiseAnd` to fix a bug.)
* Alternatively, this could be two bytes shorter if the input integers were all zero. (Not applicable when vectorising `Add` works properly.)
* This could be one byte shorter by outputting the last length instead of the first.

16 bytes using the newer version of Charcoal on ATO:

```
Ｗθ«≔⁺§θ⁰Φθλθ⟦ＩＬθ

```

Attempt This Online! Link is to verbose version of code. Outputs the last length instead of the first.

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

```
Print[i+=Length@#-1]#0/@#&[i=1;#]&

```

Try it online!

Prints the lengths. Includes a trailing `0`.

```
Print[i+=Length@#-1]#0/@#&[i=1;#]&
                          [i=1;#]   initialize i=1 before run
                    #0/@#           in depth-first, prefix order:
      i+=Length@#-1                   add length-1 to i (atoms have length 0)
Print[             ]                  print i

```

# Answer
> 3 votes
# JavaScript (ES2019), ~~51~~ ~~48~~ 47 bytes

```
i=0;f=(v=[])=>[i+=v.length-!!i,...v.flatMap(f)]

```

Attempt This Online!

Input requires `undefined` as leaves. Output includes initial size and trailing `0`.

I assume the output must be a flat array instead of allowing nested array. If nested array is acceptable then there is this 40-byte solution:

```
i=0;f=(v=[])=>[i+=v.length-!!i,v.map(f)]

```

## Algorithm

Instead of implementing the specified process and constructing the intermediate arrays, this submission uses an analytical solution to calculate the output.

Notice that, with the process in the question, each item of the root array is completely deleted before moving on to the next item. Using the original example `[[1,2],[3,[4,5]]`, the `[1,2]` subarray is fully deleted before `[3,[4,5]]` is touched. This means that while processing `[1,2]`, the sizes of the intermediate arrays at each step is the same as those while processing `[1,2]` as a root, but plus 1 because we have to count `[3,[4,5]]`

```
[[1, 2], [3, [4, 5]]]
[1, 2, [3, [4, 5]]]   (size: 3)        |        [1,2]   (size: 2)
[2, [3, [4, 5]]]      (size: 2)        |        [2]     (size: 1)
[[3, [4, 5]]]         (size: 1)        |        []      (size: 0)

```

Take another example from the test cases

```
[[6, 3, [1, 3, 4]], 4, [2, 3, 9, [5, 6]]]
[6, 3, [1, 3, 4], 4, [2, 3, 9, [5, 6]]]   (size: 5)        |        [6, 3, [1, 3, 4]] (size: 3)
[3, [1, 3, 4], 4, [2, 3, 9, [5, 6]]]      (size: 4)        |        [3, [1, 3, 4]]    (size: 2)
[[1, 3, 4], 4, [2, 3, 9, [5, 6]]]         (size: 3)        |        [[1, 3, 4]]       (size: 1)
[1, 3, 4, 4, [2, 3, 9, [5, 6]]]           (size: 5)        |        [1, 3, 4]         (size: 3)
[3, 4, 4, [2, 3, 9, [5, 6]]]              (size: 4)        |        [3, 4]            (size: 2)
[4, 4, [2, 3, 9, [5, 6]]]                 (size: 3)        |        [4]               (size: 1)
[4, [2, 3, 9, [5, 6]]]                    (size: 2)        |        []                (size: 0)

```

The size difference is 2 here because there are 2 items after the item being processed (`[6, 3, [1, 3, 4]]`).

This shows that this problem can be solved with a recursive algorithm

```
f([1, 2]) = [2, 1, 0]
f([3, [4, 5]]) = [2, 1, 2, 1, 0]

                                [2, 1, 0][2, 1, 2, 1, 0]
                           + [2,       1,             0]
                           --------------------------------
f([[1, 2], [3, [4, 5]]]) =   [2, 3, 2, 1, 2, 1, 2, 1, 0]

```

More precisely, the output of processing an array consists of:

* The initial length of the array, then
* For each item, the result of processing that item, plus adding the number of items after it to each element.

### Naive, readable implementation

```
function f(value) {
    if (value !== undefined) {
        return [
            value.length,
            ...value.flatMap((item, index) => f(item).map((n) => n + value.length - index - 1))
        ]
    }
    return [0]
}

```

## Golfing

First, of course, is to apply basic golfing techniques

```
// 70 bytes
f=v=>v?[v.length,...v.flatMap((u,j)=>f(u).map($=>$+v.length-j-1))]:[0]

```

Then, since leaves are `undefined`, we can actually use default argument to treat leaves as `[]` and merge the two branches

```
// 69 bytes
f=(v=[])=>[v.length,...v.flatMap((u,j)=>f(u).map($=>$+v.length-j-1))]

```

Then, instead of mapping a second time to add the "base" value `v.length-j-1`, we can make `f` accept a second argument for a value to add to everything.

```
// 67 bytes
f=(v=[],i=0)=>[v.length+i,...v.flatMap((u,j)=>f(u,v.length+i-j-1))]

```

Next, we can pull `i` up to the global scope and mutate it instead of passing it around and using a lengthy expression to calculate the base

```
// 53 bytes
i=0;f=(v=[])=>[i+=v.length,...v.flatMap(u=>f(u,i--))]

```

Finally, we can move the `i--` decrement into `f` so that, instead of decrementing at each `flatMap` iteration, we just decrement `i` at the start of `f`.

```
// 45 bytes
i=1;f=(v=[])=>[i+=v.length-1,...v.flatMap(f)]

```

**BUT**, this breaks because the global variable `i` is changed after calling `f`, which is forbiddened. Specifically, `i` is decremented by 1 for each root call to `f`. Before the change, `i` is decremented by 1 by one per child while looping in `flatMap`, but now `i` is decremented by 1 per call (i.e. per node), and the root is the only node that is not a child.

To counter this, we need to change the increment to "number of children" (instead of "number of children - 1") but only for the root node. This is doable by noticing that `i` is at its initial value only at the start of a root `f` call and after processing the last leaf. So we can initialize `i` to 0 and when we increment `i`, we increment by "number of children" if `i` is 0 but by "number of children - 1" otherwise.

```
// 47 bytes
i=0;f=(v=[])=>[i+=v.length-!!i,...v.flatMap(f)]

```

# Answer
> 2 votes
# Jelly, 11 bytes

```
OḢ;$Ḋ⁼¡µƬẈṖ

```

A monadic Link that accepts a ragged list of integers and yields the lengths as a list, including both the initial length and a trailing `0`.

**Try it online!** Or see the test-suite.

### How?

```
OḢ;$Ḋ⁼¡µƬẈṖ - Link: ragged list of positive integers, L
        Ƭ   - collect input, X (initially L), while distinct, applying:
       µ    -   this monadic chain - f(X):
O           -     ordinal value (vectorises) -- only here to get us a copy of X
                                                so that we don't mutate it with Ḣ
   $        -     last two links as a monad - f(Y=that):
 Ḣ          -       head Y (alters Y, yields the first element or 0 when given [])
  ;         -       concatenate that with (the altered Y)
      ¡     -     if...
     ⁼      -     ...condition: that equals X? (head of X was an integer)
    Ḋ       -     ...then: dequeue
         Ẉ  - length of each
          Ṗ - pop the last length (removes the trailing 1, the length of 0)

```

---

Also 11 with no  and, therefore, no `O`: `1ị;ḊḊ⁼¡µƬẈṖ`

# Answer
> 2 votes
# JavaScript (ES5),  ~~84~~  80 bytes

*Saved 4 bytes thanks to @tsh*

```
function(a){for(r=[];m=a.shift(r.push(a.length));)a=m[0]?m.concat(a):a;return r}

```

Try it online!

Formatted and renamed:

```
function(array){
    result = [];
    while(
        result.push(array.length),
        current = array.shift()
    ) {
        if(current !== +current) { // if current is not a number
            array = current.concat(array);
        }
    }
    return result;
}

```

# Answer
> 2 votes
# BQN, 26 bytes

```
{(≠∾·=∘⊑◶⟨⟩‿⊑∾1⊸↓)⍟(×≠)}

```

Try it here!

-1 byte thanks to @DLosc!

## Explanation

* `≠∾·...` append input length to...
* `(...)⍟(×≠)` if input is nonempty...
* `...∾1⊸↓` append tail to...
* `=∘⊑◶⟨⟩‿⊑` head if head is rank 1 (i.e. list), otherwise empty list
* recurse

# Answer
> 2 votes
# Rust, <sup>~~19~~ ~~194~~ ~~185~~</sup> 174 bytes

Even defining a type for a ragged list is bytes intensive in rust. Still shorter than C :)

```
enum K{N,Y(Vec<K>)}fn f(k:&K,n:usize)->Vec<usize>{if let K::Y(b)=k{[n+b.len()].into_iter().chain((1..).zip(b).map(|(i,z)|f(z,b.len()+n-i)).flatten()).collect()}else{vec![n]}}

```

Sequences will have a extra 0 at the end. Verify all test cases

-9 bytes by using `Vec` instead of array slices

-11 bytes by replacing `enumerate` with `zip` and `match` with `if let`

# Answer
> 1 votes
# Factor, 57 bytes

```
[ [ dup length . unclip [ prepend ] when* ] until-empty ]

```

Try it online!

Input consists of ragged sequences of `f` — Factor's canonical false value — as this saves about 20 bytes over integers.

* `[ ... ] until-empty` Call `[ ... ]` on the input until it's empty.
* `dup length .` Print the current length of the input non-destructively.
* `unclip` Remove the first element from the sequence and place it on top of the data stack.
* `[ prepend ] when*` `when*` is like `when` except it drops its input value if it's false, but retains its input if it's true (which is any non-false value in Factor). So, prepend it to the input if it's a sequence, or drop it if it's `f`.

# Answer
> 1 votes
# MathGolf, 15 (non-competing†) bytes

```
{├_nn¡¿\;+ho}▲;

```

† The program above doesn't compile due to a bug in MathGolf with (do-)while loops using blocks above 8 characters. `{...}` is supposed to be a block for when `...` contains more than 8 characters, but instead the `{` behaves as a for-each.

We can remove the `{}` and trailing `;` so the do-while works on all preceding characters, so we can verify the test cases. Unfortunately, all test cases will then output an additional trailing empty list `[]`.
Both programs also fail with an error for input `[]`.

Outputs each length to STDOUT, without leading length and with trailing 0.

`├_nn¡¿\;+ho▲`: Try it online.

**Explanation:**

```
{           }▲  # Do-while true with pop:
 ├              #  Extract and push the left item of the list
                #  (this is where the `[]` test case errors)
  _             #  Duplicate it
   n            #  If it's a list: join it with newline delimiter to a string
                #  If it's an integer: push a newline "\n" character
    n¡          #  Check that this string is NOT equal to "\n"
      ¿         #  If it's indeed not "\n" (thus it's a list)
       \        #   Swap the top two values
      ¿         #  Else (it's an integer):
        ;       #   Discard it from the stack
         +      #  If it's a list: merge the top two lists together
                #  If it's an integer: add it to each inner-most value
          h     #  Push the length (without popping the list)
           o    #  Output it with trailing newline (without popping)
             ▲  #  Once the length is 0, the do-while stops
              ; # After the do-while: discard the empty list (since MathGolf
                # implicitly outputs the entire stack at the end of a program)

```

# Answer
> 1 votes
# C (gcc), 266 bytes

```
#define S *w++=*r++
#define B b+=*r==91?1:-(*r==93)
f(r,b,w)char*r,*w;{w=++r;if(*++r==93)r++,r+=*r?*r==44:-1;else{if(*r!=44)for(b=1;b;B)S;r++;}for(;*r;)S;*w=0;}i;main(b,v,r)char**v,*r;{for(v++;*(*v+2);printf("%d ",i),f(*v))for(b=0,r=*v,i=1;*++r;B)(!b&&*r==44)&&i++;}

```

Try it online!

# Answer
> 1 votes
# Retina 0.8.2, 82 bytes

```
0
[]
+`..(],?|(((\[)|(?<-4>])|,)+)])(.*)$
$&¶[$2$5
.(.((\[)|(?<-3>])|,)*].)*.?
$#1

```

Try it online! Outputs both leading and trailing counts and takes `0` as the consistent value (since `[]` is disallowed), but link is to test suite that replaces all non-negative integers with zero and deletes spaces for convenience. Explanation:

```
0
[]

```

Replace `0`s with empty lists.

```
+`

```

Repeat until the last line is an empty list.

```
..(],?|(((\[)|(?<-4>])|,)+)])(.*)$

```

On the last line, match a list containing either an empty list as its first or only element, or otherwise the contents of the list at the first element.

```
$&¶[$2$5

```

Keep the original list to count its elements later and create a new list obtained by prepending the contents (if any) to the rest of the list.

```
.(.((\[)|(?<-3>])|,)*].)*.?
$#1

```

Count the number of elements of each list.

# Answer
> 1 votes
## Brev, 85 bytes

```
(fn(descend(x)(cons(length x)(desc(if(pair?(car x))(append(car x)(cdr x))(cdr x))))))

```

Example:

```
((fn (descend (x)
              (cons
               (length x)
               (desc
                (if (pair? (car x))
                    (append (car x) (cdr x))
                    (cdr x))))))
 '((1 2) (3 (4 5))))

```

`fn` makes a function with an argument `x`. `descend` checks if it's null, if it is, return it. Otherwise, `cons` its `length` onto a recursive call of `descend`, where the `car` of `x` has been spliced if it's a `pair?` or dropped if it's an atom. For the test example, it returns `(2 3 2 1 2 1 2 1)`

# Answer
> 1 votes
# Pyth, 9 bytes

```
#l=+|hQYt

```

Try it online!

Accepts a ragged list filled with 0s.

Excludes the length of the initial list, and includes the 0 for the final list.

# Answer
> 0 votes
# Burlesque, 32 bytes

```
saj{g_Jto'B~[{j_+}qvvIEsaj}qL[w!

```

Try it online!

```
saj      # Get initial length
{
 g_      # Pop head from list
 J       # Dup
 to'B~[  # Is Block
 {j_+}   # Prepend elements
 qvv     # Drop
 IE      # If (isBlock) else
 saj     # Length
}
qL[w!    # While non-empty

```

# Answer
> 0 votes
# APL (Dyalog Classic), 22 bytes

```
{⍴⍴⍵:∊(⍴,∇¨+⍴-⍳∘⍴)⍵⋄0}

```

Try it online!

I assume the output must be a flat array instead of allowing nested array. If nested array is acceptable then  is not needed for -1 byte

Uses the same algorithm as my other submission, but pretty much ungolfed because tacit APL is that good

```
{⍴⍴⍵:∊(⍴⍵),(∇¨⍵)+(⍴⍵)-(⍳⍴⍵)⋄0}  With trains expanded

 ⍴⍴⍵:                           If argument is array
           (∇¨⍵)                  recursive call with each element
                 +(⍴⍵)-(⍳⍴⍵)      add (length of argument - index)
                                    note that APL arrays are 1-based by default
      (⍴⍵),                       prepend length of argument
     ∊                            flatten
                           ⋄0   Else return 0

```

# Answer
> 0 votes
# Pyth (arbitrary values), 15 bytes

```
lM.u+.x[.*hN[)t

```

Test suite

Takes a ragged list of arbitrary values (even accepts floats). Includes length of original list and final 0.

##### Explanation:

```
lM.u+.x[.*hN[)t   | Full code
lM.u+.x[.*hN[)tNQ | with implicit variables
------------------+----------------------------------------------------------------------------------------------------------------
  .u            Q | Collect N, starting with the input, with each succussive N defined by the following until a result is repeated:
    +         tN  |  Prepend to the tail of N:
       [.*hN      |   N if N is a list
     .x     [)    |   or the empty list if N is not a list
lM                | Convert each element to its length

```

---
Tags: code-golf, ragged-list
---