title: Pong in the shortest code

text:
# Question
Title: Pong in the shortest code
The challenge is simple. Give the shortest code possible to reproduce the classic 2-player game of pong http://en.wikipedia.org/wiki/Pong . The level of graphics and functionality should be as close as possible to this javascript demonstration http://codeincomplete.com/posts/2011/5/14/javascript\_pong/demo.html (but without the extra options you can click on on the left or the frame, fps etc. information in the bottom right).

As always the code must be written in a free language (in both senses) and should be runnable on linux. Any libraries used must also be free, easily available and not be written for the purposes of this competition (and also not already contain a working version of Pong!).

# Answer
## Javascript, 883 (+ 70 HTML)

```
c=document.getElementById('c').getContext('2d')
c.fillStyle="#FFF"
c.font="60px monospace"
w=s=1
p=q=a=b=0
m=n=190
x=300;y=235
u=-5;v=3
setInterval(function(){if(w&&!s)return;s=0
c.clearRect(0,0,640,480)
for(i=5;i<480;i+=20)c.fillRect(318,i,4,10)
m+=p;n+=q
m=m<0?0:m;m=m>380?380:m
n=n<0?0:n;n=n>380?380:n
x+=u;y+=v
if(y<=0){y=0;v=-v}
if(y>=470){y=470;v=-v}
if(x<=40&&x>=20&&y<m+110&&y>m-10){u=-u+0.2;v+=(y-m-45)/20}
if(x<=610&&x>=590&&y<n+110&&y>n-10){u=-u-0.2;v+=(y-n-45)/20}
if(x<-10){b++;x=360;y=235;u=5;w=1}
if(x>640){a++;x=280;y=235;u=-5;w=1}
c.fillText(a+" "+b,266,60)
c.fillRect(20,m,20,100)
c.fillRect(600,n,20,100)
c.fillRect(x,y,10,10)},30)
document.onkeydown=function(e){k=(e||window.event).keyCode;w=w?0:k=='27'?1:0;p=k=='65'?5:k=='81'?-5:p;q=k=='40'?5:k=='38'?-5:q;}
document.onkeyup=function(e){k=(e||window.event).keyCode;p=k=='65'||k=='81'?0:p;q=k=='38'||k=='40'?0:q}

/* Variable index:
a -> left player score
b -> right player score
c -> context
e -> event
i -> counter for dashed line
k -> keycode
m -> left paddle y
n -> right paddle y
p -> left paddle y velocity
q -> right paddle y velocity
s -> is start of game
u -> ball x velocity
v -> ball y velocity
w -> game is waiting (paused)
x -> ball x
y -> ball y
*/

```

The script can be placed at the end of `<body>` or called `onLoad`. It needs the following canvas element:

```
<canvas id="c"width="640"height="480"style="background:#000"></canvas>

```

Player 1 uses the `q` and `a` keys, and player 2 uses the `p` and `l` keys. Press the `esc` key to pause and any key to start/continue.

*You can play it in your browser **here***.

I wasn't sure of the physics to use, so I started off with a simple reflection method and then added some variety and experimented with it a bit. The ball's velocity in the y direction is affected by where on the paddle you hit the ball, so you have some control over where the ball goes. The ball's velocity in the x direction slowly increases with each hit in the rally.

I suspect that it will be beaten quite easily by solutions using libraries, but I had fun making it in plain javascript.
> 24 votes

# Answer
## sed, 35

Raising the bar a bit with a postage-stamp sed meditation.

```
s/> / >/
s/ </< /
s/0</0>/
s/>1/<1/

```

The meditation is enjoyed on stdin/stdout on two computers, not necessarily connected by a network. The meditation begins in the state

```
0         <       1

```

with guru zero on the left and one on the right. The angle bracket moves left and right, and if a guru maneuvers their number to contact the cursor as it comes to their side, their score is increased by one, and they become elated with joy.

The meditation is initiated by typing the above state into `sed -f medi.sed`, and the computer responds with the next state. The dutiful guru types that state into the meditation, reading aloud the next key they will press, with both gurus pressing the holy key to `enter` the future at the same time. The dutiful computer replies with the next state. This, in turn, is read aloud while typed in unison as with the last. Continue advancing into the future until infinite bliss is achieved.

Gurus desiring a challenge may play 'turbo' mode, wherein the gurus attempt to collaboratively predict the computer's next state, and typing it into the prompt instead of the current state. Gurus will have the wisdom to verify agreement between their predictions before entering the future.
> 45 votes

# Answer
## Python 2 (with pygame) 650 bytes

**Features**

* **1 and 2 player modes** \- When the game begins, press `1` for 1 player, or `2` for 2 players. The game will not begin until one of these keys is pressed.
* **Increasing ball speed** \- Each volley, the ball speed is increased so that after 10 volleys it has increased by approximately 50%, after 20 it will be 50% faster than that, etc.
* **Variable ball deflection** \- Ball deflection is based on two factors: what portion of the paddle it strikes, and whether or not the paddle is moving upon impact. If the ball strikes the paddle near one of the ends, it will be deflected more strongly than if it strikes near the middle (almost as if it were a curved surface). Additionally, if the paddle is in motion, the motion of the paddle is added to the deflection. In order to obtain the strongest deflection, the ball must strike near the end of the paddle, and the paddle must be in motion towards that same end. This is very similar to the original Pong for Atari 2600.
* **Pause** \- The game may be paused at any time by pressing the `Space` bar. Play will resume upon pressing the space bar a second time.
* **Controls** \- As with the example, player 1 moves with the `Q` and `A` keys, and player 2 moves with `P` and `L`.

```
from pygame import*
init();d=display;s=d.set_mode((640,480))
g=p=16;j=q=80;x=y=200;o=t=h=v=1;z=m=n=0;w=[255]*3
while s.fill(time.wait(3)):
 event.get();k=key.get_pressed();t^=o*k[32];o=1-k[32];z=z or-k[49]-k[50]*2;e=k[113]-k[97];f=[k[112]-k[108],(h>0)*cmp(y,q-32)][z];a=p<g;b=q-[y,x][a]
 if p%608<g:m,n,p,h,v=[m+1-a,m,n+a,n,g+a*592,p,1-a*2,h/-.96,1,b/32.+~[f,e][a]][-g<b<j::2]
 for r in[(0,x,g,j),(624,y,g,j),(p,q,g,g)]+[(316,i*31,8,15)for i in range(g)]:draw.rect(s,w,r)
 if z*t:v*=(0<q<464)*2-1;x-=(0<x-e<400)*e/.6;y-=(0<y-f<400)*f/.6;p+=h;q+=v
 c=font.SysFont('monospace',j,1).render('%3d %%-3d'%m%n,1,w);s.blit(c,(320-c.get_width()/2,0));d.flip()

```

`cmp` is no longer defined in Python 3. The code above can be made Python 3 compatitble by prepending the following:

```
def cmp(a, b):
  return (a>b)-(a<b)

```

Sample screen capture:

*Note: the font used for the score may vary from system to system.*
> 17 votes

# Answer
# HTML & JavaScript (take 2) - 525

Since the OP didn't seem to care much about the "as close as possible" part, here's an alternative solution that I mercilessly simplified, stripped and golfed. Q/A and P/L to play, but every other key also has an effect. Again, the code is fully self-contained and I tested it in Chromium 25 on Linux. I can golf it even further if you can accept small bugs or greater degradation of graphics quality/gameplay.

```
<canvas id=c><script>C=c.getContext('2d');f=C.fillRect.bind(C)
S=[-1,I=J=0];A=B=210;X=Y=1
function g(n){++S[n];N=Math.random(M=n*613+9)*471}D=document
D.onkeydown=D.onkeyup=function(e){d=!!e.type[5];k=e.keyCode
k&1?I=k&16?d:-d:J=k&4?-d:d}
g(0);setInterval(function(){A-=A<I|A>420+I?0:I
B-=B<J|B>420+J?0:J
M+=X;N+=Y
N<0|N>471?Y=-Y:0
M==622&N>B&N<B+51|M==9&N>A&N<A+51?X=-X:M>630?g(0):M||g(1)
f(0,0,c.width=640,c.height=480)
C.fillStyle='tan';C.font='4em x';C.fillText(S,280,60)
f(0,A,9,60);f(631,B,9,60);f(M,N,9,9)},6)</script>

```

Thanks Shmiddty
> 7 votes

# Answer
# Processing, 487 characters

```
int a=320,b=240,c=2,d=2,e=0,f=0,g=0,h=0,i=15,j=80,k=640,
l=160,m;void setup(){size(k,b*2);}void draw(){background
(0);if(keyPressed){if(key=='q'&&g>0)g-=i;if(key=='a'&&g<
j*5)g+=i;if(key=='o'&&h>0)h-=i;if(key=='l'&&h<j*5)h+=i;}
rect(0,g,i,j);for(m=0;m<k;m+=30)rect(312,m,i,i);rect(a,b
,i,i);rect(625,h,i,j);a+=c;b+=d;c*=a<i&&(b>g&&b+i<g+j)||
a>610&&(b>h&&b+i<h+j)?-1:1;d*=b<0||b>=465?-1:1;if(a<0){f
++;a=0;b=240;c=2;}if(a>k){e++;a=625;b=240;c=-2;}textSize
(j);text(e,l,j);text(f,3*l,j);}

```

Sample screenshot:

This code was made with shortness in mind, so it is pretty buggy (the ball sometimes goes through the paddle, or wraps around it). Controls are Q/A for Player 1 and O/L for Player 2.
> 5 votes

# Answer
# TI-Basic, <sup>~~328~~</sup> 326 bytes

```
AxesOff:ZInteger:GridOn
99→Xscl:2→Yscl:1→U:1→V
Pt-Change(0,0
Line(Xmin,0,Xmin,9
Line(Xmax,0,Xmax,9
While 1
If 30≤abs(Y
-V→V
Pt-Change(X,Y
If X≥46:Then
If Y≥E and Y≤E+9:Then
-U→U
Else
IS>(A,9
X-90→X
End
End
If X≤-46:Then
If Y≥D and Y≤D+5:Then
-U→U
Else
IS>(B,9
X+90→X
End
End
If 9<max(A,B
Stop
X+U→X:Y+V→Y
Pt-Change(X,Y
Text(1,43,A,":",B
getkey→G
If G=21
1→I
If G=41
-1→I
If G=25
1→J
If G=34
-1→J
I(G≠31→I
J(G≠26→J
D+I→D:E+J→E
For(θ,-1,9,10
Pt-Change(Xmin-not(I),D+θ-I/2
Pt-Change(Xmax+not(J),E+θ-J/2
End
End

```

This program is very basic (constant speed and angles) but since there's is no precise specifications, the strict minimum will do

Since a long press is not detectable (or 2 keys pressed at the same time), an extra key is used to stop the movement of the racket

Here is the result at ~5x speed:
> 5 votes

# Answer
# HTML & JavaScript - 1663

Against my better judgment, I took the crazy approach of golfing the actual code from the demo. I removed some features and interface elements, but generally it works exactly the same - 0, 1 or 2 to choose the number of human players, Q/A and P/L to move.

Unless I made some mistakes, gameplay should be identical, pixel for pixel and millisecond for millisecond, to the original at 640\*480 (hint: resizing the browser window changes the game size in the demo). It just doesn't give instructions, doesn't announce the winner and doesn't handle esc.

The code is fully self-contained and I tested it in Chromium 25 on Linux. Firefox doesn't like it very much.

```
<body bgcolor=0><canvas id=c height=480><script>R=Math.random
C=c.getContext('2d');f=C.fillRect.bind(C)
S=[l=G=I=J=K=L=0,0];r=17;u=463;o=24;q=12;z=10;s=640;v=36
function T(z,t,u,v){P=0;if(e=v*E-u*F){a=(u*t-v*z)/e;b=(E*t-F*z)/e
a<0|a>1|b<0|b>1?0:P={x:M+a*E,y:N+a*F,d:u,s:0,X:X,Y:Y}}}function
i(p,q,h){T(p-22*(E<0),q,0,h)
P?0:T(p,q-h*(F<0),22,0)}function
U(p){if(p.a)if(M<p.x&X<0|M>p.x+q&X>0)p.u=0
else{P=p.P;if(P&&P.X*X>0&P.Y*Y>0&P.s<p.l/z)P.s+=t
else{E=X*z;F=Y*z;i(M-p.x+5,s*q,s*o)
if(p.P=P){y=P.y;while(y<r|y>u)y=y<r?34-y:y>u?u+u-y:y
P.y=y+R(e=(p.l+2)*(X<0?M-p.x-q:p.x-M)/64)*2*e-e}}P?p.u=P.y<p.y+25?1:P.y>p.y+35?-1:0:0}y=p.y-p.u*t*198
p.y=y<q?q:y>408?408:y}function
W(n,x){a=9.6;b=[~8,3,62,31,75,93,~2,7,-1,u][n]
b&4&&f(x,o,v,a);b&64&&f(x,o,a,o)
b&2&&f(x+v,o,-a,o);b&8&&f(x,43.2,v,a)
b&32&&f(x,48,a,o);b&1&&f(x+v,48,-a,o)
b&16&&f(x,72,v,-a)}A={u:0,x:0,y:210};B={u:0,x:628,y:210}
function g(n){if(++S[n]>8)G=A.a=B.a=0
else{N=R(M=n?635:5)*446+r;Y=157.5;X=n?-Y:Y
A.l=z+S[0]-S[1];B.l=20-A.l}}D=document
D.onkeydown=D.onkeyup=function(e){d=!!e.type[5]
k=e.keyCode-45;if(k>2&k<6&d&!G){G=S=[-1,0];A.a=k<4;B.a=k<5
g(0)}k^31?k^35?k^20?k^v?0:I=d:J=d:K=d:L=d
A.a?0:A.u=I-J;B.a?0:B.u=K-L}
setInterval(function(){t=new Date()/1000-l;l+=t;U(A);U(B)
if(G){E=t*X+4*t*t;F=t*Y+4*t*t
x=M+E;y=N+F;m=X+t*(X>0?8:-8);n=Y+t*(Y>0?8:-8)
if(n>0&y>u){y=u;n=-n}if(n<0&y<r){y=r;n=-n}p=m<0?A:B
i(M-p.x+5,N-p.y+5,70)
if(P){if(P.d){y=P.y;n=-n}else{x=P.x;m=-m}n*=n*p.u<0?.5:p.u?1.5:1}M=x;N=y
X=m;Y=n;M>645?g(0):M<-5&&g(1)}c.width=s;C.fillStyle='#fff'
f(0,0,s,q);f(0,468,s,q);for(j=o;j--;)f(314,6+o*j,q,q)
W(S[0],266.5);W(S[1],338.5)
f(0,A.y,q,60);f(s,B.y,-q,60);G&&f(M-5,N-5,z,z)},50/3)</script>

```

Some credits to Shmiddty for improvements
> 4 votes

# Answer
# C# - 1283 characters

This can be golfed quite a bit more but here it is.

```
using System;using System.Drawing;using System.Runtime.InteropServices;using System.Windows.Forms;using r=System.Drawing.RectangleF;namespace f{public partial class f:Form{public f(){InitializeComponent();}private void f_Load(object sender,EventArgs e){var t=this;var s=new r(0,0,300,300);var q=new r(0,0,15,50);var o=new r(0,0,15,50);var x=new PointF(150,150);var v=.06F;var h=v;var b=new r(x.X,x.Y,15,15);var p1=0;var p2=0;var p=new PictureBox{Size=t.Size,Location=new Point(0,0)};t.Controls.Add(p);p.Paint+=(wh,n)=>{var g=n.Graphics;Action<Brush,r>f=g.FillRectangle;var k=new SolidBrush(Color.Black);var w=new SolidBrush(Color.White);var d=new byte[256];GetKeyboardState(d);var l=q.Location;var _1=.1F;q.Location=new PointF(0,d[90]>1?l.Y+_1:d[81]>1?l.Y-_1:l.Y);l=o.Location;o.Location=new PointF(269,d[77]>1?l.Y+_1:d[79]>1?l.Y-_1:l.Y);f(k,s);f(w,q);f(w,o);Func<r,bool>i=b.IntersectsWith;h=i(q)||i(o)?-h:h;v=b.Top<1||b.Bottom>t.Height-30?-v:v;b.Offset(h,v);if(b.Left<0){p2++;b.Location=x;}if(b.Right>290){p1++;b.Location=x;}f(w,b);for(int j=0;j<19;)f(w,new r(140,(j+(j++%2))*15,10,10));var a=new Font("Arial",20);g.DrawString(p1.ToString(),a,w,100,12);g.DrawString(p2.ToString(),a,w,170,12);p.Invalidate();};}[DllImport("user32.dll")]static extern bool GetKeyboardState(byte[]s);}}

```

Edit: Didn't see the requirement for a free, linux-runnable language...
> 2 votes

# Answer
# K (oK) + `iKe`, ~~393~~ 335 bytes

```
q:p:-15+h%2
d:w,h
b:-2+d%2
v:5 -1
s:t:0
tick:{b::v+0|d&b
$[$[0>*b;t+::1;w<*b;s+::1;0];b::-2+d%2;0]
v*::$[(&/(b>(0;p-5))&b<(10;p+30))|&/(b>(w-15;q-5))&b<(w;q+30);-1;1],1}
draw:{((;gray);(((0;p);(w-5;q));;30 5#1);(b;;5 5#1);((w%4;0);;~,/'+text(),$t);((-10+3*w%4;0);;~,/'+text(),$s))}
kd:{$[x=81;p-::5;x=65;p+::5;x=80;q-::5;x=76;q+::5;0]}

```

Try it online!

My first K answer!

Was really fun to do in K. Kinda sad that the question spec isn't too specific about the implementation.

This answer has points based scoring, involves two players and no AI.
> 2 votes

# Answer
# Tcl/Tk, 932 bytes

***Must be run in the interactive shell***

```
gri [can .c -w 1024 -he 768 -bg #000]
proc A {} {set ::v [expr (int(rand()*36)+1)*20]}
proc R {C t\ X} {.c cr r $C -f #aaa -t $t}
proc I {} {incr ::v 20}
time {R "504 [I] 520 [I]"} 18
R "0 0 1024 20"
R "0 748 1024 768"
R "0 340 20 440" b
R "1004 340 1024 440" B
R "40 [A] 60 [I]" P
lmap n 4\ 5 T F\ S {.c cr t ${n}62 60 -ta $T -te 0 -fi #aaa -font {"" 56}}
proc C t\ n {lindex [.c coo $t] $n}
lmap {a b c d e} {q b 1 >20 -20 a b 3 <740 20 p B 1 >20 -20 l B 3 <740 20} {bind . $a "if \[C $b $c]$d {.c move $b 0 $e}"}
lassign {0 0 20 20} F S y x
proc M {} {lmap {_ a b c d e f} {0 <40 b 20 S 960 980 2 >984 B -20 F 80 100} {if [C P $_]$a {if [C P 1]>=[C $b 1]&&[C P 3]<=[C $b 3] {bell
set ::x $c} {.c itemco $d -te [incr ::$d]
if \$::$d>8 {tk_messageBox -message WINNER!
lmap T F\ S {.c itemco $T -te [set ::$T 0]}}
.c coo P $e [A] $f [I]}}}
.c move P $::x [set ::y [expr [C P 1]<40?20:[C P 3]>727?-20:$::y]]
after 99 M}
M
focus -f .

```

***Note:***

```
 #There is an Enter at the end

```

Just a very minimal version of Pong, where the ball only runs in diagonal angles and always has same velocity.
> 1 votes

---
Tags: code-golf, graphical-output, game
---


title: Generate Lucky Numbers

text:
# Question
Title: Generate Lucky Numbers
**Story:**

Lucy asked George what his Lucky Number was. After some contemplation, George replied that he had several Lucky Numbers. After some brief confusion, Lucy asked George what his first `n` Lucky Numbers are. George then asked you, his buddy, to write him a program to do the work for him.

**The Challenge:**

You will write a program/function that will receive from standard input/function argument a string or integer `n`. The program/function will then return/output the first `n` Lucky Numbers. Lucky numbers are defined via a sieve as follows.

Start with the positive integers:

```
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, ...

```

Now remove every second number:

```
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, ...

```

The second remaining number is **3**, so remove every third number:

```
1, 3, 7, 9, 13, 15, 19, 21, 25, ...

```

Now the next remaining number is **7**, so remove every seventh number:

```
1, 3, 7, 9, 13, 15, 21, 25, ...

```

Next, remove every ninth number and so on. The resulting sequence are the lucky numbers.

**Winning:**

As usual for codegolf, fewest bytes wins.

As usual, submissions using standard loopholes are disqualified.

# Answer
# Python 2, 79

```
n=input()
L=range(1,2**n)
for r in L:r+=r<2;map(L.remove,L[r-1::r])
print L[:n]

```

The magic of iterating over a list as the loop modifies it!

The list `L` starts with all the integers `1` to a sufficiently high value. The code iterates over each element `r` of `L`, taking the sublist of every `r`'th element, and removing each of those values. As a result, the removed values aren't iterated over. At the end, print the first `n` elements.

The expression `map(A.remove,B)` is a trick I've been waiting a long time to use. It calls `A.remove` for each element of `B`, which causes all the elements of `B` to removed from `A`. Effectively, it takes the list difference, though it requires `B` to be a sublist of `A`. It requires Python 2, since Python 3 wouldn't actually evaluate the map.

The first loop needs to be special-cased to convert `r` from `1` to `2`, as `r+=r<2`.

The sufficiently high upper bound of `2**n` makes the program very slow for large values of `n`. Using `n*n+1` suffices, but costs a character. Note that `n*n` doesn't work for `n=1`.
> 16 votes

# Answer
# Haskell, ~~71~~ 69 bytes

```
s(n:k)p=n:s[m|(i,m)<-zip[p..]k,i`mod`n>0](p+1)
f n=take n$1:s[3,5..]3

```

Defines a function `f`. The expression `1:s[3,5..]3` evaluates to the infinite list of lucky numbers, and `f` simply takes the first `n` of them by `take n`.

```
f 20
[1,3,7,9,13,15,21,25,31,33,37,43,49,51,63,67,69,73,75,79]

```

I could shave off 5 bytes from the sieve using a parallel list comprehension

```
s(n:k)p=n:s[m|m<-k|i<-[p..],i`mod`n>0](p+1)

```

but that would require passing the humongous compiler flag `-XParallelListComp` to GHC to enable the extension.

### Explanation of the sieve

```
s(n:k)p=               -- Sieving a list with head n and tail k with accumulator p is
 n:                    -- the head n, followed by
  s[m|                 -- the result of sieving the list of numbers m
    (i,m)<-zip[p..]k,  -- where (i,m) is drawn from [(p,k_0),(p+1,k_1),(p+2,k_2),..] and
    i`mod`n>0]         -- i does not divide n,
   (p+1)               -- using p+1 as the accumulator

```

The basic idea is that `s(n:k)p` produces the `(p-1)`th lucky number `n`, drops every `n`th number from the infinite tail `k` (offset by `p` to account for the numbers produced earlier), and recurses to that list with accumulator `(p+1)`. In `f`, we initialize the process with the odd numbers starting from `3`, and tack `1` to the front, obtaining exactly the lucky numbers.
> 14 votes

# Answer
# Python 2, ~~71 69~~ 67

At first, I thought this would be a great challenge for Python's array slicing. However, I encountered a stumbling block when I discovered that slices with a step other than 1 can only have another slice of identical length assigned to them. But after googling "python remove slice", my faith was restored: I found a funky `del` statement that does the trick perfectly.

```
n=input()
l=range(n*n+9)
for v in l:del l[v&~1::v or 2]
print l[:n]

```

**Old version**

```
n=input()
l=range(1,n*n+9)
for v in l:del l[v-1%v::v+1/v]
print l[:n]

```

-2 bytes thanks to Sp3000.
> 13 votes

# Answer
# CJam - 25

```
Lri{1$W%{1$\(1e>/+}/)+}/p

```

Try it online

**Explanation:**

This implementation doesn't remove numbers successively from an array, but calculates each number based on how many would have been removed before it.
For each index i (from 0 to n-1) and each previous lucky number l, in reverse order, we increment i by i/(l-1), except for l=1 we use 1 instead of 0, and also add 1 at the end.
E.g. for i=4 we have the first 4 numbers, \[1 3 7 9\], and calculate:
4 + 4/(9-1) = 4
4 + 4/(7-1) = 4
4 + 4/(3-1) = 6
6 + 6/1 = 12
12 + 1 = 13

```
L              empty array - the first 0 lucky numbers :)
ri             read and convert to integer (n)
{…}/           for each number (i) from 0 to n-1
    1$         copy the previous array
    W%         reverse the order
    {…}/       for each array element (l)
        1$     copy i
        \(     swap with l and decrement l
        1e>    use 1 if l=1
        /+     divide and add to i
    )+         increment and add the new lucky number to the array
p              pretty print

```
> 13 votes

# Answer
# \>\<\>, ~~121~~ ~~114~~ 111 bytes

```
i2+:&:*1\
:})?v:2+>l{
nao2\r~1
)?vv>1+:&:&=?;:[{::nao}]$}l1-[01+}:l3-$%$l1-@@-{$[{~l1
3.\ ff+
!?:<]-1v
~]{43. >

```

I have only a few words to say...

... "Argh my brain hurts."

---

## Explanation

\>\<\> is a 2D esoteric programming language and is *definitely* not suited for this task, due to its lack of arrays. In fact, the only data type in \>\<\> is strange mix of int/float/char, and everything happens on a stack of stacks.

Here's the rundown:

```
Line 1:            i2+:&:*1\

i2+:&              Read a char as input (n) and add 2, copying n+2 into the register
:*                 Duplicate and multiply, giving (n+2)^2 on the stack
1\                 Push 1 and go to the next line

Line 2:            >l{:})?v:2+

l{:})?v            Go to the next line if the stack's length is greater than (n+2)^2
:2+                Otherwise duplicate the top of the stack and add 2 to it

Line 3:            \r~1nao2

r~                 Reverse the stack and pop; stack contains the first (n+2)^2 odd integers
1nao               Print 1 (special case)
2\                 Push 2 (let's call this "i" for "iterations") and go to the next line

Line 4:            >1+:&:&=?;:[{::nao}]$}l1-[01+}:l3-$%$l1-@@-{$[{~l1)?vv

1+                 Increment i
:&:&=?;            If i is equal to n+2 (+2 because we started at 2), halt
:[{::nao}]$}       Print the i-th element down (the next lucky number) and also
                   copy it to the top of the stack, while moving i to the bottom
l1-[               Move everything but i to a new stack
0                  Push 0 (let's call this "r" for recursion depth)

Sieve loop:

1+                 Increment r
}:l3-$%$l1-@@-{$[  Move everything up to the last element to be sieved out to a new stack
{~                 Remove said last element
1)?vv              If the length is 1, go to line 6 (sieving complete)
                   Otherwise go to line 5, which repeats this sieve loop by teleporting

Line 6:            :?!v1-]

:?!v1-]            Keep unrolling and decrementing r until r is 0

Line 7:            >~]{43.

~]                 Pop r and unroll once more (to the stack where i waits)
43.                Loop, performing everything from line 4 all over again

```

Here's a mock example which demonstrates roughly how the sieving works (here `k` is the lucky number which we sieve with):

```
[[15 13 11 9 7 5 3 1 k=3 r=0]]     -- move -->
[[15 13] [11 9 7 5 3 1 k=3 r=1]]   -- pop  -->
[[15 13] [9 7 5 3 1 k=3 r=1]]      -- move -->
[[15 13] [9 7] [5 3 1 k=3 r=2]]    -- pop  -->
[[15 13] [9 7] [3 1 k=3 r=2]]      -- move -->
[[15 13] [9 7] [3 1] [k=3 r=3]]    -- pop  -->
[[15 13] [9 7] [3 1] [r=3]]        (now we unroll)

```
> 11 votes

# Answer
# Pyth: ~~23~~ 22 bytes

```
<u-G%@GhH+0GQ%2r1^hQ2Q

```

Try it online: Pyth Compiler/Executor

## Explanation:

```
<u-G%@GhH+0GQ%2r1^hQ2Q    Q = input()
             %2r1^hQ2     create the list [1, 2, ..., (Q+1)^2-1][::2]
 u          Q%2r1^hQ2     G = [1, 2, ..., (Q+1)^2-1][::2]
                           modify G for each H in [0, 1, 2, ..., Q]:
  -G%:GhH+0G                  G = G - ([0] + G)[::G[H+1]]
                               (minus is remove in Pyth)
<                    Q    print the first Q elements of the resulting list

```

The reduce actually calculates more than `Q` lucky numbers (the remove command is called Q+1 times, Q-1 should be enough).
> 6 votes

# Answer
## R, 58 bytes

```
n=scan();s=r=1:n^2;for(j in 1:n)r=r[-max(2,r[j])*s];r[1:n]

```

With line breaks:

```
n=scan()              #user input
s=r=1:n^2             #declare r and s simultaneously, both large enough to sieve
for(j in 1:n)
  r=r[-max(2,r[j])*s] #iteratively remove elements by position in vector
r[1:n]                #print

```

### Previous version, 62 bytes

```
function(n){
  s=r=1:n^2             #declare r and s simultaneously, both large enough to sieve
  for(j in 1:n)
    r=r[-max(2,r[j])*s] #iteratively remove elements by position in vector
  r[1:n]                #print
}

```

### Previous version, 78 bytes

```
n=as.numeric(readline())   #ask for user input and convert it to numeric
r=1:n^2                    #create a large enough vector to sieve
for(j in 1:n){             #loop
  r=r[-max(2,r[j])*1:n^2]  #iteratively remove elements by position in vector
}
r[1:n]                     #print

```
> 6 votes

# Answer
# Python 2, ~~105~~ 101 bytes

```
n=input()
L=range(-1,n*n+9,2)
i=2
while L[i:]:L=sorted(set(L)-set(L[L[i]::L[i]]));i+=1
print L[1:n+1]

```

Just a straightforward implementation.

# Pyth, ~~39~~ ~~36~~ ~~35~~ 32 bytes

```
J%2r1h^Q2VJI>JhN=J-J%@JhN+2J;<JQ

```

Similar to the approach above, but things are 0-indexed rather than 1-indexed. Try it online.

Thanks to @Jakube for pointing out a byte saving.
> 4 votes

# Answer
# CJam, ~~32~~ 30 bytes

```
3ri:N#,N{0\__I1e>)=%-+}fI(;N<p

```

Takes input from STDIN.

**Code explanation**:

```
3ri:N#,                          "Read the input in N and get first 3^N whole numbers";
       N{0\__I1e>)=%-+}fI        "Run the code block N times, storing index in I";
         0\__                    "Put 0 before the array and take 2 copies";
             I1e>)=              "Take min(2, I + 1) th index from the copy";
                   %             "Take every array[ min (2, I + 1)] element from the array";
                    -+           "Remove it from the list and prepend 0 to the list";
                         (;N<p   "Print number index 1 to N";

```

Try it online here
> 4 votes

# Answer
# Perl, 86 81 78

86:

```
@a=(1..($k=<>)**2);for$n(@a){$i=1;@a=map{$i++%($n+($n<2))?$_:()}@a;$k-=$k&&print"$n "}

```

UPDATE: obviously, `grep{...}` is better than `map{...?$_:()}` 81:

```
@a=(1..($k=<>)**2);for$n(@a){$i=1;@a=grep{$i++%($n+($n<2))}@a;$k-=$k&&print"$n "}

```

UPDATE: OK, actually a one-liner now. I can stop. (?) 78:

```
@a=(1..($k=<>)**2);for$n(@a){$k-=$i=$k&&print"$n ";@a=grep{$i++%($n+=$n<2)}@a}

```
> 4 votes

# Answer
# Mathematica, 80 bytes

```
(For[l=Range[#^2];i=1,(m=l[[i++]]~Max~2)<=Length@l,l=l~Drop~{m,-1,m}];l[[;;#]])&

```

Straight-forward implementation of the definition. As some other answers, starts with a range from `1` to `n<sup>2</sup>` and then keeps filtering.
> 3 votes

# Answer
# JavaScript (ES6) 96 ~~99~~

**Edit** Counting down in first loop - thanks @DocMax

```
F=n=>(i=>{
  for(o=[1];--i;)o[i]=i-~i;
  for(;++i<n;)o=o.filter((x,j)=>++j%o[i]);
})(n*n)||o.slice(0,n)

```

**Ungolfed**

```
F=n=>{
  for (i = n*n, o = [1]; --i;)
    o[i] = i+i+1;
  for (; ++i < n; )
    o = o.filter((x, j) => (j+1) % o[i])
  return o.slice(0,n)
}

```

**Test** In Firefox / FireBug console

```
F(57)

```

*Output*

```
[1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 49, 51, 63, 67, 69, 73, 75, 79, 87, 93, 99, 105, 111, 115, 127, 129, 133, 135, 141, 151, 159, 163, 169, 171, 189, 193, 195, 201, 205, 211, 219, 223, 231, 235, 237, 241, 259, 261, 267, 273, 283, 285, 289, 297, 303]

```
> 3 votes

# Answer
# J, ~~60~~ 52 bytes

```
   ({.}.@((>:@{.,]#~0<({~{.)|i.@#)@]^:[2,1+2*i.@*:@>:)) 8
1 3 7 9 13 15 21 25

```

Explanation (from right to left):

```
2,1+2*i.@*:@>:  generates the list 2 1 3 5 7 9... with (n+1)^2 odd numbers
^:[             repeats n times the following
@]                using the list
0<({~{.)|i.@#     is the remainder of the indexes of the lists elements with the first element positive (i.e. index divisible by first element)
]#~               keep those elements from the list
>:@{.,            concatenate a first element with the value of the current one +1
}.@             drop first element
{.              take the first n element

```

`2,1+2*i.@*:@>:` seems way too long but I can only shorten it by 1 byte swapping `*:` with `!` making the list grow exponentially.
> 3 votes

# Answer
# Octave, ~~139~~ ~~83~~ 72

```
function r=l(n)r=1:2:n^2;for(i=2:n)h=r(i);r(h:h:end)=[];end;r=r(1:n);end

```

Ungolfed:

```
function r=l(n)
  r=1:2:n^2;
  for(i=2:n)
    h=r(i);
    r(h:h:end)=[];
  end
r=r(1:n);  # reduce it to only N lucky numbers
end

```
> 3 votes

# Answer
# Matlab, 104 bytes

```
function x=f(n)
k=1;N=n;x=0;while nnz(x)<n
x=1:N;m=1;while m-nnz(x)
m=x(x>m);x(m:m:end)=[];end
N=N+2;end

```

With thanks to @flawr for very appropriate comments and suggestions.

Example from Matlab command prompt:

```
>> f(40)
ans =
  Columns 1 through 22
     1     3     7     9    13    15    21    25    31    33    37    43    49    51    63    67    69    73    75    79    87    93
  Columns 23 through 40
    99   105   111   115   127   129   133   135   141   151   159   163   169   171   189   193   195   201

```
> 2 votes

# Answer
# Julia, 66 bytes

```
x->(l=[1:x^2;];[deleteat!(l,(i+=i<2):i:length(l)) for i=l];l[1:x])

```

Try it online!
> 2 votes

# Answer
# Bash+coreutils, 136

I'd hoped to golf this down more, but oh well. Not every day that you pipe into a recursive function in a shell script:

```
f(){
mapfile -tn$2 a
(($1>$2))&&{
tr \  \\n<<<${a[@]}
sed $[${a[-1]}-$2]~${a[-1]}d
}|f $1 $[$2+1]||echo ${a[@]}
}
yes|sed -n 1~2=|f $1 2

```

### Output:

```
$ ./lucky.sh 23
1 3 7 9 13 15 21 25 31 33 37 43 49 51 63 67 69 73 75 79 87 93 99
$

```

---

# Bash+coreutils, 104

Shorter using a more straightforward implementation:

```
a=(`seq 1 2 $[3+$1**2]`)
for((;i++<$1;));{
a=($(tr \  \\n<<<${a[@]}|sed 0~${a[i]}d))
}
echo ${a[@]:0:$1}

```
> 1 votes

# Answer
# MATLAB, 62 characters

```
n=input('');o=1:2:n^2;for i=2:n;o(o(i):o(i):end)=[];end;o(1:n)

```

I misinterpreted the challenge at first - my revised version is now actually shorter.
> 1 votes

# Answer
# 05AB1E, ~~17~~ 16 bytes

```
∞IFD®LKн©ô€¨˜}I£

```

Try it online.

**Explanation:**

```
∞             # Push an infinite positive list: [1,2,3,...]
 IF           # Loop the input amount of times:
   D          #  Duplicate the infinite list
    ®L        #  Push a list in the range [1,`®`]
              #  (`®` is -1 by default, so the list is [1,0,-1] the first iteration)
      K       #  Remove all those values from the duplicated list
       н      #  Pop the list and leave the first (smallest) value
              #  (this is basically the smallest value above `®`)
        ©     #  Store it as new `®` (without popping)
         ô    #  Split the infinite list into parts of size `®`
          €¨  #  Remove the last item of each inner list
            ˜ #  Flatten it back to a single list
  }I£         # After the loop: only leave the first input amount of values
              # (after which the list is output implicitly as result)

```
> 1 votes

# Answer
# Go, 326

```
package main
import"fmt"
func s(k, p int,in chan int)chan int{
    o := make(chan int)
    go func(){
        for p>0{
            o<-<-in;p--
        }
        for{
            <-in
            for i:=1;i<k;i++{o<-<-in}
        }
    }()
    return o
}
func main(){
    n := 20
    fmt.Print(1)
    c := make(chan int)
    go func(c chan int){
        for i:=3;;i+=2{c<-i}
    }(c)
    for i:=1;i<n;i++{
        v := <-c
        fmt.Print(" ", v)
        c = s(v, v-i-2, c)
    }
}

```

Straight forward implementation using goroutine and pipes to make sieves.
> 0 votes

# Answer
## Racket 196 bytes

Produces lucky numbers upto n:

```
(λ(n)(let loop((l(filter odd?(range 1 n)))(i 1))(define x(list-ref l i))(set! l(for/list((j(length l))
#:unless(= 0(modulo(add1 j)x)))(list-ref l j)))(if(>= i(sub1(length l)))l(loop l(add1 i)))))

```

Ungolfed version:

```
(define f
 (λ(n)
    (let loop ((l (filter odd? (range 1 n))) (i 1))
      (define x (list-ref l i))
      (set! l (for/list ((j (length l)) #:unless (= 0 (modulo (add1 j) x)))
                (list-ref l j)))
      (if (>= i (sub1 (length l)))
          l
          (loop l (add1 i)))))
  )

```

Testing:

```
(f 100)

```

Output:

```
'(1 3 7 9 13 15 21 25 31 33 37 43 49 51 63 67 69 73 75 79 87 93 99)

```
> 0 votes

---
Tags: code-golf, number, number-theory, sequence
---


# Question
Title: No of subsets of a given array such that their product is in the form of p1*p2*p3
Given an array \\$A\\$ of size \\$n\\$. You have to find the number of subsets such that their product is in the form of \\$p\_1 \times p\_2 \times p\_3 \dots\\$ where \\$p\_1, p\_2, p\_3, \dots\\$ are prime numbers. No prime number should appear more than once, i.e. the product is "squarefree".

Example: Lets pick an array \\$A\\$ of size \\$5\\$. \\$A\[5\] = \\{2, 3, 15, 55, 21\\}\\$ The subsets in our answers should be \\$\\{2,3\\}, \\{2, 15\\}, \\{2, 55\\}, \\{2, 21\\}, \\{2, 3, 55\\}, \\{2, 55, 21\\}, \\{3, 55\\}, \\{55, 21\\}\\$. Lets take \\$\\{2, 3, 55\\}\\$ The product will be \\$2 \times 3 \times 55 = 2 \times 3 \times 5 \times 11\\$. Thus all prime numbers with power of 1. We can't take for example \\$\\{3, 15\\}\\$ because \\$3 \times 15 = 3^2 \times 5\\$. Condition not satisfied. Therefore our answer should be number of subsets i.e. here 8.

Constraints: \\$2\leq A\_i\<10^9\\$, \\$1\leq n\<10^5\\$

# Answer
> 1 votes
# Vyxal `s`, 16 bytes

```
ṗ'L1>;ƛΠǐ:UL$L"≈

```

Try it Online!

---
Tags: array, primes
---


title: Pigpen Cipher Encryption

text:
# Question
Title: Pigpen Cipher Encryption
# Pigpen Cipher Encryption

Your mission is simple: to write a program which receives text as input and outputs an ASCII representation of it in the Pigpen Cipher.

## Input

ASCII-only (no Unicode) characters. You must be able to handle at least 16384 characters and 256 lines.

## Output

* Replace all characters which are not new lines or in `ABCDEFGHIJKLMNOPQRSTUVWXYZ` or `abcdefghijklmnopqrstuvwxyz` with spaces.
* Case-insensitively, replace each letter with its encrypted form (see next section), inserting a trailing space on each of the three lines after each. Each encoded character is a 3\*3 block of ASCII art. Replace spaces with 3\*3 blocks of spaces.
* All the characters should be on the same three lines (call these three lines one pigpen-line), unless there is a new line, which starts a new pigpen-line. Leave a normal line blank between pigpen-lines.

## The Cipher

```
  |       | |       |
 .|       |.|       |.
--+ for J +-+ for K +-- for L

--+       +-+       +--
 .|       |.|       |.
--+ for M +-+ for N +-- for O

--+       +-+       +--
 .|       |.|       |.
  | for P | | for Q |   for R

(ABCDEFGHI are the same as JKLMNOPQR, but with the . replaced by a space)

\./
 V  for W (note the row of 3 spaces on the top)

 ^
/.\ for Z (note the 3 spaces on the bottom)

 \
 .>
 /  for X (note the leading spaces)

 /
<.
 \  for Y (note extra trailing spaces)

(STUV are like WXYZ, but with the . replaced by a space)

```

## Example

The input "hEllo,wORLd" should produce:

```
+-+ +-+ |   |   +--         +-- +-- |   --+
| | | | |.  |.  |.      \./ |.  |.  |.    |
| | +-+ +-- +-- +--      V  +-- |   +-- --+

```

The base64 encoding of the above, with a trailing new line, is below. The md5sum is `6f8ff1fed0cca4dd0492f9728ea02e7b`.

```
Ky0rICstKyB8ICAgfCAgICstLSAgICAgICAgICstLSArLS0gfCAgIC0tKwp8IHwgfCB8IHwuICB8
LiAgfC4gICAgICBcLi8gfC4gIHwuICB8LiAgICB8CnwgfCArLSsgKy0tICstLSArLS0gICAgICBW
ICArLS0gfCAgICstLSAtLSsK

```

Without a trailing new line, the md5sum is `581005bef7ee76e24c019d076d5b375f` and the base64 is:

```
Ky0rICstKyB8ICAgfCAgICstLSAgICAgICAgICstLSArLS0gfCAgIC0tKwp8IHwgfCB8IHwuICB8

```

LiAgfC4gICAgICBcLi8gfC4gIHwuICB8LiAgICB8CnwgfCArLSsgKy0tICstLSArLS0gICAgICBW ICArLS0gfCAgICstLSAtLSs=

## Rules

* Standard loopholes are forbidden.
* This is code golf. Shortest code wins.
* In languages which cannot accept multiple lines of input at a time (e.g. JavaScript with `prompt()`), use `*` (or some other character) as a line separator.

## Erranda

* The example was missing a few spaces (A space should consist of the trailing spaces of the previous character, if any, itself, and its own trailing spaces). This has now been fixed.

# Answer
> 4 votes
# JavaScript (ES6) 312 ~~327 340 372 446~~

Not counting indentation white space and newlines ~~\- could be golfed more~~. Using an '\*' to mark new lines in input, as `prompt` accepts a single line.

```
console.log(prompt().split('*').map(s=>
  [0,1,2].map(r=>
  [...s].map(c=>o+=n+
    '   \\1/ \\ /1\\ /  V  ^  1><1 --++-++-- 1||1||1 '.substr(
    (c=(32|c.charCodeAt())-97)<0|c>25?0:c<18
     ?27+3*'330441552030141252033144255'[f=8,c%9*3+r]
     :3*'482630015274'[f=21,c%4*3+r],3,n=' ')
  .replace(1,' .'[r&c>f])
  ,n='\n'),o=''
)&&o).join('\n'))

```

**Test** in FireFox/FireBug console

Input: ABCDEFGHI\*JKLMNOPQR\*STUV\*WXYZ\*HeLlO WoRlD!

```
  | | | |   --+ +-+ +-- --+ +-+ +--
  | | | |     | | | |     | | | |
--+ +-+ +-- --+ +-+ +--   | | | |

  | | | |   --+ +-+ +-- --+ +-+ +--
 .| |.| |.   .| |.| |.   .| |.| |.
--+ +-+ +-- --+ +-+ +--   | | | |

     \   /   ^
\ /   > <   / \
 V   /   \

     \   /   ^
\./  .> <.  /.\
 V   /   \

+-+ +-+ |   |   +--         +-- +-- |   --+
| | | | |.  |.  |.      \./ |.  |.  |.    |
| | +-+ +-- +-- +--      V  +-- |   +-- --+

```

# Answer
> 3 votes
# C# - ~~921~~ 720

Obviously not a winning entry, but this looked like too much fun to pass off :)

Program takes input as a single, then prints the pigpen. To input multiple lines, use an underscore (\_) as seen in **output**.

### Code

```
using System;class P{static void Main(){
int i,y,j,k,w,z;string[]g=Console.ReadLine().ToLower().Split('_');
var d="_________  |b .|b--+_| |b|.|b+-+_|  b|. b+--_--+b .|b--+_+-+b|.|b+-+_+--b|. b+--_--+b .|b  |_+-+b|.|b| |_+--b|. b|  _____   b\\./b v _ \\ b .>b / _ / b<. b \\ _ ^ b/.\\b   _  b  b  ".Replace('b','\n').Split('_');
for(i=0;i<d.Length;i++){if(d[i]==""){d[i]=i<17?d[i+9]:d[i+4];d[i]=d[i].Replace('.',' ');}}
for(y=0;y<g.Length;y++){string o="",s,e=g[y];var r=new string[z=e.Length][];
for(i=0;i<z;i++){if(e[i]-97<0|e[i]-97>25)e=e.Replace(e[i],'{');
o+=d[e[i]-97]+'_';r[i]=(o.Split('_')[i].Split('\n'));}
for(j=0;j<3;j++)for(k=0;k<(w=r.Length);k++){
s=r[k][j];Console.Write(k==w-1?s+'\n':s+' ');}}
Console.ReadLine();}}

```

### Concept

The cipher uses a some character sequences that get duplicated quite a bit. For example, '--' shows up 16 times and '\__' (two spaces) shows up 20 times. I replace these sequences with single-character symbols and switch them out at runtime, cutting the number of characters needed to store the pigpen cipher in half. Similarly, a newline usually requires two characters, but is replaced by a symbol (n) and switched out later.

The program handles multiple lines of input by splitting the input into an array where each element is a single line of input. The program then simply runs the cipher on each line separately.

This is my first golf in any language, so there is probably a lot that can be done to improve this code.

### Output

```
hEllo,wORLd
+-+ +-+ |   |   +--        +-- +-- |   --+
| | | | |.  |.  |.     \./ |.  |.  |.    |
| | +-+ +-- +-- +--     v  +-- |   +-- --+

code_golf
|   +-- --+ +-+
|   |.    | | |
+-- +-- --+ +-+
--+ +-- |   +--
  | |.  |.  |
  | +-- +-- +--

multi_line_input
--+  /  |    \  +--
 .| <   |.    > |
--+  \  +--  /  |
|   +-- +-+ +-+
|.  |   |.| | |
+-- |   +-+ +-+
+-- +-+ --+  /   \
|   |.|  .| <     >
|   +-+   |  \   /

```

# Answer
> 2 votes
# Python 2, 180 + 78 + 1 + 3 = 262 characters

The 180-byte program (last two newlines are tabs):

```
L=open('f','rb').read().decode('zip')
while 1:
 n=raw_input()
 for s in(0,3,6):
    for c in n:w=ord(c.lower())-97;print''.join(L[w+(s+i)*26]for i in(0,1,2))if-1<w<27 else'  ',
    print

```

Requires a 78-byte file called 'f' to be same directory (+1 byte for filename), which contains the following:

```
$ hexdump f
0000000 9c78 a853 d1a9 d6d5 2206 3805 0103 c174
0000010 c100 8b88 07d1 9ae1 051a 4ab0 385d ae03
0000020 2803 8a82 3a80 406c ae18 0f42 6006 0c1c
0000030 0a2d 31fa 6076 ee8c a030 0e14 2987 8428
0000040 7501 3080 c39a 5a10 0014 21c7 7333
000004e

```

The base64 encoding of file `f` is:

```
eJxTqKnR1dYGIgU4AwF0wQDBiIvRB+GaGgWwSl04A64DKIKKgDpsQBiuQg8GYBwMLQr6MXZgjO4w
oBQOhykohAF1gDCawxBaFADHITNz

```

The program exits with an exception, `2>_` suppresses the error (+3 bytes):

```
$ echo "hEllo,wORLd" | python pigpen.py 2>_| ./md5.py
7ed49b7013a30cc3e84aa807f6585325

```

**Explanation**:

I created a look-up table, `L`, which is a mapping of `{position_in_3x3_block: {letter_being_encrypted: symbol_for_letter_at_position}}`, stored in a flat array. The program prints the letters by doing a simple look-up for each position.

# Answer
> 1 votes
# Perl 5 `-lF`, ~~297 288 261~~ 231 bytes

```
$,=$";$_=' .||.||. ';chomp@F;map{@r=/.../g;say map{/[a-z]/i?$r[-65+ord uc]:$"x3}@F}(y/./ /r.y/.| /-+-/r x2)x2 .'    \\  /  ^ 'x2,y/./ /r x3 .$_ x3 .'\\ /  ><  / \\\\./ .><. /.\\',(y/.| /-+-/r x2 .y/./ /r)x2 .' V  /  \\    'x2;say''

```

Try it online!

There's probably still a bit here that could be golfed further.

# Answer
> 0 votes
# Vyxal `j`, 139 bytes

```
⇧×/ƛƛkAnc[C83<[»ƛ_F∆a⋎⁺^9⟨C¨¼ḢO[½ċeẇɽ»`| -+`τ9/nC⇩9%inC73>[4\.Ȧ]|`   \ / V  ^ / \    \   > /  / <   \ `4/nC›4%inC86>[4\.Ȧ]]|ð9*]3/;ÞTvṄ¤J;f

```

Try it Online!

What. A. Mess.

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


title: Output the legendary Yggdrasil

text:
# Question
Title: Output the legendary Yggdrasil
Your task is to output a representation of the legendary tree of life, Yggdrasil.

You must write a program whose output is exactly that :

```
                                       /\
                                      /**\
                                     /****\
                                    /******\
                                    /******\
                                   /********\
                                  /**********\
                                 /************\
                                /**************\
                                 /************\
                                /**************\
                               /****************\
                              /******************\
                             /********************\
                            /**********************\
                              /******************\
                             /********************\
                            /**********************\
                           /************************\
                          /**************************\
                         /****************************\
                        /******************************\
                           /************************\
                          /**************************\
                         /****************************\
                        /******************************\
                       /********************************\
                      /**********************************\
                     /************************************\
                    /**************************************\
                        /******************************\
                       /********************************\
                      /**********************************\
                     /************************************\
                    /**************************************\
                   /****************************************\
                  /******************************************\
                 /********************************************\
                /**********************************************\
                     /************************************\
                    /**************************************\
                   /****************************************\
                  /******************************************\
                 /********************************************\
                /**********************************************\
               /************************************************\
              /**************************************************\
             /****************************************************\
            /******************************************************\
                  /******************************************\
                 /********************************************\
                /**********************************************\
               /************************************************\
              /**************************************************\
             /****************************************************\
            /******************************************************\
           /********************************************************\
          /**********************************************************\
         /************************************************************\
        /**************************************************************\
               /************************************************\
              /**************************************************\
             /****************************************************\
            /******************************************************\
           /********************************************************\
          /**********************************************************\
         /************************************************************\
        /**************************************************************\
       /****************************************************************\
      /******************************************************************\
     /********************************************************************\
    /**********************************************************************\
            /******************************************************\
           /********************************************************\
          /**********************************************************\
         /************************************************************\
        /**************************************************************\
       /****************************************************************\
      /******************************************************************\
     /********************************************************************\
    /**********************************************************************\
   /************************************************************************\
  /**************************************************************************\
 /****************************************************************************\
/******************************************************************************\
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |________|

```

There is no trailing whitespace. The final newline may be omitted.

To make checking easier, here are the md5 sums of the expected output:

* `374899e56bc854d04639c43120642e37` \- No newline at end.
* `03afb81d960b8e130fe2f9e0906f0482` \- Newline at end

Standard loopholes apply. This is code-golf, so the smallest entry in bytes win!

# Answer
# Golfscript, ~~84~~ ~~77~~ ~~76~~ ~~75~~ 72 characters

Different approach from Howard's. Click on the character count to try it.

```
10,{.)4*,\3*>{.39\-' '*'/'@2*'*'*'\
'}/}/12,{' '35*'|'@11<'_-'1/=8*1$n}/

```

Thanks to Howard for saving 3 characters!

**Explanation**:

This is more or less a straightforward port of my Python solution. Taking some expressive liberties (using named variables instead of keeping track of stack positions, and `print` is really keeping things on the stack, not printing):

```
10,{...}/            # for i in range(10):
   .                 #    x = i
   )4*,              #    Y = range((i+1)*4)
   \3*               #    x *= 3
   >                 #    Y = Y[x:]  # y is now range(3*i, (i+1)*4)
   {...}/            #    for j in Y:
      .39\-          #        q = 39 - j
      ' '*           #        print ' '*q  # print right number of spaces
      '/'            #        print '/'
      @2*            #        j *= 2
      '*'*           #        print '*'*j
      '\<NEWLINE>'   #        print "\\\n"
12,{...}/            # for i in range(12):
    ' '35*           #    print ' '*35
    '|'              #    print '|'
    @11<             #    i = i < 11
    '_-'1/=          #    z = "_-"[i] # pick "-" if i < 11, else pick "_"
    8*               #    print z*8
    1$               #    print '|' # (copy from earlier in the stack)
    n                #    print "\n"

```
> 22 votes

# Answer
# Haml & Sass

# 37 + 277 = 314

**Haml:**

```
%link(rel="stylesheet" href="s")
%pre

```

**Sass:**

```
pre:after{$l:"";@for$k from0 to10{@for$i from0 to4+$k{@for$j from0 to40-($k*6+$i*2)/2{$l:$l+' ';}$l:$l+'/';@for$j from0 to$k*6+$i*2{$l:$l+'*';}$l:$l+"\\\a ";}}@for$i from0 to12{@for$j from0 to35{$l:$l+" ";}@if$i<11{$l:$l+"|--------|\a ";}@else{$l:$l+"|________|";}}content:$l;}

```

\*Sass allows control directives, concatenation, and variable dereference. All of which are useful when styling, but verbose while golfing.

---

*gets generated into:*

**HTML:**

```
<link rel="stylesheet" href="s" /><pre></pre>

```

**CSS:**

```
pre:after {
  content: "                                        /\\\a                                        /**\\\a                                       /****\\\a                                      /******\\\a                                      /******\\\a                                     /********\\\a                                    /**********\\\a                                   /************\\\a                                  /**************\\\a                                   /************\\\a                                  /**************\\\a                                 /****************\\\a                                /******************\\\a                               /********************\\\a                              /**********************\\\a                                /******************\\\a                               /********************\\\a                              /**********************\\\a                             /************************\\\a
             /**************************\\\a                           /****************************\\\a                          /******************************\\\a                             /************************\\\a                            /**************************\\\a                           /****************************\\\a                          /******************************\\\a                         /********************************\\\a                        /**********************************\\\a                       /************************************\\\a                      /**************************************\\\a                          /******************************\\\a                         /********************************\\\a                        /**********************************\\\a                       /************************************\\\a                      /**************************************\\\a                     /******************************
**********\\\a                    /******************************************\\\a                   /********************************************\\\a                  /**********************************************\\\a                       /************************************\\\a                      /**************************************\\\a                     /****************************************\\\a                    /******************************************\\\a                   /********************************************\\\a                  /**********************************************\\\a                 /************************************************\\\a                /**************************************************\\\a               /****************************************************\\\a              /******************************************************\\\a                    /******************************************\\\a                   /**********************************
**********\\\a                  /**********************************************\\\a                 /************************************************\\\a                /**************************************************\\\a               /****************************************************\\\a              /******************************************************\\\a             /********************************************************\\\a            /**********************************************************\\\a           /************************************************************\\\a          /**************************************************************\\\a                 /************************************************\\\a                /**************************************************\\\a               /****************************************************\\\a              /******************************************************\\\a             /*****************************************************
***\\\a            /**********************************************************\\\a           /************************************************************\\\a          /**************************************************************\\\a         /****************************************************************\\\a        /******************************************************************\\\a       /********************************************************************\\\a      /**********************************************************************\\\a              /******************************************************\\\a             /********************************************************\\\a            /**********************************************************\\\a           /************************************************************\\\a          /**************************************************************\\\a         /****************************************************************\\\a        /*********
*********************************************************\\\a       /********************************************************************\\\a      /**********************************************************************\\\a     /************************************************************************\\\a    /**************************************************************************\\\a   /****************************************************************************\\\a  /******************************************************************************\\\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a
|--------|\a                                    |--------|\a                                    |________|"; }

```

---

*the resulting page*
> 22 votes

# Answer
# CJam, 62 bytes

```
A,{I4+,{I3*J+_39\-S*'/@2*'**'\N}fJ}fI{35S*'|'-8*'|N++}C*'-/'_*

```

Try it online!

### How it works

```
A,           " Push [ 0  …  9 ].                                                   ";
{            " For each I in that array:                                           ";
  I4+,       " Push [ 0  …  I + 3 ].                                               ";
  {          " For each J in that array:                                           ";
    I3*J+_   " Push K := 3 * I + J twice.                                          ";
    39\-S*   " Push a string consisting of 39 - K spaces.                          ";
    '/       " Push a slash.                                                       ";
    @2*'**   " Push a string consisting of 2 * K asterisks.                        ";
    '\N      " Push a backslash and a linefeed.                                    ";
  }fJ        "                                                                     ";
}fI          "                                                                     ";
{            " Do the following 12 times:                                          ";
  35S*       " Push a string consisting of 35 spaces.                              ";
  '|         " Push a vertical bar.                                                ";
  '-8*'|++   " Push the string '--------|\n'.                                      ";
}C*          "                                                                     ";
'-/'_*       " Replace the hyphen-minus signs of the last string with underscores. ";

```
> 16 votes

# Answer
### GolfScript, 79 characters

```
10,{:^4+,{2*^6*+'*'*.,2/~40+' '*'/'@'\
'}/}/[' '35*]12*'|--------|
'*'||''_'8**

```

Try the code here. Note that the line breaks aren't optional in this code
> 15 votes

# Answer
# Python, ~~148~~ ~~129~~ ~~126~~ 121 characters

```
R=range
for i in R(10):
 for j in R(i*3,4+i*4):print' '*(39-j)+'/'+'**'*j+'\\'
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

```

Thanks to Falko for saving 3 characters and to flornquake for brilliantly saving another 5!
> 13 votes

# Answer
# Bash, ~~236 197~~ 193

10 bytes of code + 1-byte filename + 182-byte data file = 193 bytes total

```
zcat y 2>j

```

## Explanation

`y` is a file containing the Yggdrasil, without a trailing new line, compressed with the zopfli algorithm (invoked as `zopfli --i64`) and then with the last 8 bytes removed. zopfli is compatible with gzip, so I can decompress the file with standard Bash utilities designed for gzip. The size of the data file is 182 bytes (229 bytes when normal gzip is used). The size of the original Yggdrasil, without the trailing new line, is 5876 bytes.

The removal of the last 8 bytes causes error messages, which are suppressed by sending standard error to a file called `j`. If `j` exists, it will be overwritten.

The base64 of `y` is (use `base64 -d` to obtain the original file):

```
H4sIAAAAAAACA+3SMQoCURDA0N5TWC+IFxK8yD/8Nul9hfDRnamT6J+du83zdUPwOACNNDb0+3Bs
tMPhSscDvusHgM9wIcUNclL+5r/luJXkmlh5rM3r8txkMdVNcEn1Nc2a1AU72XWz3Xd91r5z7eZD
AQKQgAI0PDFf8xJfExpQgQhkpAIdz8ytzK3AQMg6UMIQpLQELU/NQc5B/thBegtqHpOc16jHOX/v
x1mPZg19MfrdrBM=

```

And the md5sum is:

```
4a049a80241160cdde0a3cbca323b7f2

```
> 12 votes

# Answer
## Ruby - 100

```
puts (0..21).map{|i|i>9??\ *35+?|+(i>20??_:?-)*8+?|:(0..i+3).map{|y|?\ *(39-z=y+3*i)+?/+?**z*2+?\\}}

```

Puts auto-flattens, so we can collect all the lines even in nested arrays. Needs Ruby 1.9

Try at ideone
> 7 votes

# Answer
# C, 169

```
i;j;p(a,b){while(b--)putchar(a);}main(){for(;i++<10;)for(j=i*3-4;++j<i*4;p(32,39-j),p(47,1),p(42,j*2),puts("\\"));for(++i;i--;p(32,35),p(124,1),p(i?45:95,8),puts("|"));}

```

Ungolfed (and slightly disentangled):

```
int i;
int j;
void p(a,b) {
  while (b--) putchar(a);
}
void main() {
  for (;i++<10;) {
    for (j=i*3-4;++j<i*4;) {
      p(32,39-j);
      p(47,1);
      p(42,j*2);
      puts("\\");
    }
  }
  for (++i;i--;) {
    p(32,35);
    p(124,1);
    p(i?45:95,8);
    puts("|");
  }
}

```
> 7 votes

# Answer
# PowerShell ~~104~~ 101

```
0..9|%{(3*$_)..(3+$_*4)|%{" "*(39-$_)+"/"+"*"*2*$_+"\"}};0..11|%{" "*35+"|"+("-","_")[$_-eq11]*8+"|"}

```
> 7 votes

# Answer
## C# ~~258~~ 234bytes

Thanks to some annoymous user for the suggested edits making good use of the String.PadLeft method!

```
using System;class G{static void Main(){Action<string>p=Console.WriteLine;int i=0,j;for(;i++<10;)for(j=i*3-3;j++<i*4;)p("/".PadLeft(41-j)+"\\".PadLeft(2*j-1,'*'));while(i-->0)p("|--------|".PadLeft(45));p("|________|".PadLeft(45));}}

```

The code is pretty simple, not much left to golf.

Formatted code:

```
using System;
class G
{
    static void Main()
    {
        Action<string> p = Console.WriteLine;
        int i = 0, j;
        for(; i++ < 10 ;)
            for(j = i*3 - 3; j++ < i*4;)
                p("/".PadLeft(41 - j) + "\\".PadLeft(2*j - 1,'*'));
        while(i-- > 0)
            p("|--------|".PadLeft(45));
        p("|________|".PadLeft(45));
    }
}

```
> 6 votes

# Answer
## J, ~~98 88 84~~ 75

```
(85 11 1#3 4$' /*\ |-| |_|')#"1~(39&-,1,+:,1:)"0(12$4),~85(-4&+#-:*>:)&i.10

```
> 6 votes

# Answer
# Ruby - ~~139~~ ~~129~~ ~~126~~ ~~123~~ 121

Hoisted "puts" outside of array creation (suggestion from bitpwner).

```
puts (0..9).map{|i|(i*3...(i+1)*4).map{|j|"/#{'**'*j}\\".rjust(41+j,' ')}}+["%45s"%'|--------|']*11<<'%45s'%'|________|'

```

Ungolfed ("puts" unhoisted):

```

# print fill patterns from the intervals
# [0..3, 3..7, 6..11, 9..15, 12..19, 15..23, 18..27, 21..31, 24..35, 27..39]
# centered on columns 81-82
(0..9).each { |i|
  (i*3...(i+1)*4).each { |j|    # x...y vs x..y-1 saves a char
    puts "/#{'**'*j}\\".rjust(41+j,' ')
  }
}
# print the stump
puts ("%45s\n" % '|--------|') * 11
puts '%45s' % '|________|'

```
> 4 votes

# Answer
# Perl, 127

```
for$i(0..9){for$j($i*3..3+$i*4){print" "x(39-$j),"/","*"x($j*2),"\\\n";}}for$i(0..11){print" "x35,"|",($i>10?"_":"-")x8,"|\n";}

```

### Ungolfed:

```
for $i (0..9) {
  for $j ($i*3..3+$i*4) {
    print " "x(39-$j) , "/" , "*"x($j*2) , "\\\n";
  }
}
for $i (0..11) {
  print " "x35 , "|" , ($i>10?"_":"-")x8 , "|\n";
}

```
> 4 votes

# Answer
# PHP 223 202 181 160 156

Edit I figured out how to alias a function with a variable and was able to chop off some more characters. That `str_repeat` function was really verbose

Edit 2: Thanks everyone for the suggestions!

Golfed:

```
<?$s=str_repeat;for($i=-1;$i++<9;)for($j=$i*3;$j<4+$i*4;)echo$s(' ',39-$j).'/'.$s('**',$j++)."\\
";for($i=12;$i--;)echo$s(' ',35),'|'.$s($i?'-':'_',8)."|
";

```

Readable:

```
    <?

$s=str_repeat;

for($i=-1;$i++<9;)
{
    for($j=$i*3;$j<4+$i*4;)
    {
        echo$s(' ',39-$j).'/'.$s('**',$j++)."\\
        ";
    }
}

for($i=12;$i--;)
{
    echo$s(' ',35),'|'.$s($i?'-':'_',8)."|
    ";
}

```

Output: http://brobin.me/yggdrasil.php
> 4 votes

# Answer
## Javascript, 288 281

Chrome hides duplicated `console.log`s, use IE instead.

```
function t(w){s="";for(i=0;i++<39-w;)s+=" ";s+="/";for(i=0;i++<w*2;)s+="*";return s+"\\"}function r(l){s="";for(i=0;i++<36;)s+=" ";s+="|";for(i=0;i++<8;)s+=l;return s+"|"}w=0;c=console;for(h=0;h++<10;){for(j=0;j++<3+h;)c.log(t(w++));w-=h}for(j=0;j++<11;)c.log(r('-'));c.log(r('_'))

```

Ungolfed:

```
function t(w)
{
    s="";
    for(i=0;i++<39-w;)
        s+=" ";
    s+="/";
    for(i=0;i++<w*2;)
        s+="*";
    return s+"\\"
}
function r(l)
{
    s="";
    for(i=0;i++<36;)
        s+=" ";
    s+="|";
    for(i=0;i++<8;)
        s+=l;
    return s+"|"
}

w=0;
c=console;
for(h=0;h++<10;)
{
    for(j=0;j++<3+h;)
        c.log(t(w++));
    w-=h;
}
for(j=0;j++<11;)
    c.log(r('-'));
c.log(r('_'))

```
> 3 votes

# Answer
# Delphi 429

Will try to improve later.
Golfed

```
uses strutils,SysUtils,Classes;const a='|----';b='|____';c:array [0..9,0..1]of int32=((0,3),(3,7),(6,11),(9,15),(12,19),(15,23),(18,27),(21,31),(24,35),(27,39));var t:TStrings;i,j:integer;begin t:=tstringlist.Create;for I:=0to 9do for J:=c[i,0]to c[i,1]do t.Add('/'+StringOfChar('*',j));for I:=0to 10do t.Add(a);t.Add(b);for I:=0to t.Count-1do t[i]:=t[i].PadLeft(40)+ReverseString(t[i]).Replace('/','\');write(T.TEXT);readln;end.

```

ungolfed

```
uses
  strutils,SysUtils,Classes;
const
  a='|----';
  b='|____';
  c:array [0..9,0..1]of int32=((0,3),(3,7),(6,11),(9,15),(12,19),(15,23),(18,27),(21,31),(24,35),(27,39));
var
  t:TStrings;
  i,j:integer;
begin
  t:=tstringlist.Create;
  for I:=0to 9do
    for J:=c[i,0]to c[i,1]do
      t.Add('/'+StringOfChar('*',j));
  for I:=0to 10do
    t.Add(a);
  t.Add(b);
  for I:=0to t.Count-1do
    t[i]:=t[i].PadLeft(40)+ReverseString(t[i]).Replace('/','\');
  write(T.TEXT);
  readln;
end.

```
> 3 votes

# Answer
# C (219)

Thanks to everyone for the golfing tips -- managed to get it down to 219. Don't think it'll go much lower.

```
w,W,s,S,i,r;main(){char T[78];memset(T,42,78);for(r=4,s=39;r<14;++r,s-=3,w+=6)for(i=0,S=s,W=w;i<r;++i,W+=2,--S)printf("%*s/%.*s\\\n",S,"",W,T);for(i=0;i<11;i++)printf("%35s|--------|\n","");printf("%35s|________|","");}

```

Required includes:

```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

```
> 3 votes

# Answer
## JavaScript (console.log), ~~168~~ 166

(Whitespace for readability only)

```
for(i=c=0;i<11;i++)
  for(j=0;j<4+i&!c;j++)
    l=i*13+j,
    a=Array(n=i-10?3*i+j+1:5).join("*-_"[k=(l>129)+(c=l==141)]),
    console.log(Array(41-n).join(" ")+'/||'[k]+a+a+'\\||'[k])

```
> 3 votes

# Answer
# Haskell, ~~153~~ 148

Straight-forward, no tricks, just plain golfing:

```
(a:b:c)%n=(39-n)&' '++a:(2*n)&b++c
n#m=[n..m]++(n+3)#(m+4)
(&)=replicate
main=putStr$unlines$map("/*\\"%)(take 85$0#3)++map("|-|"%)(11&4)++["|_|"%4]

```

The `%` operator draws a single line, its first argument being a `String` of length 3 containing the borders and the fill characters in that line (now assuming exactly 3 `Char`s, saving 5 bytes), the second, an `Int`, specifies half the number of fill characters. Pattern matching, cons-ing and appending is used in combination in order to save bytes by taking care of the "glue" between `Char` and `String`. In this second version, I also made `#` infinite and introduced a `take 85` to make it finite again (no bytes saved, unfortunately).

The `#` operator creates the sequence for the `n` argument to `%` required for the tree: `[0..3], [3..7], ...` concatenated.

`&` is just an infix shorthand for `replicate`, which occurs three times.

The tree is put together in the last line, the newlines are added by `unlines`.
> 3 votes

# Answer
## Lua - 164

```
a=' 'for i=0,9 do for j=i*3,3+i*4 do print(a:rep(39-j)..'/'..(('*'):rep(j*2))..'\\')end end for i=0,11 do print(a:rep(35)..'|'..((i>10 and'_'or'-'):rep(8))..'|')end

```
> 2 votes

# Answer
**Mathematica ~~191~~ 178**

For sure not the best solution:

```
n=Nest;
t=Table;
""<>
    t[
        {n[#<>" "&,"",39-i],"/",n[#<>"*"&,"",2i],"\\\n"}
    ,
        {i,Flatten@t[Range[j+4]-1+3j,{j,0,9}]}
    ]
<>
    t[
        n[#<>" "&,"",35]<>If[i==12,"|________|\n","|--------|\n"]
    ,
        {i,12}
    ]

```

Not counting newlines. Mathematica skews the output, as it doesn't take the same width for a whitespace as for "\*" and "/". But the result is correct.
> 2 votes

# Answer
# Java - 286

My first golf.

Golfed:

```
class M{public static void main(String[]args){int i=0,a,f=0;String s="";for(;i++<11;){for(a=i*3-4;++a<i*4;){if(i>10){a=4;if(++f>12)break;}s+=s.format("%"+(40-a)+"s"+(a>0?"%0"+a+"d":"")+"%3$s",f>0?"|":"/",0,f>0?"|":"\\").replace("0",f<1?"**":f>11?"__":"--")+"\n";}}System.out.println(s);}}

```

Ungolfed:

```
class M {
    public static void main(String[] args) {
        int i=0,a,f=0;
        String s = "";
        for(;i++<11;){
            for(a=i*3-4;++a<i*4;a++){
                if(i>10){
                    a=4;
                    if(++f>12)break;
                }
                s+=s.format("%"+(40-a)+"s"+(a>0?"%0"+a+"d":"")+"%3$s",f>0?"|":"/", 0,f>0?"|":"\\").replace("0", f<1?"**":f>11?"__":"--")+"\n";
            }
        }
        System.out.println(s);
    }
}

```

Test here
> 2 votes

# Answer
# Python 2, 117

```
j=0
while j<40:j-=j/4;exec(j/3+4)*r"print' '*(39-j)+'/'+'**'*j+'\\';j+=1;"
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

```

---

Other versions I tried include:

```
# 118
for i in range(10):j=i*3;exec(i+4)*r"print' '*(39-j)+'/'+'**'*j+'\\';j+=1;"
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

# 118
i=j=4
while j:j=52-3*i;exec"j-=1;print' '*j+'/'+'**'*(39-j)+'\\\\';"*i;i+=1
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

# 118
j=0
for b in'\\'*10:j-=j/4;exec(j/3+4)*"print' '*(39-j)+'/'+'**'*j+b;j+=1;"
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

# 119
s=40
while s:s+=10-s/4;exec(52-s)/3*r"s-=1;print' '*s+'/'+'**'*(39-s)+'\\';"
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

```
> 2 votes

# Answer
# Pyth, ~~101~~ ~~100~~ ~~99~~ ~~90~~ ~~81~~ 66 bytes

```
jbm+*;-39d++\/*\**2d\\s.e+L*3kb+L4TV11+J*35ds_B"|----";+Js_B"|____

```

Try it online!

---

Python 3.8 translation:

```
from functools import reduce
from operator import add
B = lambda G, H: (H, G(H))
r = lambda s: s[::-1]

print("\n".join(map(lambda d: " "*(39-d)+"/"+"*"*(2*d)+"\\", reduce(add,
map(lambda e: list(map(lambda d: 3*e[0]+d, range(e[1]))), enumerate(map(lambda d: 4+d, range(10))))))))
for N in range(11):
    print((J:=" "*35)+reduce(add, B(r, "|----")))
print(J+reduce(add, B(r, "|____")))

```
> 2 votes

# Answer
# Powershell, 88 bytes

```
0..9|%{(3*$_)..(3+$_*4)|%{' '*(39-$_)+"/$('**'*$_)\"}}
,'-'*10+'_'|%{' '*35+"|$($_*8)|"}

```
> 2 votes

# Answer
## Groovy 118

```
10.times{(it*3).upto 3+it*4,{println' '*(39-it)+'/'+'*'*it*2+'\\'}};12.times{println' '*35+'|'+(it>10?'_':'-')*8+'|'}

```
> 1 votes

# Answer
# C,194

This code is a hot mess and can definitely be golfed more. Still, it was an opportunity to try out a couple of things I've never done before: using a literal for a string of asterisks, and using the width specifier `*` with a string in `printf`.

```
i,j=5,k=5,n;
main(){
  char d[]={[0 ...77]=42,0};
  for(;i<85;i++)k--,j+=!k,k+=(j-1)*!k,n=39-i+(j-5)*(j-4)/2,printf("%*s/%s\\\n",n,"",d+n*2);
  for(;i<97;i++)printf("%*s|\n",44,i-96?"|--------":"|________");
}

```
> 1 votes

# Answer
## Racket 223 220 211 204 198

Golfed:

```
(for-each display(flatten(let([m make-list])`(,(for*/list([i 10][j(range(* i 3)(* 4(+ 1 i)))])`(,(m(- 39 j)" ")"/",(m j"**")"\\\n")),(for/list([c`(,@(m 11"-")"_")])`(,(m 35" ")"|",(m 8 c)"|\n"))))))

```

Ungolfed:

```
(for-each display
     (flatten
      (let([m make-list])
        `(,(for*/list([i 10][j(range(* i 3)(* 4(+ 1 i)))])
             `(,(m(- 39 j)" ")"/",(m j"**")"\\\n"))
          ,(for/list([c`(,@(m 11"-")"_")])
             `(,(m 35" ")"|",(m 8 c)"|\n"))))))

```
> 1 votes

# Answer
# Assembly (MIPS, SPIM), ~~768~~ ~~671~~ ~~659~~ ~~655~~ 654 bytes

```
.text
.globl main
main:
li $8 32
li $9 47
li $t2 42
li $t3 92
li $t4 10
li $t5 42
addi $sp -4
move $4 $sp
la $s6 q
la $s5 w
li $t8 0
li $s0 10
li $t9 0
li $s3 40
li $s2 39
q:
sub $s3 $s3 $t8
add $s2 $s2 $t8
addi $t7 $t8 3
addi $t8 1
blt $s0 $t8 e
r:
sw $0 ($4)
blt $t9 $s2 t
beq $t9 $s2 y
beq $t9 $s3 u
beqz $t7 i
sb $t2 ($4)
p:
li $2 4
syscall
addi $t9 1
ble $t9 $s3 r
move $t9 $0
j $s5
o:
addi $t7 -1
bgez $t7 r
jr $s6
w:
addi $s2 -1
addi $s3 1
j o
t:
sb $8 ($4)
j p
y:
sb $9 ($4)
j p
u:
sb $t4 1($4)
sb $t3 ($4)
j p
i:
sb $t5 ($4)
j p
e:
li $t1 124
li $t3 124
li $t2 45
li $t5 95
li $t7 11
la $s6 a
la $s5 o
li $s2 35
li $s3 44
j r
a:
li $2 10
syscall

```

Try it online!

**Edit:** Saved ~100 bytes by hard coding each character in a register and simply writing to the stack, then abusing the fact that MIPS doesn't have types so implicit word to ascii string is allowed.
**Edit 2:** removed duplicate stack alloc. (`addi $sp -4`) Oops!
**Edit 3:** in rewrite, accidently made the tree stump 1 character too short. (36 in stead of 35). Fixed.
**Edit 4:** -4 bytes by using $8 and $9 instead of $t0 and $t1. they mean the same thing, but $t0 is easier to read. unfortunately, all other t registers are the same length when written nicely ($t2 == $10, but both are 3 characters), so the rest are a wash. I could (in theory) use the remaining 'a' registers (5-7. print syscall uses 4), but afaik the behavior isn't defined when using syscall.
-1 Byte by setting t8 to 0 and branching on less than instead of on equal. also required me to reorder the add ops, which unfortunately made the execution time take a whopping 3 opcodes longer.

Not the best at MIPS, but after clearing my conscience of this in meta discussion, i'm submitting them. MIPS is not designed for this (no output, no for loops) but it's pretty fun to do this perhaps in spite of that.

Unfortunately, I haven't created a commented version for this new solution, but you can view the old version, with full documentation here

Feel free to take the credit and improve upon this answer if you can beat it - I'm probably missing a few optimizations here and there.
> 1 votes

# Answer
# Canvas, 40 bytes

```
Ａ｛３＋｛╷¹╷３×＋*×/×｝］⁵-＊_∔｛４×|×］∔｛║Ｌ»‾◂∔ ××］

```

Try it here!
> 1 votes

# Answer
# Zsh, 114 bytes

```
0 5()<<<${(l:4$0:)1}$2
eval '(repeat '{4..13}' 0 /$S $S\\&&S+=*;);S+=***;' \;{a..l}';5 "|${(l:8::-:)}|"' '|tr - _'

```

Try it online!

Explanation:

* `0 5()`: define a function under both the names `0` and `5`

+ `<<<`: print
    + `${1}`: the first argument,
    + `(l:4$0:)`: left-padded with spaces to the length:
        - `$0`: the name of the function
        - `4`: with a 4 prepended
        - so if this function is called by the name `0`, it will use length 40; if `5`, then 45
    + `$2`: with the second argument appended
* `eval`uate the following string as `zsh` code (you can replace the `eval` with `echo` to see the generated code string is):

+ `{4..13}`: repeat the string `(repeat X 0 /$S $S\\&&S+=*;);S+=***;` multiple times with the numbers from `4` to `13` each in place of the `X`. The meaning of the string
        - `repeat N`: do this `N` times:
            * `0`: call the function with first argument {a `/` plus the variable `$S`} and second argument {the variable `$S` plus a backslash `\\`}
            * `&&`: then
            * `S+=*;`: append a `*` to the variable `$S`
        - `)`: reset all variables (importantly `$S`) to their values before the `(`
        - `S+=***;`: append `***` to `$S`
    + `{a..l}`: repeat the string `;X;5 "|${(l:8::-:)}|"` : repeat this string with the letters from `a` to `l` each in place of the `X`
        - each letter is just a nonexistent command which is ignored; the `{a..l}` here just makes the code execute 12 times
        - `5`: call the function with the first argument `|${(l:8::-:)}|` (and no second argument)
            * `${(l:8::-:)}`: left-pad {nothing} to length 8 with dashes `-`
            * `"||"`: surrounded by pipes
    + `|tr - _`: replace the dashes with underscores. This only applies to the last call to `5`, so only the last line of the trunk is drawn with underscores, because the repeated string `;X;5 "|${(l:8::-:)}|"` has the semicolons at the start to separate the commands.
> 1 votes

# Answer
# brainfuck, 526 bytes

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

```

Try it online!
> 1 votes

# Answer
# Jelly, 55 bytes

```
x39_;ḤØ1jƊƲ}
⁵Ḷµ+4Ḷ++Ḥ“ /*\”çⱮYð€;ø“ |-|”ẋ12”_-¦s4ç€4µY

```

Try it online!
> 1 votes

# Answer
# Cobra - 166 ~~228~~ ~~260~~

```
class P
    def main
        for x in 10,for n in 4+x,print' '.repeat(39-x*3-n)+'/['**'.repeat(x*3+n)]\\'
        w=' '.repeat(35)
        print'[w]|--------|\n'.repeat(11)+w+'|________|'

```
> 0 votes

# Answer
# Python (313)

```
'eJztmEsOwjAMBfecoutIFUfiIjk8FAJNE3+eE0sI6qxnRq3jVZYFOlcQSwnlMPIJeqOFRNgPCsAVq9MH+Lvxhtb4DlcEgpcNUvjBr2IMyWEVQRIc3hKlk/2VYnGeqjEi4NEmJMZwrCpoUi6sErLB7W2THKPGXe9RG+3WN+tNYMA/FoYCcX9/dH+DhboxnKgiE429MhWJ3egSsRttZrLy7kxnSsih8yq5hGL9+Eqsn1TyWz+n0tZySz1ijq2UXGPQi1pey8mXoM9F38rJd5RXZaM='.decode('base64').decode('zip')

```
> 0 votes

# Answer
# C (gcc), ~~163~~ ~~160~~ 159 bytes

-3 -1 bytes thanks to ceilingcat.

```
j,w,s[99];main(i){for(;++i<12;w-=i-1)for(j=i+2;j--;)printf("%*c%.*s\\\n",40-w++,47,w*2,memset(s,42,99));for(;i--;)printf("%44s|\n",i?"|--------":"|________");}

```

Try it online!
> 0 votes

# Answer
# Jelly, 56 bytes

```
4Ḷ4ịr+L}¥¥Ɗ9Ð¡ẎḤ”*ẋ⁾/\jÐ€;⁾-_x11,1¤ẋ8⁾||jƊ€¤µLH40_⁶ẋ;µ€Y

```

Try it online!
> 0 votes

# Answer
# PHP, ~~140 138~~ 136 bytes

```
while($n--||30>$w+=3-$n=3+$i++)echo($p=str_pad)("",39-$w),$p("/",1|2*$w++,"*"),"\\
";while(-~$i)echo$p("",35),$p("|",9,$i--?"-":_),"|
";

```

less golfed:

```
for(;$i<10;$w-=$i)for($n=3+$i++;$n--;)
    echo str_pad("",39-$w), str_pad("/",1+2*$w++,"*"),"\\\n";
for($i++;$i--;)
    echo str_pad("",35), str_pad("|",9,$i?"-":_),"|\n";

```

Run with `php -nr '<code>'` or try it online. Requires PHP 7.
> 0 votes

# Answer
# Japt `-R`, ~~51~~ ~~50~~ ~~49~~ 48 bytes

```
Ao*3 cÈôY+3@'\i'/+Xç*²
cCÆ'|i|+8ç"-_"gXzB})û mx1

```

Test it

```
Ao*3 cÈôY+3@'\i'/+Xç*²
A                             :10
 o                            :Range [0,A)
  *3                          :Multuply each by 3
     c                        :Flatten after ...
      È                       :  Map each X at 0-based index Y
       ôY+3                   :    Sorted range [X,X+Y+3]
           @                  :    Map each X
            '\i               :      Prepend "\" with
               '/+            :        "/" appended with
                  Xç          :          X times repeat
                    *²        :            "*" repeated twice

```

```
cCÆ'|i|+8ç"-_"gXzB})û mx1
c                             :Concatenate
 C                            :  12
  Æ                           :  Map each X in the range [0,C)
   '|i                        :    Prepend "|" with
      |+                      :      "|" appended with
        8ç                    :        8 times repeat
          "-_"g               :          Get the character in "-_" at index
               Xz             :            X floor divided by
                 B            :              11
                  }           :  End map
                   )          :End concat
                    û         :Centre pad each element with spaces to the length of the longest
                      m       :Map
                       x1     :  Trim right
                              :Implicit output, joined with newlines

```
> 0 votes

# Answer
# 05AB1E, 36 bytes

```
TLεÌÝN3*+'*×'/ì]˜…|--11и…|__ªº€¨«º.c

```

Try it online!

```
TLε            ]       # for y in [1 .. 10]
   ÌÝ                  #  [0 .. y+2]
     N                 #  0-based iteration count (effectively y-1)
      3*               #  times 3
        +              #  add (vectorizes over the range, yielding [3*y-3 .. 4*y-1])
         '*×           #  "*" repeated that many times (vectorizes)
            '/ì        #  prepend "/" (vectorizes)
˜                      # flatten
 …|--                  # literal "|--"
     11и               # repeated 11 times as an array
        …|__           # literal "|__"
            ª          # appended to that array
             º         # mirror (vectorizes: ["|----|", "|----|", ..., "|____|")
              €¨       # remove the last character of each
                «      # merge the two lists (["/", "/*", ..., "|----", ...])
                 º     # mirror
                  .c   # center

```
> 0 votes

# Answer
# Deadfish~, 5411 bytes

```
{iii}ii{ccc}ccccccccc{i}iiiiic{iiii}iiiiic{{d}ii}ddc{ii}ii{ccc}cccccccc{i}iiiiicdddddcc{iiiii}c{{d}ii}ddc{ii}ii{ccc}ccccccc{i}iiiiicdddddcccc{iiiii}c{{d}ii}ddc{ii}ii{ccc}cccccc{i}iiiiicdddddcccccc{iiiii}c{{d}ii}ddc{ii}ii{ccc}cccccc{i}iiiiicdddddcccccc{iiiii}c{{d}ii}ddc{ii}ii{ccc}ccccc{i}iiiiicdddddcccccccc{iiiii}c{{d}ii}ddc{ii}ii{ccc}cccc{i}iiiiicddddd{c}{iiiii}c{{d}ii}ddc{ii}ii{ccc}ccc{i}iiiiicddddd{c}cc{iiiii}c{{d}ii}ddc{ii}ii{ccc}cc{i}iiiiicddddd{c}cccc{iiiii}c{{d}ii}ddc{ii}ii{ccc}ccc{i}iiiiicddddd{c}cc{iiiii}c{{d}ii}ddc{ii}ii{ccc}cc{i}iiiiicddddd{c}cccc{iiiii}c{{d}ii}ddc{ii}ii{ccc}c{i}iiiiicddddd{c}cccccc{iiiii}c{{d}ii}ddc{ii}ii{ccc}{i}iiiiicddddd{c}cccccccc{iiiii}c{{d}ii}ddc{ii}ii{cc}ccccccccc{i}iiiiicddddd{cc}{iiiii}c{{d}ii}ddc{ii}ii{cc}cccccccc{i}iiiiicddddd{cc}cc{iiiii}c{{d}ii}ddc{ii}ii{ccc}{i}iiiiicddddd{c}cccccccc{iiiii}c{{d}ii}ddc{ii}ii{cc}ccccccccc{i}iiiiicddddd{cc}{iiiii}c{{d}ii}ddc{ii}ii{cc}cccccccc{i}iiiiicddddd{cc}cc{iiiii}c{{d}ii}ddc{ii}ii{cc}ccccccc{i}iiiiicddddd{cc}cccc{iiiii}c{{d}ii}ddc{ii}ii{cc}cccccc{i}iiiiicddddd{cc}cccccc{iiiii}c{{d}ii}ddc{ii}ii{cc}ccccc{i}iiiiicddddd{cc}cccccccc{iiiii}c{{d}ii}ddc{ii}ii{cc}cccc{i}iiiiicddddd{ccc}{iiiii}c{{d}ii}ddc{ii}ii{cc}ccccccc{i}iiiiicddddd{cc}cccc{iiiii}c{{d}ii}ddc{ii}ii{cc}cccccc{i}iiiiicddddd{cc}cccccc{iiiii}c{{d}ii}ddc{ii}ii{cc}ccccc{i}iiiiicddddd{cc}cccccccc{iiiii}c{{d}ii}ddc{ii}ii{cc}cccc{i}iiiiicddddd{ccc}{iiiii}c{{d}ii}ddc{ii}ii{cc}ccc{i}iiiiicddddd{ccc}cc{iiiii}c{{d}ii}ddc{ii}ii{cc}cc{i}iiiiicddddd{ccc}cccc{iiiii}c{{d}ii}ddc{ii}ii{cc}c{i}iiiiicddddd{ccc}cccccc{iiiii}c{{d}ii}ddc{ii}ii{cc}{i}iiiiicddddd{ccc}cccccccc{iiiii}c{{d}ii}ddc{ii}ii{cc}cccc{i}iiiiicddddd{ccc}{iiiii}c{{d}ii}ddc{ii}ii{cc}ccc{i}iiiiicddddd{ccc}cc{iiiii}c{{d}ii}ddc{ii}ii{cc}cc{i}iiiiicddddd{ccc}cccc{iiiii}c{{d}ii}ddc{ii}ii{cc}c{i}iiiiicddddd{ccc}cccccc{iiiii}c{{d}ii}ddc{ii}ii{cc}{i}iiiiicddddd{ccc}cccccccc{iiiii}c{{d}ii}ddc{ii}ii{c}ccccccccc{i}iiiiicddddd{cccc}{iiiii}c{{d}ii}ddc{ii}ii{c}cccccccc{i}iiiiicddddd{cccc}cc{iiiii}c{{d}ii}ddc{ii}ii{c}ccccccc{i}iiiiicddddd{cccc}cccc{iiiii}c{{d}ii}ddc{ii}ii{c}cccccc{i}iiiiicddddd{cccc}cccccc{iiiii}c{{d}ii}ddc{ii}ii{cc}c{i}iiiiicddddd{ccc}cccccc{iiiii}c{{d}ii}ddc{ii}ii{cc}{i}iiiiicddddd{ccc}cccccccc{iiiii}c{{d}ii}ddc{ii}ii{c}ccccccccc{i}iiiiicddddd{cccc}{iiiii}c{{d}ii}ddc{ii}ii{c}cccccccc{i}iiiiicddddd{cccc}cc{iiiii}c{{d}ii}ddc{ii}ii{c}ccccccc{i}iiiiicddddd{cccc}cccc{iiiii}c{{d}ii}ddc{ii}ii{c}cccccc{i}iiiiicddddd{cccc}cccccc{iiiii}c{{d}ii}ddc{ii}ii{c}ccccc{i}iiiiicddddd{cccc}cccccccc{iiiii}c{{d}ii}ddc{ii}ii{c}cccc{i}iiiiicddddd{ccccc}{iiiii}c{{d}ii}ddc{ii}ii{c}ccc{i}iiiiicddddd{ccccc}cc{iiiii}c{{d}ii}ddc{ii}ii{c}cc{i}iiiiicddddd{ccccc}cccc{iiiii}c{{d}ii}ddc{ii}ii{c}cccccccc{i}iiiiicddddd{cccc}cc{iiiii}c{{d}ii}ddc{ii}ii{c}ccccccc{i}iiiiicddddd{cccc}cccc{iiiii}c{{d}ii}ddc{ii}ii{c}cccccc{i}iiiiicddddd{cccc}cccccc{iiiii}c{{d}ii}ddc{ii}ii{c}ccccc{i}iiiiicddddd{cccc}cccccccc{iiiii}c{{d}ii}ddc{ii}ii{c}cccc{i}iiiiicddddd{ccccc}{iiiii}c{{d}ii}ddc{ii}ii{c}ccc{i}iiiiicddddd{ccccc}cc{iiiii}c{{d}ii}ddc{ii}ii{c}cc{i}iiiiicddddd{ccccc}cccc{iiiii}c{{d}ii}ddc{ii}ii{c}c{i}iiiiicddddd{ccccc}cccccc{iiiii}c{{d}ii}ddc{ii}ii{c}{i}iiiiicddddd{ccccc}cccccccc{iiiii}c{{d}ii}ddc{ii}iiccccccccc{i}iiiiicddddd{cccccc}{iiiii}c{{d}ii}ddc{ii}iicccccccc{i}iiiiicddddd{cccccc}cc{iiiii}c{{d}ii}ddc{ii}ii{c}ccccc{i}iiiiicddddd{cccc}cccccccc{iiiii}c{{d}ii}ddc{ii}ii{c}cccc{i}iiiiicddddd{ccccc}{iiiii}c{{d}ii}ddc{ii}ii{c}ccc{i}iiiiicddddd{ccccc}cc{iiiii}c{{d}ii}ddc{ii}ii{c}cc{i}iiiiicddddd{ccccc}cccc{iiiii}c{{d}ii}ddc{ii}ii{c}c{i}iiiiicddddd{ccccc}cccccc{iiiii}c{{d}ii}ddc{ii}ii{c}{i}iiiiicddddd{ccccc}cccccccc{iiiii}c{{d}ii}ddc{ii}iiccccccccc{i}iiiiicddddd{cccccc}{iiiii}c{{d}ii}ddc{ii}iicccccccc{i}iiiiicddddd{cccccc}cc{iiiii}c{{d}ii}ddc{ii}iiccccccc{i}iiiiicddddd{cccccc}cccc{iiiii}c{{d}ii}ddc{ii}iicccccc{i}iiiiicddddd{cccccc}cccccc{iiiii}c{{d}ii}ddc{ii}iiccccc{i}iiiiicddddd{cccccc}cccccccc{iiiii}c{{d}ii}ddc{ii}iicccc{i}iiiiicddddd{ccccccc}{iiiii}c{{d}ii}ddc{ii}ii{c}cc{i}iiiiicddddd{ccccc}cccc{iiiii}c{{d}ii}ddc{ii}ii{c}c{i}iiiiicddddd{ccccc}cccccc{iiiii}c{{d}ii}ddc{ii}ii{c}{i}iiiiicddddd{ccccc}cccccccc{iiiii}c{{d}ii}ddc{ii}iiccccccccc{i}iiiiicddddd{cccccc}{iiiii}c{{d}ii}ddc{ii}iicccccccc{i}iiiiicddddd{cccccc}cc{iiiii}c{{d}ii}ddc{ii}iiccccccc{i}iiiiicddddd{cccccc}cccc{iiiii}c{{d}ii}ddc{ii}iicccccc{i}iiiiicddddd{cccccc}cccccc{iiiii}c{{d}ii}ddc{ii}iiccccc{i}iiiiicddddd{cccccc}cccccccc{iiiii}c{{d}ii}ddc{ii}iicccc{i}iiiiicddddd{ccccccc}{iiiii}c{{d}ii}ddc{ii}iiccc{i}iiiiicddddd{ccccccc}cc{iiiii}c{{d}ii}ddc{ii}iicc{i}iiiiicddddd{ccccccc}cccc{iiiii}c{{d}ii}ddc{ii}iic{i}iiiiicddddd{ccccccc}cccccc{iiiii}c{{d}ii}ddc{iiii}dddcddddd{ccccccc}cccccccc{iiiii}c{{d}ii}ddc{ii}ii{ccc}ccccc{{i}d}iic{{d}ii}icccccccc{{i}dd}dc{{d}}{d}ddddc{ii}ii{ccc}ccccc{{i}d}iic{{d}ii}icccccccc{{i}dd}dc{{d}}{d}ddddc{ii}ii{ccc}ccccc{{i}d}iic{{d}ii}icccccccc{{i}dd}dc{{d}}{d}ddddc{ii}ii{ccc}ccccc{{i}d}iic{{d}ii}icccccccc{{i}dd}dc{{d}}{d}ddddc{ii}ii{ccc}ccccc{{i}d}iic{{d}ii}icccccccc{{i}dd}dc{{d}}{d}ddddc{ii}ii{ccc}ccccc{{i}d}iic{{d}ii}icccccccc{{i}dd}dc{{d}}{d}ddddc{ii}ii{ccc}ccccc{{i}d}iic{{d}ii}icccccccc{{i}dd}dc{{d}}{d}ddddc{ii}ii{ccc}ccccc{{i}d}iic{{d}ii}icccccccc{{i}dd}dc{{d}}{d}ddddc{ii}ii{ccc}ccccc{{i}d}iic{{d}ii}icccccccc{{i}dd}dc{{d}}{d}ddddc{ii}ii{ccc}ccccc{{i}d}iic{{d}ii}icccccccc{{i}dd}dc{{d}}{d}ddddc{ii}ii{ccc}ccccc{{i}d}iic{{d}ii}icccccccc{{i}dd}dc{{d}}{d}ddddc{ii}ii{ccc}ccccc{{i}d}iic{ddd}icccccccc{iii}dc

```
> 0 votes

# Answer
# Vyxal `C`, 39 bytes

```
₀ƛ‹3*n4*rƛ×*\/pøṀ;;\|4-mw11ẋ\|\_4*+mJJf

```

Try it Online!

```
₀ƛ                ;                     # 1...10 map...
        r                               # Range between...
  ‹3*                                   # 3(n - 1)
        r                               # And...
     n4*                                # 4n (excluded)
         ƛ       ;                      # Map to...
          ×*                            # That many asterisks
            \/p                         # Prepend a backslash
               øṀ                       # Ascii-art mirror
                         11ẋ            # 11 copies of...
                   \|4-mw               # '|--------|'
                            \|\_4*+mJ   # And a '|________|'
                                     Jf # Append to the original and flat the whole thing
                                        # (C flag) center and join by newlines

```
> 0 votes

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


title: Make me an alphabet tree

text:
# Question
Title: Make me an alphabet tree
# Intro

In most fonts all of the uppercase alphabet characters besides `BDO` have single lines approximately touching some of the four corners of the character's bounding rectangle: `ACEFGHIJKLMNPQRSTUVWXYZ`.

For example, the two legs of an `A` "touch" the bottom left and bottom right corners of the character. Likewise, `C` touches its top and bottom right corners (it is a bit curved but it's close enough). `L` only touches it's top left and bottom right corners with single lines. The bottom left corner of `L` is a vertex, not the end of a single line.

Here is a table of what characters touch which corners according to the Stack Exchange font I (and hopefully you) see. `1` is for upper left, `2` is for upper right, `3` lower left, `4` lower right.

```
A: 3 4
C: 2 4
E: 2 4
F: 2 3
G: 2
H: 1 2 3 4
I: 1 2 3 4
J: 1 3
K: 1 2 3 4
L: 1 4
M: 3 4
N: 2 3
P: 3
Q: 4
R: 3 4
S: 2 3
T: 1 2
U: 1 2
V: 1 2
W: 1 2
X: 1 2 3 4
Y: 1 2
Z: 1 4

```

# Setup

Pretend like these corner touching lines extend in the direction of the corner that they touch so that arrangements of these characters on a grid can be "connected".

For example, all the characters in

```
 A
C X

```

are connected because the bottom left of `A` and top right of `C` connect, and the bottom right of `A` and top left of `X` connect.

However,

```
CAX

```

has no connections because **connections only occur diagonally from one character to the next**.

# Challenge

Write the shortest program possible (in bytes) that outputs all of the characters in `ACEFGHIJKLMNPQRSTUVWXYZ` in one big fully connected tree, according to the rules above. **Each character must appear exactly once.** Use spaces for empty space.

# Example

Everything in this 23-letter tree can be reached from anything else via the diagonal connections defined above:

```
  Q
 A J   R
C U   S Y
 I M N
E H X
 F L T
G   Z K P
     V W

```

# Notes

* You may hardcode your solution.
* Your output should only contain `ACEFGHIJKLMNPQRSTUVWXYZ`, spaces, and newlines. `BDO` will not be used.
* Leading/trailing spaces are fine as long as all the connections are properly positioned.
* The output grid should not be larger than 30 by 30 characters (including newlines and spaces).
* Only corner connections are considered. The bottom of `Y` does not connect to anything. You must use the corner connections from the table above.
* Not all connectable corners need to connect to something. Connectable and non-connectable corners may border each other.
* Output to stdout. There is no input.
* Including a connectivity graph made with slashes as Peter Taylor has done is a helpful touch but not required.

**Update:**
githubhagocyte has made an alphabet tree validity checker over on Github.

# Answer
# Pyth, 32

```
jd"QAPMFRLZ\nUINKSHXJ\n\0GTCVEWY

```

Output:

```
Q A P M F R L Z
 U I N K S H X J
  G T C V E W Y

```

Connections, thanks to @githubphagocyte's checker:

```
Q   A   P   M   F   R   L   Z
 \ / \ /   / \ /   / \   \   \
  U   I   N   K   S   H   X   J
     / \ /   / \ /   / \ / \ /
    G   T   C   V   E   W   Y

```

Combines @grc's null byte trick and Pyth's extremely short syntax. Made my own grid for the hell of it.

Explanation:

`j` is python's string join. `d` is space. `\0` is the escape sequence for the null byte. It is a NOP when printed, so the third line has exactly two spaces in front. Also, note that strings can be EOL-terminated in Pyth, as well as quote-terminated.
> 1 votes

# Answer
## Python, 49

```
print' '.join('  MQRCNAF\n XZHLKSIP\n\0GJWVUYET')

```

Example:

```
>>> print' '.join('  MQRCNAF\n XZHLKSIP\n\0GJWVUYET')
    M Q R C N A F
   X Z H L K S I P
  G J W V U Y E T

```

I think it connects up properly now, but I may have missed something again.
> 12 votes

# Answer
## GolfScript (41 chars)

```
'QZENRPMALHIFKSXJTUVWYGC'8/{' '*n' '+:n}/

```

Online demo

Connectivity graph:

```
Q   Z   E   N   R   P   M   A
 \   \   \ /   / \ /   / \ / \
  L   H   I   F   K   S   X   J
   \ / \ / \ /   / \ /   /   /
    T   U   V   W   Y   G   C

```
> 12 votes

# Answer
# Marbelous ~~164~~ ~~158~~ 143

used bmarks' tree since it almost perfectly optimized for Marbelous. Code in this case is just the ascci codes for all characters (including spaces and newlines) from left to right, delimited by spaces.

```
43 20 46 20 50 20 4D 20 51 20 52 20 45 20 41 14 20 58 20 48 20 4e 20 4C 20 4B 20 5A 20 49 20 53 14 47 20 59 20 56 20 20 20 55 20 4A 20 54 20 57

```

*Output:*

```
 C F P M Q R E A
  X H N L K Z I S
 G Y V   U J T W

```

# A better Marbelous approach ~~135~~ 129

This one outputs the same tree with one extra space before and after each line, it works by feeding the literals into a subroutine that prints a space before printing the literal. And just printing a space if the literal is a space (20 HEX)

```
57
54
4A
55
20
56
59
47
14
53
49
5A
4B
4C
4E
48
58
20
14
41
45
52
51
4D
50
46
43
Sp
Sp:
20 I0
.. =V

```
> 9 votes

# Answer
# BrainF\*ck 669

Made this one for giggles. Outputs the exact same as the example.
Will provide another solution later. Can't think of a clever way to do this in Lua so I'll just stick to this one :)

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

```

### Output

```
  Q
 A J   R
C U   S Y
 I M N
E H X
 F L T
G   Z K P
     V W

```
> 7 votes

# Answer
# PHP 46

This was more like puzzle solving rather than programming, so my answer is more like puzzle solution rather than code. However it's a valid PHP program, so I'm submitting it.

```
C A Q S R P M J
 X Z I F K N H
G T U V W Y E L

```

**Update** the same in Perl. Length still remains 46:

```
print"CAQSRPMJ
 XZIFKNH
GTUVWYEL"=~s/\S/$& /rg

```
> 7 votes

# Answer
## HTML, 55

code

```
<pre>C F P M Q R E A
 X H N L K Z I S
G Y V   U J T W

```

output:

```
C F P M Q R E A
 X H N L K Z I S
G Y V   U J T W

```
> 4 votes

# Answer
# Bash+coreutils, 46

```
sed 's/\S/ &/g'<<<"CAQSRPMJ
 XZIFKNH
GTUVWYEL"

```

Now shamelessly borrowing @core1024 optimal tree:

### Output:

```
$ ./alphatree.sh
 C A Q S R P M J
  X Z I F K N H
 G T U V W Y E L
$

```
> 3 votes

# Answer
## STATA 63

Edit: now my own solution. Should be all the letters.

```
di 'C F P M Q R E A' di ' X H N L K Z I S' di 'G Y V   U J T W'

 C F P M Q R E A
  X H N L K Z I S
 G Y V   U J T W

```
> 2 votes

# Answer
# Javascript 83

I'll begin with hardcoding YOUR solution

```
console.log('  Q\n A J   R\nC U   S Y\n I M N\nE H X\n F L T\nG   Z K P\n     V W')

```
> 1 votes

# Answer
# PHP, 69

```
<?php echo preg_replace("/(\w)/",'\1 ',"CAQSRPMJ
 XZIFKNH
GTUVWYEL");

```

gives

```
C A Q S R P M J
 X Z I F K N H
G T U V W Y E L

```
> 1 votes

# Answer
# Vyxal, 28 bytes

```
«⟑Eƈ↓Z↔⁺τ¾ꜝdB_ḣC«3/ƛṄ¥$꘍&›⇧,

```

Try it Online!

Yes, I stole @isaacg's grid.

```
«...«            # Compressed string 'qapmfrlzuinkshxjgtcvewy ' (Note trailing space)
     3/          # Into 3 pieces
       ƛ         # Map...
        Ṅ        # Join by spaces
         ¥$꘍     # Prepend (register) spaces
            &›   # Increment register
              ⇧, # Output as uppercase.

```
> 0 votes

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