# Create a 'Triforce' array (Sierpiński Triangle) with a formula

Trusted Contributor

# Create a 'Triforce' array (Sierpiński Triangle) with a formula

I've been studying 'pyramid' arrays lately and with a new Zelda title out, I was inspired to generate a left-justified 'Triforce' array with a formula.

Sierpiński triangle - Wikipedia

Triforce - Wikipedia

I took the approach of identifying and keeping the odd binomial coefficients and discarding evens.

``````Sierpiński
=LAMBDA(r,c,LET(n, INT(COMBIN(r - 1, c - 1)), IF(AND(r = 1, c = 1), 1, IF(c <= r, IF(ISODD(n), 1, ""), ""))))

Triforce
=LAMBDA(dim,MAKEARRAY(dim, dim, Sierpiński))``````

I'm interested in any other creative approaches to creating this array!

6 Replies

# Re: Create a 'Triforce' array (Sierpiński Triangle) with a formula

ok this ISODD() (pun intended). there are a couple of errors in your output and I don't think due to the formula. In particular on cell(26,11) the calculation is COMBIN(25,10) which = 3268760 and the result of ISODD is TRUE. This is the classic roundoff / representation inside of excel causing issues so you need to add INT() around that COMBIN (or around the N)

# Re: Create a 'Triforce' array (Sierpiński Triangle) with a formula

On another note I complicated the formula a bit for aesthetic improvements:

``=MAKEARRAY(K2,K2,LAMBDA(r,c, IF(AND(r = 1, c = 1), "\", IF(c = r,"\",IF(c<r, IF(ISODD(INT(COMBIN(r - 1, c - 1)) ), IF(ISODD(INT(COMBIN(r - 2, c-1 )*COMBIN(r-1, c ))),"X","\"), ""), "")))))``

or using characters I found in the Cambria Math font I could get:

Good catch!

# Re: Create a 'Triforce' array (Sierpiński Triangle) with a formula

The left justified one is straightforward and maybe too easy!  This one below (Image) would take some work to add spaces where needed for the sake of appearance in Excel:
1

1       1

1       1      1

# Re: Create a 'Triforce' array (Sierpiński Triangle) with a formula

@Patrick2788  here is a start:

``=LET(s,K2,MAKEARRAY(s,2*s,LAMBDA(r,i,LET(c,ROUND((r+i-s)/2,0),IF(c<1,"",IF(AND(r=1,c=1),K3,IF(c=r,K3,IF(c<r,IF(ISODD(INT(COMBIN(r-1,c-1))),IF(ISODD(INT(COMBIN(r-2,c-1)*COMBIN(r-1,c))),K4,K3),""),""))))))))``

getting closer:

``````=LET(s,K2,MAKEARRAY(s,2*s,LAMBDA(r,i,LET(cc,(r+i-s)/2,c,ROUND(cc,0),cp,ROUND(cc+0.5,0),cm,ROUND(cc-0.5,0),
IF(c<1,"", IF(AND(r=1,c=1,cp=1),K5,IF(AND(c=r,cm=r),K6,
IF(c<=r,IF(ISODD(INT(COMBIN(r-1,c-1))),
IF(ISODD(INT(IFERROR(COMBIN(r-1,cm-1),0))),
IF(ISODD(INT(COMBIN(r-1,cp-1))),K7,
IF(ISODD(INT(COMBIN(r-2,c-1))),K8,K6)),
IF(ISODD(INT(IFERROR(COMBIN(r-2,c-1),0))),K5,K9)),""),""))))))))``````

# Re: Create a 'Triforce' array (Sierpiński Triangle) with a formula

This is my solution:

``````'Triforce
=DROP(
REDUCE(
"",
SEQUENCE(32),
LAMBDA(a, v,
LET(
binom, INT(COMBIN(v - 1, TAKE(Seq, , v * 2))),
padding, EXPAND("", 1, 64 - v, ""),
resize, EXPAND(1, 1, 2, 1),
VSTACK(
a,
EXPAND(HSTACK(padding, IF(v = 1, resize, IF(ISODD(binom), 1, ""))), 1, 96, "")
)
)
)
),
1,
32
)``````

I achieved the 'doubling' with some help from Seq which is:

``````Seq
=INT(SEQUENCE(, 64, 0, 0.5))``````

Rolled it into a 'Triangle' Lambda where you can pick left justified or Triforce.