[Question]
  [
This challenge takes place on the [snub square tiling](https://en.wikipedia.org/wiki/Snub_square_tiling).
Start by choosing any triangle, and color it \$c\_1\$.
Next, find all tiles which touch this triangle at any vertex, and color them \$c\_2\$. Next, find all tiles which share a vertex with any \$c\_2\$-colored tile, and color these \$c\_3\$.
Continue this process ad infinitum.
# Illustration
[![Concentric tiling on snub square tiling](https://i.stack.imgur.com/Sst1X.png)](https://i.stack.imgur.com/Sst1X.png)
# Initial terms
The sequence begins
```
  a(1) = 1
  a(2) = 9
  a(3) = 21
  a(4) = 35
```
Notice:
* `a(1) = 1` corresponds to the red triangle;
* `a(2) = 9` corresponds to the number of tiles in the second, orange layer;
* `a(3) = 21` corresponds to the number of tiles in the third, green layer; and so on.
(Note, this [sequence is now in the OEIS](https://oeis.org/A332019); OEIS sequence [A296368](https://oeis.org/A296368) is closely related.)
# Challenge
Your goal is to write a program that takes in a positive integer `n` and returns the number of tiles that are colored \$c\_n\$, (i.e. the number of tiles in the \$n\$-th layer.) This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") challenge, so the shortest code in bytes wins.
  
[Answer]
# [Ruby](https://www.ruby-lang.org/), 26 bytes
```
->n{~-n*12-496/4**n%4+1/n}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vuk43T8vQSNfE0kzfREsrT9VE21A/r/a/hqGenqGBpl5uYkF1TWZNgUJ0pk5adGZsbO1/AA "Ruby – Try It Online")
Revised version adding `1/n` and subtracting `496/4**n%4` to get the `+1,-3,-3,-1` offset for the first 4 terms.
# [Ruby](https://www.ruby-lang.org/), 32 bytes
```
->n{n>4?~-n*12:[0,1,9,21,35][n]}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vOs/OxL5ON0/L0Mgq2kDHUMdSx8hQx9g0Njovtva/hqGenqGBpl5uYkF1TWZNgUJ0pk5adGYsUAoA "Ruby – Try It Online")
After 4, the sequence settles down to `(n-1)*12`. See diagram below (the equilateral triangles have been distorted into 45 degree isosceles triangles and the entire diagram rotated 45 degrees, but it remains topologically equivalent.)
[![enter image description here](https://i.stack.imgur.com/QYnJD.png)](https://i.stack.imgur.com/QYnJD.png)
[Answer]
# JavaScript (ES6), 23 bytes
Based on [Level River St's answer](https://codegolf.stackexchange.com/a/198953/58563).
```
n=>[1,5,13,7][--n]^n*12
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/P1i7aUMdUx9BYxzw2Wlc3LzYuT8vQ6H9afpFGnoKtgqG1Qp6CDZA2ADK0tTUVqrkUFJLz84rzc1L1cvLTNRISNVSq82o1gWpVqtM08jRrEzStuWr/AwA "JavaScript (Node.js) – Try It Online")
### How?
We compute \$(n-1)\times12\$ and adjust the first 4 values with a XOR.
$$\begin{array}{c|c}
n&1&2&3&4&5&6&7&8&9&10\\
\hline
(n-1)\times12&0&12&24&36&48&60&72&84&96&108\\
\hline
\text{XOR}&1&5&13&7&\color{grey}0&\color{grey}0&\color{grey}0&\color{grey}0&\color{grey}0&\color{grey}0\\
\hline
a(n)&1&9&21&35&48&60&72&84&96&108
\end{array}$$
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
```
<©12*3®cα
```
[Try it online!](https://tio.run/##yy9OTMpM/f/f5tBKQyMt40Prks9t/P/fGAA "05AB1E – Try It Online") or [try a test suite](https://tio.run/##yy9OTMpM/R/i7mevpKBrp6Bk7/ff5tBKQyMt40Prks9t/K/zHwA).
```
<           # input - 1
 ©          # save to register
  12*       # multiply by 12
      ®     # push the register
     3 c    # binomial coefficient(3, input - 1)
        α   # absolute difference
```
With 0-indexing, this would be 7 bytes:
```
12*3Icα
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
’3cạ×ʋ12
```
**[Try it online!](https://tio.run/##y0rNyan8//9Rw0zj5Ie7Fh6efqrb0Oj///@mAA "Jelly – Try It Online")**
### How?
```
’3cạ×ʋ12 - Link: integer, n
’        - decrement              (n-1)                1   2   3   4   5   6   7  ...
      12 - twelve                 12                  12  12  12  12  12  12 12  ...
     ʋ   - dyad:
 3       -   three                3                    3   3   3   3   3   3   3  ...
  c      -   choose               3C(n-1)              1   3   3   1   0   0   0  ...
    ×    -   multiply             (n-1)*12             0  12  24  36  48  60  72  ...
   ạ     -   absolute difference  |3C(n-1)-(n-1)*12|   1   9  21  35  48  60  72  ...
```
[Answer]
# [Python](https://docs.python.org/3/), 31 bytes
```
lambda n:n*12-11-(n>4or 5%-n%5)
```
[Try it online!](https://tio.run/##DcrNCkBAFAbQV/lSakZmcf1sFC@CxYjhFtc02UiefTjr4@9rO6WMDi2GuNtjmi2kkYwKQ2SUdNUZUKdG0lrH3geWS7nk4Remw@MU6zfRcH9isCBYWRdFeUF6jB8 "Python 3 – Try It Online")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 14 bytesSBCS
```
12(|×-3!⍨⊢)-∘1
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///39BIo@bwdF1jxUe9Kx51LdLUfdQxw/B/2qO2CY96@x71TfX0f9TVfGi98aO2iUBecJAzkAzx8Az@n3ZoxaPezYYGAA "APL (Dyalog Unicode) – Try It Online")
Direct translation of [Jonathan Allan's Jelly answer](https://codegolf.stackexchange.com/a/198961/78410). Even the code structure is the same. Jelly is a golfy descendant of APL; if you want to learn Jelly, learn APL first!
### How it works
```
12(|×-3!⍨⊢)-∘1  ⍝ Monadic train, input: n
12(       )-∘1  ⍝ Pass on to the inner function with left←12 and right←n-1
    ×             ⍝ left × right
     -            ⍝ minus
      3!⍨⊢        ⍝ binomial(3, right)
   |              ⍝ absolute value of the above
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~15~~ 9 bytes
```
’3cạ×12$Ʋ
```
[Try it online!](https://tio.run/##AS8A0P9qZWxsef//4oCZM2PhuqHDlzEyJMay/zvigJwgLT4g4oCdO8OHCjEww4figqxZ/w "Jelly – Try It Online")
A monadic link taking \$n\$ as its argument and returning \$a(n)\$. 
Based on [@LevelRiverSt’s clever Ruby answer](https://codegolf.stackexchange.com/a/198953/58563) so be sure to upvote that one too!
Thanks to @Grimmy for saving 6 bytes!
## Explanation
```
 ’       | Subtract 1
       Ʋ | Following as a monad
3c       | - Number of ways of picking (n-1) items from 3
  ạ   $  | - Absolute difference from:
   ×12   |   - Multiply (n-1) × 12
```
[Answer]
# brainfuck, 50 bytes
```
>>>>>>+<++<<----<+<,-[>++++++++++++[[>+<-]<]>>-]>.
```
Does i/o as raw byte values, like the others here.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 26 bytes
```
{$_*12-[-1,3,3,1][$_]}o*-1
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwv1olXsvQSDda11DHGAgNY6NV4mNr87V0Df9bcxUnViroAdWl5RcpGOrpGRr8BwA "Perl 6 – Try It Online")
If this could be zero-indexed the `o*-1` at the end can be removed. Returns `(n-1)*12`, offsetting the first 4 values.
[Answer]
# [Python 3](https://docs.python.org/3/), 40 36 bytes
```
lambda n:~-n*12-(*n*[0],1,3,3,-1)[4]
```
[Try it online!](https://tio.run/##DcJBCoMwEAXQq3xcJSGBjnYl2IukWUQ0dkBHCW5E9OqxvLcd@2@VpiR0@JY5Lv0QIe3txFDtlBHjX8GSbf4caf8OxW@ZZVepOvmC@@BMivVVaaQ1g8GCHGUaFVkiHcoD "Python 3 – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 39 bytes
```
lambda n:n>4and~-n*12or[1,9,21,35][n-1]
```
[Try it online!](https://tio.run/##BcFBCoMwEAXQqwyukhIXk9RFBb2IuphiYwfaHwluRPTq8b11374JocRuLD/5v2chtOifgvmq8WCf8sDu5Ty70EwDap5KTJmUFJQFy8ewY7btmhWbiZWYQ09LHR3RqD0rW24 "Python 3 – Try It Online")
Total rip of [Level River St](https://codegolf.stackexchange.com/users/15599/level-river-st)'s answer so upvote him.
[Answer]
# [Python](https://docs.python.org/3/), 38 bytes
```
lambda n:n*12-11-([1]*n+[2,4,4,0])[-n]
```
**[Try it online!](https://tio.run/##HYlLCoAgFAD3neLt0lLoVRAEdRFzYZQV1DPMTae3z8xqmPMOq6Mq2m6IuznGyQC1lGEpESVTqDPKVSnq10JzJUlH6zyE@QqwEXhDy8xQADa8TeDl9BsF9n0BqexTAfYvzuMD "Python 3 – Try It Online")**
[Answer]
# [J](http://jsoftware.com/), 14 bytes
```
12(*|@-3!~])<:
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/DY00tGocdI0V62I1baz@a3IpcKUmZ@QraFinaSqo2SkYamfqGRr8BwA "J – Try It Online")
A [J](http://jsoftware.com/) port of [Bubbler's APL answer](https://codegolf.stackexchange.com/a/198966/75681), so it's also a port of [Jonathan Allan's Jelly answer](https://codegolf.stackexchange.com/a/198961/78410).
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~34~~ ~~33~~ 32 bytes
Saved a byte thanks to [Grimmy](https://codegolf.stackexchange.com/users/6484/grimmy)!!!
```
f(n){n=--n<4?"!)5C"[n]-32:n*12;}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI0@zOs9WVzfPxsReSVHT1FkpOi9W19jIKk/L0Mi69n9uYmaehmZ1Wn6RRmZeiUKmrYG1tnamjZGhdUERUCBNQ0k1RUHXTkE1JSZPSSdTJ00jU1NTE6gRAA "C (gcc) – Try It Online")
[Answer]
# brainfuck, 78 bytes
```
++++[->+++<]>>>+>--->--->-<<<<<<,-[->>>[+]<[->+<]<[->+>+<<]<[->+<]>]>>[->+<]>.
```
You can try it online over at [TIO](https://tio.run/##SypKzMxLK03O/p@bmptfVGnFlZlXoFCjYGgEJBKTk0FMIM5LTVcwRqNB4gZQnFqSnFqSWpT4XxsIonXtgKRNrJ2dnbadrq4uBNuAgY4uUNbOLlo71gakzAZCARk2MAE7oD4oS@//fy4A) (the input is a line-feed (ascii 10) and the output is an `l` (ascii 108))
You can also try the verbose code at [this](https://copy.sh/brainfuck/?c=KysrK1stPisrKzxdIHNldCB1cCAxMgo-Pj4rPi0tLT4tLS0-LSBzZXQgdXAgdGhlIHNoaWZ0cwo8PDw8PDwgYmFjayBhdCAwCiwKbWVtb3J5IGF0IHRoaXMgcG9pbnQgKHBvaW50ZXIgaXMgYXQgdGhlIGxlZnQpCmlucCB8IDEyIHwgMCAoYWNjdW11bGF0b3IpIHwgMSB8IG5lZyAzIHwgbmVnIDMgfCBuZWcgMSB8IDAgfCAwIHwgZXRjZXRlcmEKLSBzdWJ0cmFjdCAxIGZyb20gbiBmaXJzdApbIHdoaWxlIHRoZXJlIGlzIHNvbWUgaW5wdXQKLSBkZWNyZW1lbnQgaXQuCj4-PlsrXSB6ZXJvIG91dCB0aGUgbmV4dCBzaGlmdAo8Wy0-KzxdIG1vdmUgdGhlIG91dHB1dCBvbmUgY2VsbCBmb3J3YXJkCjxbLT4rPis8PF0gbW92ZSB0aGUgMTIgZm9yd2FyZCBhbmQgYWxzbyBhZGQgaXQgdG8gdGhlIG91dHB1dAo8Wy0-KzxdPiBtb3ZlIHRoZSBpbnB1dCBvbmUgY2VsbCBmb3J3YXJkCl0KPj4KWy0-KzxdIGFkZCBvdXRwdXQgdG8gb2Zmc2V0Cj4uIHByaW50IG91dHB1dA$$) online interpreter where input can be inserted as decimals, e.g. `\6` gives 6 as input. After running, you can hit the "view memory" button and check the value of the output cell in bold, to ensure the result is right.
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), 61 bytes
```
,-[>++<-[>+++<-[>+++>++<<-[>+++>+<<-[>+++<-]]]]]>[>++++<-]>+.
```
Input/output as character codes ([meta](https://codegolf.meta.stackexchange.com/a/18027/6484)).
[Try it online!](https://tio.run/##SypKzMxLK03O/v9fRzfaTlvbBkzCKJAAnGkDl4sFATswB8Sz09b7/58LAA "brainfuck – Try It Online") or [try it with decimal I/O](https://tio.run/##dVBBCsMwDHuQl152FfqI8aEbDMagh8Hen8pum22wCeLEtiwluTzn@3J7XR@d5t6CWic3b2941qzg2EpsoRPgjbQBICguYGQoRAQCXQLqVTy2LIwjRi8SrCQzWv@Wl50xydJnXjJNKkOh7BU@hzTzfyI2vu8D2d4hwpQPsWQEvHRwfEMbDpKYioGfEmrltdMV/bwC).
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 10 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
Å²@8Ω@╩vä3
```
[Run and debug it](https://staxlang.xyz/#p=8ffd4038ea40ca768433&i=1%0A2%0A3%0A4&m=2)
[Answer]
# Rust - 52 bytes
```
let m=|n|(match n{1=>1,2=>9,3=>21,4=>35,_=>n}-1)*12;
```
oh gosh.. it loses even to Brainf\*\*\*
]