[Question]
  [
My robot for generating [Mad Libs](https://en.wikipedia.org/wiki/Mad_Libs)-style [sequence](/questions/tagged/sequence "show questions tagged 'sequence'") challenges has gone rogue! To defeat it, I need you to write code that can solve all the challenges it can crank out.
Your input is three selections for the blanks A, B, C, each from (1,2,3), specifying the sequence challenge to solve, and the number \$n\$ that's the input to the challenge.
**Challenges**
Given a positive integer \$n\$, output (A) \_\_\_\_\_\_\_\_
> 
> **A:**  
> 
>  (1) the \$n\$'th  
> 
>  (2) whether \$n\$ is a  
> 
>  (3) the smallest number above \$n\$ that's a
> 
> 
> 
positive (B) \_\_\_\_\_\_\_
> 
> **B:**  
> 
>  (1) [Fibonacci number](https://en.wikipedia.org/wiki/Fibonacci_number)  
> 
>  (2) [triangular number](http://triangular%20number)  
> 
>  (3) multiple of 3
> 
> 
> 
whose base-10 representation (C) \_\_\_\_\_\_\_
> 
> **C:**  
> 
>  (1) starts and ends with the same digit.  
> 
>  (2) is in sorted order.  
> 
>  (3) doesn't have any 1's.
> 
> 
> 
**Example**
Given selections `(A, B, C) = (3, 1, 1)` and `n=13`, the challenge is "Given a positive integer \$n\$, output (A3) the smallest number above \$n\$ that's a positive (B1) Fibonacci number whose base-10 representation (C1) starts and ends with the same digit." With input `n=13`, the Fibonacci numbers bigger than \$13\$ start out as \$21, 34, 55, 89, ...\$, and the first one starting and ending with the same digit is is 55. So you should output 55.
**Details**
* You may take the fill-in-the-blank selections one-indexed (1, 2, 3) or zero-indexed (0, 1, 2).
* Note that we're restricting the sequences to positive values, so none of them contain zero. They start as
	+ Fibonacci: \$1, 1, 2, 3, ...\$
	+ Triangular: \$1, 3, 6, 10, ...\$
	+ Multiple of 3: \$3, 6, 9, 12, ...\$
* For choice A1, outputting the \$n\$'th element, \$n\$ is one-indexed. So, the `n=1` Fibonacci number is 1, the `n=2` Fibonacci number is also 1, `n=3` gives 2, and so on.
* For deciding whether n is in the sequence (A2), you may use any two consistent outputs [decision-problem](/questions/tagged/decision-problem "show questions tagged 'decision-problem'")-style.
* You may assume that each sequence has an infinite number of terms meeting each condition C, and not worry about what happens with machine overflows and the like.
* For C2, digits in sorted order can have "ties", such as `377`.
**Test cases**
Here are all outputs for every combination with `n=10`, as `(A,B,C), n: result`. For these, we use one-indexed selections, and for A2 we use `1/0` for `True/False` 
```
(1, 1, 1), 10: 165580141
(1, 1, 2), 10: 89
(1, 1, 3), 10: 987
(1, 2, 1), 10: 1431
(1, 2, 2), 10: 78
(1, 2, 3), 10: 276
(1, 3, 1), 10: 222
(1, 3, 2), 10: 36
(1, 3, 3), 10: 42
(2, 1, 1), 10: 0
(2, 1, 2), 10: 0
(2, 1, 3), 10: 0
(2, 2, 1), 10: 0
(2, 2, 2), 10: 0
(2, 2, 3), 10: 0
(2, 3, 1), 10: 0
(2, 3, 2), 10: 0
(2, 3, 3), 10: 0
(3, 1, 1), 10: 55
(3, 1, 2), 10: 13
(3, 1, 3), 10: 34
(3, 2, 1), 10: 55
(3, 2, 2), 10: 15
(3, 2, 3), 10: 28
(3, 3, 1), 10: 33
(3, 3, 2), 10: 12
(3, 3, 3), 10: 24
```
The first 10 outputs, `n=1` to `n=10`, for each challenge combination are:
```
(1, 1, 1): 1, 1, 2, 3, 5, 8, 55, 17711, 63245986, 165580141,
(1, 1, 2): 1, 1, 2, 3, 5, 8, 13, 34, 55, 89,
(1, 1, 3): 2, 3, 5, 8, 34, 55, 89, 233, 377, 987,
(1, 2, 1): 1, 3, 6, 55, 66, 171, 595, 666, 1081, 1431,
(1, 2, 2): 1, 3, 6, 15, 28, 36, 45, 55, 66, 78,
(1, 2, 3): 3, 6, 28, 36, 45, 55, 66, 78, 253, 276,
(1, 3, 1): 3, 6, 9, 33, 66, 99, 111, 141, 171, 222,
(1, 3, 2): 3, 6, 9, 12, 15, 18, 24, 27, 33, 36,
(1, 3, 3): 3, 6, 9, 24, 27, 30, 33, 36, 39, 42,
(2, 1, 1): 1, 1, 1, 0, 1, 0, 0, 1, 0, 0,
(2, 1, 2): 1, 1, 1, 0, 1, 0, 0, 1, 0, 0,
(2, 1, 3): 0, 1, 1, 0, 1, 0, 0, 1, 0, 0,
(2, 2, 1): 1, 0, 1, 0, 0, 1, 0, 0, 0, 0,
(2, 2, 2): 1, 0, 1, 0, 0, 1, 0, 0, 0, 0,
(2, 2, 3): 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
(2, 3, 1): 0, 0, 1, 0, 0, 1, 0, 0, 1, 0,
(2, 3, 2): 0, 0, 1, 0, 0, 1, 0, 0, 1, 0,
(2, 3, 3): 0, 0, 1, 0, 0, 1, 0, 0, 1, 0,
(3, 1, 1): 2, 3, 5, 5, 8, 8, 8, 55, 55, 55,
(3, 1, 2): 2, 3, 5, 5, 8, 8, 8, 13, 13, 13,
(3, 1, 3): 2, 3, 5, 5, 8, 8, 8, 34, 34, 34,
(3, 2, 1): 3, 3, 6, 6, 6, 55, 55, 55, 55, 55,
(3, 2, 2): 3, 3, 6, 6, 6, 15, 15, 15, 15, 15,
(3, 2, 3): 3, 3, 6, 6, 6, 28, 28, 28, 28, 28,
(3, 3, 1): 3, 3, 6, 6, 6, 9, 9, 9, 33, 33,
(3, 3, 2): 3, 3, 6, 6, 6, 9, 9, 9, 12, 12,
(3, 3, 3): 3, 3, 6, 6, 6, 9, 9, 9, 24, 24,
```
  
[Answer]
# JavaScript (ES6), ~~158 ... 145~~ 144 bytes
Takes input as `(a,b,c,n)`, with \$a\$, \$b\$ and \$c\$ 0-indexed.
```
(a,b,c,n)=>(g=x=>[(d=[...x+''],i+=C=![d[0]-x%10,d+''>d.sort(),/1/.test(x)][c])>n,x>=n,x>n&C][a]?a-1?x:C&x==n:g([y,x+y,x+3][b],y+=b||x))(i=0,y=1)
```
[Try it online!](https://tio.run/##bZDdasMwDIXv@xTaxVqbKG6y7rdD7kXYUxhfOM7PMjq7JGE4rH32LGkZG2wXOgf0SUegN/NhOts2hz52vijHikZmMEeLjpNkNQWSihWkhBAhWq00NhFldKUKleg4XKcJFlNbFqLzbc84rtO16MuuZ4FrZTWXDoOkWdwy08ronYnTXdhmy0DktjVTA4Zoro1WucYhovx4DJyzhhIcKOXj80IlCCnCjRaVb1@MfWUGSMLnAuAvyr/Rf9D@QADrXef3pdj7egqM5tH8YvZial5G2CDcItwh3CM8IDwiPE25iRbv5sDcnFhNT4N82kNwnPNz/mm2s/y@wxcnPn4B "JavaScript (Node.js) – Try It Online")
### Commented
```
(a, b, c, n) => (              // given the challenge parameters ...
  g = x =>                     // g is a recursive function taking the current value x
    [                          // this is the array for A
      (                        //   a = 0:
        d = [...x + ''],       //     d[] = array of digits in x
        i += C =               //     increment i if C is true
          ![                   //     set C if the condition is false:
            d[0] - x % 10,     //       c = 0: the 1st and the last digits are not equal
            d + '' > d.sort(), //       c = 1: the digits are not in sorted order
            /1/.test(x)        //       c = 2: there's a '1' in x
          ][c]                 //     pick the relevant condition for C
      ) > n,                   //     exit if i is greater than n
      x >= n,                  //   a = 1: exit if x is greater than or equal to n
      x > n & C                //   a = 2: exit if x is greater than n and C is true
    ][a]                       // pick the relevant condition for A
    ?                          // if we're done:
      a - 1 ? x                //   if a is not equal to 1, return x
            : C & x == n       //   otherwise, test whether C is true and x is equal to n
    :                          // else:
      g(                       //   do a recursive call:
        [                      //     update x:
          y,                   //       b = 0: x = y (Fibonacci)
          x + y,               //       b = 1: x += y (triangular numbers)
          x + 3                //       b = 2: x += 3 (multiples of 3)
        ][b],                  //     pick the relevant update for B
        y += b || x            //     if b = 0, add x to y (for Fibonacci)
                               //     otherwise, add b to y (we actually just need to
                               //     add 1 for triangular numbers; for multiples of 3,
                               //     y is ignored anyway)
      )                        //   end of recursive call
)(i = 0, y = 1)                // initial call to g with x = i = 0 and y = 1
```
[Answer]
# [Python 3](https://docs.python.org/3/), ~~426~~ \$\cdots\$ ~~204~~ 181 bytes
Saved 9 bytes thanks to [RGS](https://codegolf.stackexchange.com/users/75323/rgs)!!! 
```
def f(a,b,c,n):
 j=i=l=x=0;y=1
 while(i<n,l<n,l<=n)[a]:
  j+=1;x,y=y,x+y;p=(x,j*-~j//2,3*j)[b];s=str(p)
  if(s[0]==s[-1],[*s]==sorted(s),not'1'in s)[c]:l=p;i+=1
 return(l,l==n)[a%2]
```
[Try it online!](https://tio.run/##XZDdaoQwEEbv9ykGoZjoLLtZ77TzJMELf2I3EqIkliqyfXVrXNiWXiSEw3cyXzIu032w2ba1qoOOVVhjg5bnJ@hJk6GZrsVC4gRfd20U0@8WzbHIclmVew76lEQx40ILzulSjMRm7JPzd3@53DBLei7rsvDkJ8dGvud1x7y8lkRenkWJMvHhPLhJtcxztMMUi1hb8Fw2ZW5oLHQaGjg1fTrLDBo6hr/dyq0bHBydYRfYsz4/YACush@KZQeo/4PmLwgPHp22E@sitlYPhLUOW/PgOUSobEtxvJcPov0VBYIQwX3Ja/hDqBEaBMv3KyKEl/0M8e0H "Python 3 – Try It Online")
\$(a,b,c)\$ are zero-indexed and *...whether \$n\$ is a...* returns `True`/`False`.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 245 bytes
**Input {a,b,c,n}**  
True/False for A(2)
```
(d=#4;a=#;c=#3;n={#&@@(i=IntegerDigits)@#==#~Mod~10&,OrderedQ@i@#&,i@#~FreeQ~1&};{t=v=1;While[v<=d,While[!n[[c]][#@t++]];v++];#[t-1],!FreeQ[#[w=Range[3d]],d]&&n[[c]]@d,#&@@Select[Select[#@w,#>d&],n[[c]]]}[[a]]&[{Fibonacci,#(#+1)/2&,3#&}[[#2]]])&
```
[Try it online!](https://tio.run/##LU7BSsNAFPwVy4MloSs2jbf1yR6k4EE0evDweId195EutFuIa3oIza/H2MjAzMDMwBxd3svR5ejd1OJUBIR74xCMR6hNwgGUtUXE55Slle4ptjF/lxYQYXw5hbHaKP3aBekkNDZaUHqmcdeJNGOlLmbI2GNlPvfxINQ/YNCLXSUiz0xg83rNbPqZDVC@rVivrnMCOuO7S61QHZh1YKWWkQ3679WHHMRn@hewZw2PQbFeSnwhcsyKhl38OiXnfdRQwLoq77ZK16DmHLZzr1TTWxdTts1PlGzbG6r0FRuepl8 "Wolfram Language (Mathematica) – Try It Online")
[Here](https://tio.run/##NdCxasMwEAbgvU@hRCASfKVRPToqGkqgQ2nTDh2OG2RJOILEAVckg4lf3ZUjV8PdD98diDuZePAnE4M147g7d2iYYhKYYVvFytSLAh4Ym6TOUs9SZ7mTzWRnsjPdzWVzk8lNCv/IGrVqVc@F1qug3troG9@9hibE37XmSvHh/ewGuRHw0TnfebfXQXMBqQy7zvv9IMWt6qO6KFn9HMLR42WrHOS4aBEtEXIdi4KouqRacYyPkmBxX0eOV/Vl2sZj6YjAkRB5STuYfvXtj95GnBvXV@AvThDkIbohGiKB/S7U59ZYG4CveCHXT88CSi6S12lsXX12oY3YG6jB3mDJlukIwJbpAik1NL1x/AM) are all test cases for n=1 to 10
[Answer]
# [R](https://www.r-project.org/), 199 bytes
```
f=function(A,B,C,n){u=c(sum(1:B),1+2*(B>2))
while(sum(v<-grepl(c("^(.)(.*\\1)?$","^1*2*3*4*5*6*7*8*9*$","^[^1]*$")[C],u))<n+2)u=c(u[1]+c(u[2],sum(u^0)+1,3)[B],u)
w=u[v]
c(w[3],n%in%w,min(w[w>n]))[A]}
```
[Try it online!](https://tio.run/##Tc7fasIwFAbw@z6FlAnnpJmYc9w/sQ7rY8T0ptgtoFE6Yy/Gnr1rO1YOCeRL8pFfmq7O@1nHUN38JcBOF3qvA37HvIKveAazLlCbjBQUW0JM2k9/Oo43983jR3O8nqCCtIQFwkIdDgbfH1KdlkaRYrVST@pZvahX9abGY1sa1ye0e6cj4iZkhIMUrXHZsJDTw9uxXGJmNKMthmLS5tHeXVJBa9npMPdh3uqzD/2@3QaHaHfup6vB6HEsMfnLJDJPmUSHRIdEh0WHRYenDgmLhEXCImGRsEhYJCwSFgmLhcXCYmGxsFhYLCwWFguLJyupLw34mQ8zs@7318aHG/x/3iN2vw "R – Try It Online")
Conditions C1-C3 are checked via regex. 
In all cases, it computes the first `n+2` terms verifying the condition; this is always enough. They are stored in reverse in `w`. Then:
* for A1, take `w[3]`
* for A2, check whether `n` appears in `w`
* for A3, take the min of the elements of `w` which are greater than `n`.
Details of the regexes:
* C1: `^(.)(.*\\1)?$`: get first digit with `^(.)`, then find either the end of the number (correspond to a 1-digit number) or any sequence followed by the same digit again
* C2: `^1*2*3*4*5*6*7*8*9*$`: any number of 1s, then any number of 2s, then... then any number of 9s
* C3: `^[^1]*$` only digits which are not 1
`w` is built as the elements of sequence `u` verifying the regex, where `u` is the Fibonacci/Triangular/multiples of 3 sequence, built iteratively by adding the appropriate increment at each step.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 58 bytes
```
ị"“ÆḞ“+1c2“×3”,“.ịEƊ“ṢƑ“ċ1¬$”,“ṖṪ“e@“>Ƈ”ż“¶1ÇD“Ɗ⁸+1¤#Ç”FvḢ
```
[Try it online!](https://tio.run/##y0rNyan8///h7m6lRw1zDrc93DEPSGsbJhuBuNONHzXM1QGy9IAKXI91AVkPdy46NhFIH@k2PLRGBSr9cOe0hztXARmpDkDC7lg7UPzoHiDz0DbDw@0uQAZQb@MObcNDS5QPgyTdyh7uWPT/4c591kA5BV07BaCY9eHljzauMzQAiqpwGT/cOd0YqLRpTeR/AA "Jelly – Try It Online")
A dyadic link taking the choices in the order `B, C, A` as the left argument and `n` as the right argument. Builds a program from component parts and then executes it. The presence of two ones at the start of the Fibonacci sequence added an extra four characters!
## Explanation
```
ị"          | Index into the following list of strings, zipped with the first argument (so the first choice picks from the first list of strings, the second from the second and the third from the third):
```
### First set of choices
```
“ÆḞ         | - Fibonacci sequence
“+1c2       | - Triangular numbers
“×3”,       | - Multiply by 3
```
### Second set of choices
```
“.ịEƊ       | - Extract last and first terms and check if equal
“ṢƑ         | - Check whether invariant when sorted
“ċ1¬$”,     | - Count 1s and then logical not
```
### Third set of choices
```
“ṖṪ         | - Remove last then take last remaining
“e@         | - Exists (with arguments reversed)
“>Ƈ”        | - Keep those greater than
```
### Fixed bits of generated program
```
ż           | Zip with strings representing the following
“¶1ÇD       | - Newline, then 1 followed by call of previous link followed by D convert to decimal digits
“Ɗ⁸+1¤#Ç”   | - Last three as a monad called to find n+1 matching terms
```
### Code to execute the generated program
```
F           | Flatten
 v          | Call as Jelly code using n as argument
  Ḣ         | Head (needed when A is 3)
```
### Example generated code for `[1,1,1]`:
```
ÆḞ
1ÇD.ịEƊƊ⁸+1¤#ÇṖṪ
```
[Answer]
# [Python 2](https://docs.python.org/2/), 162 bytes
Inputs A, B, C are 0-indexed.
```
a,b,c,n=input();
i=0;x=k=1
while[n,i<n,i<=n][a]|1-x:i,k=[k,k+i,i+3][b],k+(b or i);s=`i`;x=[s[0]==s[-1],sorted(s)==list(s),not'1'in s][c];n-=x>a
print[i,i==n][a%2]
```
[Try it online!](https://tio.run/##TY9Ba8MgFIDv/op3GWmpgfh2a/Z266677CZCk1SopJiglqWw/56ZhXQPFD/w4306PtJ18Dh3w8UCQVEUcyNb2UlPzo/3tNvXwlFVT9STEt9Xd7PaS/e2bPJGN@ZHldPRyZ50L/uDk@7wanRrMu9aGAK4fR3p7M55hI66MkRRl8rIOIRkL7u4J7q5mDJIP6RCFc5DNLoztS9pem/EGJxPOg@mv@ALmjk/U6yPga9wt0cBkMJjOQDsZDtYviMW7uyY4PT5cQphCKvQBtv0cyUhL5VXJVbGjdV6tbFi/HSQOcgc3Jx1SMVYMX46ijmKOYo5yBxkzrOFrIWshayFrIWshayFrIWshf@tXw "Python 2 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~49~~ 44 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
∞3*∞Åf∞ηO)³èʒ1å≠y¬Å¿yD{Q)Iè}D¹²i<èë²<i.ië›Ïн
```
Input is 1-based in the order \$n,A,B,C\$, and for A2 it'll output \$0\$/\$1\$ for truthy/falsey respectively.
-5 bytes thanks to *@Grimmy*.
[Try it online](https://tio.run/##AVoApf9vc2FiaWX//@KInjMq4oiew4Vm4oiezrdPKcKzw6jKkjHDpeKJoHnCrMOFwr95RHtRKUnDqH1EwrnCsmk8w6jDq8KyPGkuacOr4oC6w4/Qvf//MTAKMQoyCjM) or [verify all test cases](https://tio.run/##yy9OTMpM/W/sY3x4cVmIq19lUIKSo@3h/TpOIMIZROQBCYVHbZMUlOwrQ/3C/j/qmGesBSQOt6YByXPb/TUjDrcWH15xapLh4aWPOhdUHlpzuPXQ/kqX6kDNiHM7Dq@odYmMuLA30@bwisOrgQybTL3Mw6sfNew63H9h7//aWh3NmP8A).
**Explanation:**
```
∞           # Push an infinite list of positive integers: [1,2,3,...]
 3*         # Multiply each by 3
∞           # Push an infinite list of positive integers again
 Åf         # Get the (0-based) n'th Fibonacci of each
∞           # Push an infinite list of positive integers again
 η          # Get all prefixes
  O         # And sum each prefix
   )        # Wrap all infinite lists into a list
    ³è      # And index the third input (B) into it (0-based and with wraparound)
ʒ           # Filter this list by:
 1å         #  Check if the current value contains a 1
   ≠        #  And invert the boolean
 y          #  Push the current value again
  ¬         #  Push its head (without popping)
   Å¿       #  And check if the value ends with this head
 y          #  Push the current value again
  D{        #  Create a copy, and sort its digits
    Q       #  Check if both are equal
     )      #  Wrap all three checks into a list
      Iè    #  And index the next fourth input (C) into it (0-based and with wraparound)
}D          # After the filter: duplicate the resulting filtered infinite list
  ¹         # Push the first input (n)
   ²i       # If the second input (A) is exactly 1:
     <      #  Decrease `n` by 1 to make it 0-based
      è     #  And use it to index into the filtered infinite list
    ë²<i    # Else-if the second input (A) is 2:
        .i  #  Check if input `n` is in the filtered infinite list
    ë       # Else (second input (A) is 3):
     ›      #  Check for each value whether `n` is larger than it
      Ï     #  Only keep the values at the truthy indices
            #  (hence the duplicate after the filter)
       н    #  And only keep its first value
            # (after which the result is output implicitly)
```
[Answer]
# [Python 3](https://docs.python.org/3/), ~~182~~ 173 bytes
```
def f(a,b,c,n):
 u=i=l=0;v=b&2|1
 while(i<n,l<n,l<=n)[a]:
  u,v=v,[u+v,2*v-u+1,v+3][b];s=str(u)
  if(s[0]==s[-1],[*s]==sorted(s),not'1'in s)[c]:l=u;i+=1
 return(l,l==n)[a%2]
```
[Try it online!](https://tio.run/##XZBda8MgFIbv@ysOhS3anEJN7pKeXyJexHysQjBFo2Nk/e1ZTKEbu1Dk4X08r96/5ttky3Xt@gEG1qDGFi2vDhDI0EiXOpJ@L77FAT5vZuyZuVoc90WWy0ZtSQgYKaIMecTiFM8hFxjzUkmtak9@dizwLWUG5uVFEXl5Fgrlyafz5Oa@Y56jneZMZMaC57JV1UihNjltc10/B2fZiCPtI98KtQ6Tg70rbAJ71uY7TMA19qNn5Q70f9D@Bemhd2fszIYjW5oHwqLT1j54BUfsbUdZtpVPov0VBYIQyX3JS/o70AgtguXbFUeEl/0M8XX9AQ "Python 3 – Try It Online")
The skeleton was borrowed from Noodle9's Python answer, but I'm building the sequence of values in a different way.
Thanks to @xnor for saving me 9 bytes.
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + GNU utilities, 277 bytes
```
b=(d*5*d4+dvd*-r4-dvd*-* 8*1+dvd*- d3/3*-)
c=('^(.)(.*\1)?$' ^`seq -s* 9`*$ -v\ 1)
f()(egrep -q ${c[$3]}<<<$5&&dc<<<"$5 ${b[$2]}d/p"||echo 1)
case $1 in
0)for((n=1;k<$4;n++,k+=!`f $* $n`+($n$2$3<102))){ :;};$[--n];;1)n=`f $* $4`;;2)for((n=$4+1;`f $* $n`;n++)){ :;}
esac
echo $n
```
[Try it online!](https://tio.run/##bVHbUsIwFHzvV6zMGXMpaUkpjppWx8tfAE6hCeo4Ey5leIF@O5aKIqPnISfZze5kT6aT6m0/m6/wgHePbS@KktrYeQDggD7@QY/E039EU658m0N5dOgB9Ah6Qn6Hzok/aJ9brY6iq9rgt7ipyq3xI6XnM44H@2nOrRxIm4Z2Y6VapartEtdSf0Gw/bgvlQjKnLMXHgkeyZEW98TwUlRuCVVJ3BSSoDYjaBHMuODudeUWUEvQthxSf1xnWUaDy0tbNpsODRp8OqRkXNt40dnt2pCNtJxUDqSbOEFPNMk497k2Hxmlxodh9yPML4oZSIJ8EXLylFA/071ECLHFrakNDZXyY2O08PnxZloYk3ybURpq82NxMD0qA1dNyqB9B/n9aUQCO6xXYCPPwLqsOVXOglVxN@4ifmWnedq5d@ffFpwTbT8sv0xAccz2nw "Bash – Try It Online")
Input is passed in the arguments, in the order A B C n. The values A, B, and C are 0-based.
Output is on stdout. For A=1, the output is 0 for truthy and 1 for falsey.
There is lots of spurious output on stderr, which is allowed under standard golfing rules, but if you want to try it out yourself, I recommend a command like:
`madlibs 0 2 1 5 2>/dev/null`
so that your output doesn't have stderr output included in it.
---
The TIO link shows all 27 combinations of A, B, and C, and all values of n from 1 to 6. (TIO times out if I use larger values for n, but I've tested more on my own computer.)
By the way, this script requires GNU utilities. In particular, it won't work on OS X (and probably other BSD systems), because `seq` is different there.
---
Some comments on the code:
`b` is an array of three dc scripts for testing whether a number is a Fibonacci number, a triangular number, or a multiple of 3, respectively. (Each dc script outputs 0 for true and 1 for false.)
`c` is an array of three regexes which match an input which starts and ends with the same digit, or is in sorted order, or doesn't have any 1s, respectively. The regex for being in sorted order is computed using `seq`, not given explicitly, because the code is shorter that way.
`f` is a function that tests to see if input $5 satisfies the requirements with B=$2 and C=$3. It prints 0 for true, and 1 for false. (This works by calling the appropriate dc script from `b` and matching against the appropriate regex from `c`.)
The case statement computes the desired answer by calling `f` as needed to test whether the appropriate numbers have the required properties.
]