Skip to main content
added 22 characters in body
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 17
  • 43

Jelly, 1515 9 bytes

-,3,3,1ṫḢạ’×12Ɗ’3cạ×12$Ʋ

Try it online!Try it online!

A monadic link taking \$n\$ as its argument and returning \$a(n)\$.

Based on @LevelRiverSt’s clever Ruby answer so be sure to upvote that one too!

Thanks to @Grimmy for saving 6 bytes!

Explanation

-,3,3,1ṫ        | Sublist ofSubtract -1,3,3,1 starting at 
 the nth character (empty if n>4)
   Ʋ | Following as a monad
3c       | Head (zero if- emptyNumber list)
of ways of picking (n-1) items from 3
$ Ɗ | - Absolute difference from:
     ×12   |  ’×12 - |Multiply (n-1) × 12

Jelly, 15 bytes

-,3,3,1ṫḢạ’×12Ɗ

Try it online!

A monadic link taking \$n\$ as its argument and returning \$a(n)\$.

Based on @LevelRiverSt’s clever Ruby answer so be sure to upvote that one too!

Explanation

-,3,3,1ṫ        | Sublist of -1,3,3,1 starting at the nth character (empty if n>4)
               | Head (zero if empty list)
Ɗ | Absolute difference from:
          ’×12  | (n-1) × 12

Jelly, 15 9 bytes

’3cạ×12$Ʋ

Try it online!

A monadic link taking \$n\$ as its argument and returning \$a(n)\$.

Based on @LevelRiverSt’s clever Ruby answer 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
Source Link
Nick Kennedy
  • 21.2k
  • 3
  • 17
  • 43

Jelly, 15 bytes

-,3,3,1ṫḢạ’×12Ɗ

Try it online!

A monadic link taking \$n\$ as its argument and returning \$a(n)\$.

Based on @LevelRiverSt’s clever Ruby answer so be sure to upvote that one too!

Explanation

-,3,3,1ṫ        | Sublist of -1,3,3,1 starting at the nth character (empty if n>4)
        Ḣ       | Head (zero if empty list)
         ạ    Ɗ | Absolute difference from:
          ’×12  | (n-1) × 12