[Question]
  [
A tower is made out of layers, each one being one unit shorter than the one below it. Every layer is completely on top of the previous layer. For example, here is a tower along with it's height map:
```
  #
 ##
 ###
 ####
#####
14532
```
Because the lengths of the layers are the integers from 1 to n, and because the layers are completely on top of each other, the height map will always be a permutation of the integers from `1` to `n`. (Can you see why? Comment below)
The converse is not true. Some permutations are not the height map of a tower, meaning they are not *tower permutations*. For example, `[2,1,3,5,4]` is not the height map of any tower, meaning that it's not a tower permutation. However, `[1,4,5,3,2]` is a tower permutation, as you can see from the previous ascii drawing.
Just to be clear, the following is **not** a tower:
```
   #
   ##
  ###
# ###
#####
21354
```
Because each layer has to be continuous. This is instead a castle :P
Your task is to take a permutation of the integers 1 to n (inclusive) and decide if it's a tower permutation, as per usual [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") and [decision-problem](/questions/tagged/decision-problem "show questions tagged 'decision-problem'") rules. You can assume that `n>0`
# Test cases (all permutations up to n=4)
```
[1] -> True
[1, 2] -> True
[2, 1] -> True
[1, 2, 3] -> True
[1, 3, 2] -> True
[2, 1, 3] -> False
[2, 3, 1] -> True
[3, 1, 2] -> False
[3, 2, 1] -> True
[1, 2, 3, 4] -> True
[1, 2, 4, 3] -> True
[1, 3, 2, 4] -> False
[1, 3, 4, 2] -> True
[1, 4, 2, 3] -> False
[1, 4, 3, 2] -> True
[2, 1, 3, 4] -> False
[2, 1, 4, 3] -> False
[2, 3, 1, 4] -> False
[2, 3, 4, 1] -> True
[2, 4, 1, 3] -> False
[2, 4, 3, 1] -> True
[3, 1, 2, 4] -> False
[3, 1, 4, 2] -> False
[3, 2, 1, 4] -> False
[3, 2, 4, 1] -> False
[3, 4, 1, 2] -> False
[3, 4, 2, 1] -> True
[4, 1, 2, 3] -> False
[4, 1, 3, 2] -> False
[4, 2, 1, 3] -> False
[4, 2, 3, 1] -> False
[4, 3, 1, 2] -> False
[4, 3, 2, 1] -> True
```
  
[Answer]
# [Python](https://docs.python.org/3.8/), 46 bytes
```
f=lambda l:len(l)<3or min(l[:3])<l[1]*f(l[1:])
```
[Try it online!](https://tio.run/##dZJBboMwEEX3nGJ2wZVTyXgWFQpd9gTdIRZGdRqkCUHGadXTUwdjFYy7m3n@fH/PMPzYy62XL4OZpnNF6tp@KKCSdJ8TO8mbgWvnyrqUDTtRLZqns@tE2bDp@9KRBlFmoHhbdf1wtzl7HgfqbH6A4yscWAZU6S9FuXKlVeZTW6hgJq0jRo@udYauHkzX23wm1SLlQPyh4UvPJnf/w/jd3HVWCw7Fqi04xKcc5JbI/SdB86Zo9EhujeQsKtYiOXsnbuOAO4jJFEG5OHqK23jCkyihp@mXRK6eYvqJe61PILa2mJwR/jemyFWGBKn57bXFKsEfxeQGcLcEDBE2aTGMpohoYvsY1igimvgJMCxyFeEX "Python 3.8 (pre-release) – Try It Online")
Uses the characterization
> 
> A tower permutation is one where no element is smaller than both its neighbors.
> 
> 
> 
---
## [Python 2](https://docs.python.org/2/), 36 bytes
```
lambda l:'-1, 1'in`map(cmp,l[1:],l)`
```
[Try it online!](https://tio.run/##dZLBboQgEIbv@xRzExO2CTAnE3vcJ@jNbrrYsl0TtETZbvr0FlFSRXobPn7/@ZnR/NjbV8fHa/k6atnWHxJ0kR0ZBZY13aWVhry3huqKFWeq88v4uDVaASsOIGld9vLx1nTmbkn@NBjdWJLB8Rmy/AC6VN9SE@lKK/tPZaEET2pHejW445VoV5u@6SwQj8pFm0/lSepBUdB0ktPlZqzYeWrx0t/VoXI5@erIXezoloLYErH/JGh8Q4/E1kh4EV@LhPdOdKOAO4jJFEG5OM4Ut/HYTKKEM02/JHKdKaafuNfOCdjWFpMzwv/GFLmKkCA1v72WrxL8UUxuAHdLwBBhkxbDaHhEE9vHsEYW0cRPgGGRqwi/ "Python 2 – Try It Online")
Really crams in the Python 2 nostalgia: `cmp`, backticks, `map` producing a list.
The idea is to use `cmp` to compare consecutive elements to detect an decrease (`-1`) followed by an increase `(+1)`. This is identified by the string representation containing the substring `-1, 1`, so that tower permutations give `False` and others give `True`.
---
## [Python 3](https://docs.python.org/3.8/) error code, 32 bytes
```
def f(a,*l):(a,)>l<l[1:]or f(*l)
```
[Try it online!](https://tio.run/##dZJBbsMgEEX3PsXsgitaCTOLyilZ9gTdWVmQljSWkIMwaZvTu9gY1cZ0hef58/nMYO7ucu34s7HD8KHOcCaSPuiy9kt50C@6YfXxaj32cPi@tFoBqwuQ9CTaztwcKZ96o1tHdvB4gF1ZgBbqS2oi/aeT9lM5EDCR00jsvZ689lb14lXqXhWgft6VcfVI3uzNA2PbzhFfgxCzCQVNwRM61@XQsON45LSjYRSqRVlRSP9S4GvCt1uiJuQaEV8b8UlULUV88s6cRgE3ELMponJ2DBTX8VggScJA8zdJXAPF/BW32pCArW0x2yP8r02JK48Jcv3baqtFgj@K2QngZggYI6zSYmxNldDM9DGOkSU08wgwDnIR4Rc "Python 3.8 (pre-release) – Try It Online")
A nifty short solution by loopy walt. Takes inputs splatted and outputs by erroring or not erroring, with successful termination indicating *not* a tower permutation.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jellylanguage), ~~5~~ 4 bytes
```
>ƝṢƑ
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6Fivsjs19uHPRsYlLipOSi9ccm3y4_eHOlkNLDA_thyhYcIuxLdpQR8FIR8FYR8EklgvKMQHy4RwoyxgsbAThmID5RnAZKAtEGcGUGkI4EKWGcBkQC2oWhAM1Cy5jBFcNomBMZBdCFJlAlBvCOVDz4TJGcA6UBfeLCdxjJjADjOGuNYTLGME5CJYxzCgjuG6o_41huo3gnjKEyyBYRvDAMYEFPJADiQ8A)
Explanation:
```
(implicit input)                     [1, 4, 5, 3, 2]
 Ɲ      for each neighouring pair:   [(1, 4), (4, 5), (5, 3), (3, 2)]
>       is left greater than right?  [0, 0, 1, 1]
   ṠƑ   is it the same after sorting?
(implicit output)
```
This tests if the list is increasing and then decreasing again.
[Answer]
# [Julia 1.0](http://julialang.org/), ~~26~~ 23 bytes
```
!v=issorted(diff(v).<0)
```
[Try it online!](https://tio.run/##hVLBbsMgDL3nK@iNSGgq2MflS6JoQguRqCJaAW2n/nyWxoEk3dpewM/v@WEDh3NvtfwZht2lsiEcfTQtb23X8Uv58bkvh2hC/PrWwYSqrmUjaimYGjclWEKCAUWwUJRTU@6ugymnKNrWCoYZ4MYrMzAxigCuj8THU6mGAG66yAy5SQK4bhYf@6UaSG6r/jOjshskN5XBPCkmN8hg7hqTG2QAuWa5NEwXIpumKLQLV@PHB4n@bMR/S6f78Dd8x1O4Xt8rnqhfScYJuqNnPAqmS2Ydu9kTX/6ZmMcri5O3LvaO7yKrqlFbGNcOvw "Julia 1.0 – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 33 bytes
Or **[R](https://www.r-project.org/)>=4.1, 26 bytes** by replacing the word `function` with a `\`.
```
function(v)is.unsorted(diff(v)<0)
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP0@jTDOzWK80rzi/qCQ1RSMlMy0NKGRjoPk/TSNZw1BTU1lB104hpKg0lQssoKNghC5mpKOAVZ2OgjEWYWMcJiBUuyXmFMPFjbEYbgxWboSh3BhsKS636CiYYJcxwe1QhB6wLf8B "R – Try It Online")
Outputs flipped `TRUE`/`FALSE`.
[Answer]
# [Shue](https://codegolf.stackexchange.com/questions/242897/golf-the-prime-numbers-in-shue), 100 99 bytes
```
=L
=R
,1,R=<,R
1<={
1{={1
,{=<,
L{=L
L1,=L>
>1=}
}1=1}
},=,>
>R=R
LR
,1,1=e
e1=e
1e=e
e,=e
,e=e
LeR
```
[Try it online!](https://tio.run/##lVXBjts2EL3rKwjlEHLNdUtbJyN0UTTepoCxDpRNe/C6BS3TuypkUqCkzS4cf0UPveTr8iObIWXZkiwHGx9kzfDNm@HjDJU@5fdaDZ/jTapNjoykKHvKPCMZ4mD1I71J40Ris/Qxnv/NF59vbzm5IJjXrV984nkruUaFklkkUoljMvIQ/IzMgWjp@86CRbB@du9rbVCEYoXiEml/8dpBhFrBErdxt7f@cXlP2NsvNPx1amcnp2T8DBf/cSp1riz1Mq5WtIgzif4USSEnxmiD1/57YTJpkLTmCN3pHEX3wogoB@c22iGxtm@gAmlyn9OtLITVwJns3MJTLjM8jxYlb7vaF1U6mU1/msyu2jVCgsIo@@eV3ZLayEOrAHYTK5Frk0GlmczxPqxIZNOTxMp54n6WJnGOnezk0FWJ7SqHOda9ce3M@huRR/c4IfWW2/TvjC5SPCQtQWzizxxt8aGtKygjhKIT75DM2WhByO47Ktd2aam7mHd1tWp4WlZUaicfZVTkEkcU1QWsQLDdUt2o3Gqh4gcJNvi3cZlgo1dg3ZhCOvPTPcy5ddZEc4grAZs4@JT89E@N7HgolfqZVb9CNPcOWrtVV@hov8HsR6LhPioUHPjr8DVBY8RGkVZ5rAp5Hjn9HtKmFHRpkzrZmhkrhHbrQt1JnEiFM9Jj5BRZZZ7rke5ZnCALO4yiG9oW03ZDNh/pRW/ZA449w2ixOxvdOsDWMde5vXOja/SdEZtqdpWGrksTEcmNVHmGhJEo1VkWL6EzYAig72CqVmgp78VDrAtD7L3vvUJ//Rpe/3H9O3o7u75BHz9M0NUsRLObd5MQfXj3cYJ@m72deJFeQV3wKfCf@dTjoUcZDfkbGnrsDd96bMu3zKNb8HjTLSCmjPLp2BszvvN2jDN4Uk7BEULs1IUzLj1pH0zaNwoPat@mMnyGPDCNl2zx0vq8w90BX8B@lq9i5U5OACW@2IgUyweR0GR/6fiXYx9uAdf8dtx8v/@vjhWeP174zO/51Ld8j5ZPlJepcWN5GFyQAz62fansGyYOkpoYmtb/@uX/r1/@8@cYQjhINg19wrlcUEFtWpqVf7BKnudsgS7HZRvMGUWDmjmgqL1K0bDpGZ6GVJhy8q1r2CQaOtCgDho67o5sFAUnzqCzigq5Zyy9QbM8VnpaFZbe7p20WEtv0L3FU2xZAWvSBp0aBedkarEOqwq69DvFDmoVHL1B5wkEJ4cQVCU0qg0qaQYtb8fpB9Uxspa3owmC6iCPJXwD "Python 3 – Try It Online")
Takes input as comma-separated list of unary numbers, with a trailing comma.
# Explanation
```
=L       - Implicit left edge
=R       - Implicit right edge
,1,R=<,R - Spawn a left triangle on the right, if last element is 1. Remove the last element
1<={     - Triangle decrements element, turns into left curly triangle
1{={1    - Curly triangle passes trough ones
,{=<,    - Curly triangle turns into a sharp triangle (to decrement next element)
L{=L     - After reaching the left edge, curly triangle dissapears
L1,=L>   - Same stuff but in the other direction
>1=}     - --||--
}1=1}    - --||--
},=,>    - --||--
>R=R     - --||--
LR       - If everything has been reduced, output true
,1,1=e   - Or if there is a one not located near the edges, create an error
e1=e     - Errors propagate
1e=e     - --||--
e,=e     - --||--
,e=e     - --||--
LeR      - Final error state
```
[Try it online!](https://tio.run/##lVXBjts2EL3rKwjlEHLNdUtbJyN0UTTepoCxDpRNe/C6BS3TuypkUqCkzS4cf0UPveTr8iObIWXZkiwHGx9kzfDNm@HjDJU@5fdaDZ/jTapNjoykKHvKPCMZ4mD1I71J40Ris/Qxnv/NF59vbzm5IJjXrV984nkruUaFklkkUoljMvIQ/IzMgWjp@86CRbB@du9rbVCEYoXiEml/8dpBhFrBErdxt7f@cXlP2NsvNPx1amcnp2T8DBf/cSp1riz1Mq5WtIgzif4USSEnxmiD1/57YTJpkLTmCN3pHEX3wogoB@c22iGxtm@gAmlyn9OtLITVwJns3MJTLjM8jxYlb7vaF1U6mU1/msyu2jVCgsIo@@eV3ZLayEOrAHYTK5Frk0GlmczxPqxIZNOTxMp54n6WJnGOnezk0FWJ7SqHOda9ce3M@huRR/c4IfWW2/TvjC5SPCQtQWzizxxt8aGtKygjhKIT75DM2WhByO47Ktd2aam7mHd1tWp4WlZUaicfZVTkEkcU1QWsQLDdUt2o3Gqh4gcJNvi3cZlgo1dg3ZhCOvPTPcy5ddZEc4grAZs4@JT89E@N7HgolfqZVb9CNPcOWrtVV@hov8HsR6LhPioUHPjr8DVBY8RGkVZ5rAp5Hjn9HtKmFHRpkzrZmhkrhHbrQt1JnEiFM9Jj5BRZZZ7rke5ZnCALO4yiG9oW03ZDNh/pRW/ZA449w2ixOxvdOsDWMde5vXOja/SdEZtqdpWGrksTEcmNVHmGhJEo1VkWL6EzYAig72CqVmgp78VDrAtD7L3vvUJ//Rpe/3H9O3o7u75BHz9M0NUsRLObd5MQfXj3cYJ@m72deJFeQV3wKfCf@dTjoUcZDfkbGnrsDd96bMu3zKNb8HjTLSCmjPLp2BszvvN2jDN4Uk7BEULsFKIgnnHpSftg0r5ReFD7NpXhMySCcbxki5cW6B0uD/gE9rN8FSt3dAIo8cVGpFg@iIQm@1vHvxz7cA247rfz5vv9f3Ws8Pzxwmd@z6e@5Xu0fKK8TY2by8Pkgh7wte1LZd8wcZDUxNC1/tcv/3/98p8/xxDCQbNp6BPO5YIKatPSrPyDVfI8Zwt0OS77YM4oGtTMAUXtVYqGTc/wNKTClKNvXcMm0dCBBnXQ0HF3ZKMoOHEGnVVUyD1j6Q2a5bHS06qw9HbvpMVaeoPuLZ5iywpYkzbo1Cg4J1OLdVhV0KXfKXZQq@DoDTpPIDg5hKAqoVFtUEkzaHk7Tj@ojpG1vB1NEFQHeSzhGw "Python 3 – Try It Online")
# [Python 3](https://docs.python.org/3/) algorithmic equivalent
```
def f(arr):
 if arr==[]:return True
 if 1 in arr[1:-1]:return False
 if arr[0]==1:return f([e-1 for e in arr[1:]])
 if arr[-1]==1:return f([e-1 for e in arr[:-1]])
```
[Try it online!](https://tio.run/##K6gsycjPM/7/PyU1TSFNI7GoSNOKSyEzTQHIsrWNjrUqSi0pLcpTCCkqTQWLGypk5oEkow2tdA3h0m6JOcWpMH3RBrG2toYwqTSN6FRdQ4W0/CKFVITe2FhNuHKgOQTUg6yK1fxfUJSZV6IBVGCkY6hjrGOiYxqrqfkfAA "Python 3 – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~8~~ 6 bytes
```
sṪ⌋∈₁Ṫ
```
Outputs false for a tower permutation, true for a non-tower permutation. [Try it online!](https://tio.run/##SypKTM6ozMlPN/r/v/jhzlWPerofdXQ8amoEsv//jzbUMdYx1THRMYoFAA "Brachylog – Try It Online")
### Explanation
Uses the "does it have a local minimum" test from [xnor's answer](https://codegolf.stackexchange.com/a/243180/16766).
```
s       For some consecutive sublist of the input
 Ṫ      which has three elements,
  ⌋     its minimum
   ∈₁   occurs at index 1 (i.e. the middle element)
     Ṫ  in that sublist
```
[Answer]
# Haskell + [hgl](https://gitlab.com/WheatWizard/haskell-golfing-library), ~~16~~ ~~13~~ 9 bytes
```
mnI<pa lt
```
Returns `True` when it is a tower permutation and `False` when it is not.
The following also works for the same score:
```
mnI<pa cp
```
## Explanation
We want to look for an element which is smaller than both of it's neighbors.
To do this we start with `pa lt`. `pa` takes a function and applies it to all consecutive neighbors, `lt` returns `True` if the first argument is less than the second and `False` otherwise.
```
[1,2,3,5,9,8,7,6,4]
 [T,T,T,T,B,B,B,B]
[1,2,9,5,3,8,7,6,4]
 [T,T,B,N,T,B,B,B]
```
If we started with a tower permutation this result is some number of `T`s follower by some number of `B`s. If it was not there is a `[B,T]` sub-sequence. This means that we just have to check if the result is monotonically increasing. If it is then it was a tower permutation, if it is not then it wasn't. `mnI` is the function to check if a list is monotonically increasing.
## Reflection
While working on this I found a bug and some documentation errors. None of this actually effects the answer, but I've fixed them.
[Answer]
# [J](http://jsoftware.com/), 19 14 12 bytes
```
-:]/:2>/\0&,
```
[Try it online!](https://tio.run/##dVIxDsIwDNx5hcVAheS2ie0pUlmQmJiYYUJUiIX/T6FqaeQ6yRApuZzts32fuO@aEYYADSA4CNNpOzjfrpfYhkcf6NTf3QHjcfd6vr8wAga/XD0M09MjkH4TQvaPwAbiFOVSlGHRzPKaxZiVY6xVRJAclVTEaSk5l2cuGa4Um5FqPymvRq2Gf6NGA60avOFKcVRSnZbRwKsGMihpDRqVPK8UFyF6FwtXcGsAjdqZCW5toFHO8xbMIJj8EH8 "J – Try It Online")
-5 after realizing from pxeger's answer that I could use sort by instead of group by
another -2 stealing pxeger's idea to use `>` instead of `*@|`
The key insight is that the deltas of successive elements in a tower permutation have at most one "peak":
* `/:` Sort by...
* `2>\0&,` Is left greater than right (pairs of 2
* `-:` Does that equal the original input?
[Answer]
# [Python](https://www.python.org), 49 bytes
```
lambda x:sorted(a:=[*map(int.__gt__,x,x[1:])])==a
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TZFBasMwFETpNqfQIgupqAF9aVEMPolrjErsxuA4JlUa9wQ9RDaBkN6pPU3t6GvSleZ55g_68ul7-AybXX--NPnL9RCap-cf0_nt69qLMXvf7UO9lj7Li8etH2Tbh1VVvYWq0qMeC5OVqlR57nlwedy0XS2meNsPhyBVNuynEel1I-sP30mvlIrZ8-_DV2G0IC2sFq5cMLiJAazs7TNFcDcmOKzmg1LURIhRA2dW3BWBu-AQ0vOR5P8bxpCLcQPgfjgEYIVdHBZzqcDitgYOAe7KpirCNO9v0zRhKQPnrgiP49LDT7CIP-QP)
Port of my Jelly answer. (Writing this is what inspired the -1 byte golf there)
[Answer]
# [Husk](https://github.com/barbuz/Husk), 5 bytes
```
V<Ẋ-…
```
[Try it online!](https://tio.run/##TU@xDcMwDHtIGeRo7B1ZjOwBgk5B9zZjD@kR/aZ5RJEZuvYiySRF0ctjW/1@7C@fbr/vezieH3fPWWfJKilqEs4yoo8VxTtQ8FGBB9v0Ypys7RILDnotnaz13tCVydodYmVXMdk/hfU5oIO@ZSKWuAsPssbMQOAHX7DgiNW/4hbZ67/zCQ "Husk – Try It Online")
Outputs zero for towers, non-zero for non-towers.
```
    …   # Fill gaps with numeric ranges
  Ẋ-    # Pairwise differences
V       # Index of first element that is 
 <      # less than the next one
        # (or zero if not found)
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 35 bytes
```
f=->l{l==l.sort||l.pop<l[-1]&&f[l]}
```
[Try it online!](https://tio.run/##Dcu9CoAgFAbQV2lyCLzg0Ja9iDhUKARfKv4MpT27uZ8Ty/H0biXfUCElKPmYWwMFH1YoLjRjVkF/PUxqFkSLpmDiXfKeL@8oGZgz14Zm1Tv6Ce/M0D8 "Ruby – Try It Online")
[Answer]
# [Java (JDK)](http://jdk.java.net/), 76 bytes
```
h->{int d=1,i=1;for(;i<h.length-1;)d&=h[i-1]>h[i]&h[i]<h[++i]?0:1;return d;}
```
[Try it online!](https://tio.run/##VVBNa@MwEL33VzwCKTZNRNW6X3acpZeFPSw9dG/BBzW2Y2Ud20hyIJT8du1oktDtQTN@b968eXir9mq@Lf/6dausxW@lO3xeAcP40eo1rFOO2r7XJXY0i96d0d1mVUCZjY1ZCmzJRIxOt6Ieu7XTfSf@9L869/OMFrpzq2KJGrlv5stPgihzOdO5zOreRJleNKKtuo1r5jKLy@u8Wem5LJbUiutQFs3q5kYXP25TmZnKjaZDmR19xufJAtFemZAJ6bdkwIk36oD8v5yvgbHCOlOpXUQbwg6tdtEEkzgWOzVw/ohetalMmu5VO1ZvdSxcz6tRnJ393w/WVTvRj04M9GtcHU2mNsXUTrvJLGSZoRZqGNrDqw2WnCVGnkOePY5X4R29l17izt@BO@6p3p8wfRMmnh4xxF40SLgnFzVjYkklQ2U@@fKheejJxZFx0EsfXE6Xkq9bNGfV5SpjVnreYj7hPIxon12IZ5bxKTu7Mv8tPx7wiCc84wXyFpLqM@QT5CPkAySZ0RbJ5T8 "Java (JDK) – Try It Online")
Returns `1` if it's a tower, `0` if it's a castle.
[Answer]
# [Quipu](https://github.com/cgccuser/quipu), ~~64~~ ~~58~~ 46 bytes
```
3&2&1&4&\/0&
[][]  []  ??
4&3&
[]==
--::
2&
>>
```
Takes input from stdin, one number per line. Outputs by throwing an error for tower permutations and exiting silently for non-tower permutations. [Attempt This Online!](https://ato.pxeger.com/run?1=m720sDSzoHTBgqWlJWm6Fjf1jNWM1AzVTNRi9A3UuKJjo2MVFEDY3p7LRM0YJGJry6Wra2XFZaTGZWcH0QXVvGClIZcRlzGXKZcJRAAA)
### Explanation
Programs in Quipu consist of *threads*, which are two-character-wide columns. This program has six threads, numbered 0 through 5:
```
"0  1  2  3  4  5"
3& 2& 1& 4& \/ 0&
[] []    []    ??
4& 3&
[] ==
-- ::
2&
>>
```
Threads 3 and 4 hold two consecutive numbers in the list. (Initially, they're both 0.) Execution proceeds as follows:
* Thread 0 takes the value of thread 3 minus the value of thread 4 and tests whether the difference is positive, i.e. whether the numbers are in descending order. If they are, jump to thread 2; otherwise, continue to thread 1.
* Thread 1 tests if thread 2 is still 0. If so, it jumps to thread 3; if not, it exits the program.
* Thread 2, if reached, sets its value to 1.
* Thread 3 sets its value equal to the value of thread 4.
* Thread 4 reads and stores a number from stdin.
* Thread 5 jumps back to thread 0.
The end result is that any descending pair sets thread 2's value to 1, and any subsequent ascending pair ends the program. If this descending-ascending pattern never occurs, the program continues until it runs out of input and errors.
[Answer]
# [Behaviour](https://github.com/FabricioLince/BehaviourExolang), 52 bytes
```
t=&(i=1\~([a%i>a%(i+1)a%i>a%(i-1)]i+=1i<#a-1)i>#a-2)
```
I don't exactly know the rules regarding recently self-made esolangs, but here goes nothing.
Ungolfed and commented:
```
t = &(
    i=1 // start on the index 1
    // repeat the following sequence until failure
    \~( 
      // either the ith member is bigger than the previous or bigger than the next
      [ 
        a%i > a%(i+1)
        a%i > a%(i-1)
      ]
      // increment index and check if it still is less than n-1
      i += 1
      i < #a-1
    )
    // is a tower if the index stopped incrementing on the last possible index (i.e. passed all the checks)
    i > #a-2
  )
```
Test with:
```
t:{1}
t:{1 2 3}
t:{3 1 2}
```
Bonus (bigger) answer using more obscure features of the language but basicaly the same logic:
```
t=&![#(t=a)<3(#a-2)*&(v=t%(a+1)v>t%a|v<t%(a+2));>&a|b]
```
[Answer]
# Curry, 24 bytes
*Tested to work in both [PAKCS](https://www.informatik.uni-kiel.de/%7Epakcs/) and [KiCS2](https://www-ps.informatik.uni-kiel.de/kics2/)*
```
f(_++a:b:c:_)|b<a&&b<c=1
```
[Try it online!](https://tio.run/##Sy4tKqrULUjMTi7@/z9NI15bO9EqySrZKl6zJskmUU0tySbZ1vB/bmJmnoKVlUJAUWpOaUqqnqe/goYmF1jUVqGgKDOvREFFIU0h2ljHRMdQxyj2PwA "Curry (PAKCS) – Try It Online")
Checks if any value is smaller than both of its neighbors using Curry's powerful pattern matches. Returns a `1` if it isn't a tower permutation and nothing otherwise.
TIO has a limited ability to test things like this. Paste the following to [smap](https://smap.informatik.uni-kiel.de/smap.cgi?new/curry) and run in `PAKCS 2.2.0` for better testing abilities:
```
import Control.SetFunctions
f(_++a:b:c:_)|b<a&&b<c=1
-- Helper to run tests
helper :: [Int] -> Bool
helper a = isEmpty $ set0 $ f a
main =
  [ helper [1,2,3]
  , helper [3,2,1]
  , helper [3,1,2]
  , helper [4, 1, 2, 3]
  ]
```
This test handler will not work in KiCS2 or at least not on the version used by smap. But the function itself does if you want to manually test it.
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, 39 bytes
```
[ 3 clump [ dup infimum second= ] ∃ ]
```
[Try it online!](https://tio.run/##fVO7TsQwEOzzFcsHECnxViAoQTQ0QHW6wnJ8h0XsGD8k0OkqGr6THwkhEjlb502qZGZ3PZ6d7LgIgxtfnh4e769g74ZoldkvL7X8CI57eJPOyB68fI/SCOn/cT@48FeveXg9sfNnHY0SQyfBOhnCp3XKBLiuqkMF03OABo5wAZe38OyiXLC2gLZkLSvijJyy1N/x3p8IVjyApXLSBraqCAkGV9Ri6ZhmHtYWmzC9fN6Eq/fHsgNNKu/cHKQoLBrRzjgxD1ftxrLhTerE@S6QohJ9OYX0cpFYL@aRS5swT11OkcHDPHo5RaYPC/k7jpsJFX3UFjbQRQvK7JSOevonxWC6G9jCz/cXbEfNLdTjLw "Factor – Try It Online")
## Explanation
Returns `f` for true and `t` for false.
*"Is there an element that is smaller than both its neighbors?"*
Thanks to @xnor's [answer](https://codegolf.stackexchange.com/a/243180/97916) for the characterization. The shortest I could get the 'sorted signs of differences' method was 44 bytes.
```
             ! { 2 1 3 5 4 }
3 clump      ! { { 2 1 3 } { 1 3 5 } { 3 5 4 } }
[ ... ] ∃    !          (is there any element that...)
             ! { 2 1 3 }
dup          ! { 2 1 3 } { 2 1 3 }
infimum      ! { 2 1 3 } 1
second=      ! t
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 17 bytes
```
\d+
$*
(1+),\1,\1
```
[Try it online!](https://tio.run/##RY5BDoMwDATvfkeRoPhi8B/6CQ5Uag@9cED8P91MFCElcXa8Wef8Xr/jXYbxtZftM9vjaWPMk2@hVUpY@GKLU33VuTatu7S4toho93hSs7vRonJFPeF556hfa/ZEdPWH1ZQ2Ke9Z6uPqU9E4jVfw5D8ovSdFHIpufycVTtIf "Retina 0.8.2 – Try It Online") Link includes test cases. Outputs `0` for a tower permutation, nonzero if not. Explanation: Uses @xnor's observation that each number in a tower permutation is greater than at least one of its neighbours. After unary conversion, the regex simply has to find a run of `1`s where both neighbouring runs of `1`s are at least as long and therefore neither neighbour is lower.
A direct positive test takes a massive 39 bytes:
```
\d+
$*
^(^1+,|1+\1)*((1+),(?!\3))*(1+)$
```
[Try it online!](https://tio.run/##RY6xDsIwDER3/wVSkZzGixvvjPxEVIEEAwsDYuTfw@WiqEPi3PPl7M/z@3rf21mvt1YfWZZVdt09289z9bSqek6ml1MtCQpiac3FbZPNWK3gLkPjDQ2OAwI6PRasMd3UoHB5v8njyEG/15iJ1N3v0lPGpDhmoU/XnEpNp/AXeXAfKvxnCjgp9didqeRM@gM "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation: Looks for an ascending sequence followed by a descending sequence.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~93~~ \$\cdots\$ ~~59~~ 54 bytes
```
r;f(a,n)int*a;{for(r=0;n-->2;)r|=*a>*++a&*a<a[1];n=r;}
```
[Try it online!](https://tio.run/##dZZdb9owFIbv@ys8JCYCQc05Dl9N015M@xWUiyyEDnVLqwRpaF3/@piJncTnjYYoLn7s18ePEyCfP@f55VIlh0kWlsGxPE2z5P3wWk2qNErK@fyBk6D6k06zh@lsln2eZvfZlnZJmVbJx8UMVz@zYzkJ1PuNMo9rx6moT7TdqVS900fSdbHrChV7vdr2cqj8sXE/NlTaA4sOaJmz7HPkjFUHtFxjbYFuZvhRmw5AVRSJskIV@5B8GMsiiEXdMFP7MJbFUK8iHtighQ/BCEklsObKh1jtWjiDmRsfxtIQRx2MByfB5EM4DWZxHHJN1j4EQxyL84KZCx9itcsOxoOrgFc@hCuBnaG4rVbsc@NDOBUddXB4rWryIRjS3MHhNau1D2217Q05bUbUdkBzhKGt0zbaNrFtFrZZ2mZlm7VtNqG7DVzrcsgFkUsiF0Uui1wYuTRyceTy2OVxW5fLY5fHLo9dHrs8dnns8tjlaZenXZ5uN6p7J01HaZXUx9/F62HSlBTcundT@zZUHmVJWVItqZY0ljSWdCHpQtKlpEtJV5KuJF1LupZ0I@lGUopARwQcdYEvAmEExgiUETgjkEZgjUAbgTcCcQTmCNQRuCOQR2CPQB@BPwZ/DP4Y/DFeb3jBgT8Gfwz@GPwx@GPwx@CPwR@DPwZ/DP4Y/DH4Y/DH4E@DPw3@NPjT4E@DP413LN6yOvA@IYrzW5Gfin33Fes/I@912BO1z2FP9L8et3L@WtYnlX/Pqql5LfKXorIFjJ7OX/npvPli/hajUPnv9cjNNr/b1ORa/LHcF2czLUrcv/ftxttt9VvvehI1mzWjgybM/qLrv0RMnP0iacbsEh@r0tFyQPuaXD2mlrJZKujGXB9vlRl0mIzG9Xhv9nd8vG7ybrQ1zWl73AVyvdqEfTLHGKoSyJshdZpS9Bjd1T2ySgsDu4PFStsKdmr@oMZ7Na6fSrN6HXYnUaRp7Vdye3s8XDfXyE4VBepbVWQvdsDHzcflb374kT3Xl/mvfw "C (gcc) – Try It Online")
*Saved a whopping 24 bytes thanks to [Olivier Grégoire](https://codegolf.stackexchange.com/users/16236/olivier-gr%c3%a9goire)!!!*
Inputs a pointer to an array of a permutation of the integers from \$1\$ to \$n\$ and \$n\$ (because pointers in C carry no length info).  
Returns \$0\$ if it's a tower permutation or \$1\$ otherwise.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 37 bytes
```
a=>!a.some((x,i)=>x<a[i-1]&&x<a[i+1])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=dVS9TsMwEGZgIU9xDNS26kYk8YAaUiYYGAAJthCpVkkgUtpEcStFqngSlg4w8EjwNDhxrebHZPH5u-_On-98-fhc5S_x7nuRr8QaEgi-NutkcvFzxoPZKbdFvowxrmhKgll1ycN04kSjUWONnYgo8u_xkQovIIAteuBCoCmcU0A3PM1q8923FGPBRSwkax46EUxm8FRuYit0KLitrUuh76XgdRFvGKI5NzwTCvK6ibyG5LZJXpPbcBoFNgCZUYVm7jMqlHXlOQrpKVSo-Sa9rApl5isOuUqB003LjDVi_5Wpl9XTCkz1G3LdloIDyowdYIMmMC2ho5bp0rg91NB9ptvo9FDDI2C6kQcJc9-ymrdqiyJL1xg9rxCxl7zAFQQzqDRc8xFpecLbx_s7u-CliHEVnkeEQiXfurQgCAA9oYjYSV5e88UbxiGnUEYUUlKHbq2T_RjJMYQEc4nKmBKuQM0UTPcT5Vsgv5qcZ7Gd5a9YhowByYmTy0B3mEbEt06KsEii8di33kl9u1Y08Tvb5rRpk6uwa7vvr0Vof20TX_0Idju1_gE)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), ~~9~~ 7 bytes
```
2lvƒ>ÞṠ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIybHbGkj7DnuG5oCIsIiIsIls0LDIsMywxXSJd) or [Run all the test cases](https://vyxal.pythonanywhere.com/#WyJQIiwiQGY6MXwiLCIybHbGkj7DnuG5oCIsIjtcbsabQGY7O1rGm2AgPT4gYGo74oGLIiwiW1sxXSxbMSwyXSxbMiwxXSxbMSwyLDNdLFsxLDMsMl0sWzIsMywxXSxbMywyLDFdLFsxLDIsMyw0XSxbMSwyLDQsM10sWzEsMyw0LDJdLFsxLDQsMywyXSxbMiwzLDQsMV0sWzIsNCwzLDFdLFszLDQsMiwxXSxbNCwzLDIsMV0sWzMsMSwyXSxbMSwzLDIsNF0sWzEsNCwyLDNdLFsyLDEsMyw0XSxbMiwxLDQsM10sWzIsMywxLDRdLFsyLDQsMSwzXSxbMywxLDIsNF0sWzMsMSw0LDJdLFszLDIsMSw0XSxbMywyLDQsMV0sWzMsNCwxLDJdLFs0LDEsMiwzXSxbNCwxLDMsMl0sWzQsMiwxLDNdLFs0LDIsMywxXSxbNCwzLDEsMl1dIl0=)
*-2 bytes thanks to Aaroneous Miller*
[Answer]
# Dyalog APL: 10 bytes
Nothing really to say here, regular solution.
```
(⍳∘≢≡⍋)2>/
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 13 bytes
```
¬№⭆Φθκ›ι§θκ01
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMMvv0TDOb8UyAouAQqk@yYWaLhl5pSkFmkU6ihka@oouBelJoK4mToKjiWeeSmpFRAZTaCckoGhEpBh/f9/dLShjoKJjoKpjoKxjoJRbOx/3bIcAA "Charcoal – Try It Online") Link is to verbose version of code. Outputs a Charcoal boolean, i.e. `-` for a tower permutation, nothing if not. Explanation: Port of @xnor's Python 2 answer.
```
    θ           Input array
   Φ            Filtered where
     κ          Current index is not zero
  ⭆             Map over remaining elements and join
       ι        Current element
      ›         Is greater than
         θ      Unfiltered array
        §       Indexed by
          κ     Current index
¬№              Does not contain
           01   Literal string `01`
                Implicitly print
```
[Answer]
# [Perl 5](https://www.perl.org/), 47 bytes
```
sub{join('',map$_[-2]>pop?I:D,2..@_)=~/^I*D*$/}
```
[Try it online!](https://tio.run/##hVPRasIwFH3vV1zGdW0lKk2zPViqPshABvPFN@fEzbR00zZUCw5xv951zSpuS7JCobknp@fc3BPB881NiVFY7orn42uWpI5tk@1K4HLeoYuByMRw0h8T2u2Olm740XuatMdt7J3KwNq@OzjLC07wbrXZcTd0PFKkax65gRVluWPNAebeAsIB1PsAFkTWCFBFmRLQ7SbgqxFf/6szp3Z3CflqIb8mURXJrz0Y3BFgWpAZ3Z@ZPxUlytTteRLRdChR88loVCXKzEen50rHnlqWGWfC/huLRtVvHJvmpufSS8d/UGZMBNOGgjWWld2yZgRUgxrSy5q4eRrUEGLWBO63ZfdoQfV83eeEYHWRR7gMvksYh9cYOSNMXFkSeZLuo6tW53YHwA@Cv@z5ug8tr1pCnO2bzyQVRbWoiI/pFQEHORyyHDB2YQj2w3QG03sb@mBnbzYB5NUbB9ap/AQ "Perl 5 – Try It Online")
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 41 bytes
```
f(a)=#a<3||(a[2]>min(a[1],a[3]))*f(a[^1])
```
[Try it online!](https://tio.run/##DcoxDoMwDIXhq1h0sSszhHQsHIMlCpKFCPIQakUduXvwG359wzNpOp7We0Gh@SXfeN8oacpL1csRMkuKmejth7SFTL38GuocGD4MbjtaRQU2Bmt6/XE9djSCAcbFU9y@/gA "Pari/GP – Try It Online")
A port of [@xnor's Python answer](https://codegolf.stackexchange.com/a/243180/9288).
---
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 47 bytes
```
a->#a<3||prod(i=2,#a-1,a[i]>min(a[i-1],a[i+1]))
```
[Try it online!](https://tio.run/##FcqxDoMwDATQX7FgcVR7CHQs@YwuVQarJcgDYFkd@ffUveH0TjoTV96sN1i6cBnlMV@X@flBXSYahTPJS2vZ9cAA5/rft1xT6u30eGWCO0HYVt9RgYzAXI8vPtc3WoIBuES1cKT/AA "Pari/GP – Try It Online")
[Answer]
# [Java (JDK)](http://jdk.java.net/), 71, 63 bytes
```
h->{int b=0,s=1;for(int a:h)s=s*b>s*(b=a)?s>0?-1:0:s;return s;}
```
[Try it online!](https://tio.run/##VVDLbtswELznK6YGDFCBTYiJ8qhUOcilQA9FDuktyIF2JEeuLAlcyoAR@NvZ5dpGmgN3NbOzswNt7M7ON29/w6q1RPhtmw4fF8AwLttmBfLWc9v1zRu2PFPP3jXd@uUV1q0pESmwYRM9@qbV9ditfNN3@k//q/M/T@hH0/mX1wVqlOF9vvhgiGWZzqg0Rd07FbHN3xMq6XK5oEu1LG3yQIv0YW7yNKfCVX50Hag4hEIu8hbUzroYA/mXMMCRd3aP8r9oj5EhTd5Vdqt4Q9PQNl5NMEkSvbWDRFb8qnXl8nxn27F6qhPte1lVSXHyf96Tr7a6H70e@G/4Wk2mlGNK024yi1lmqLUdhnb/SNFSsiT4ViI9eRwu4juEYILBVbiCdFxzvT5i/mbMPD9mmD1rkEnPzmrBzLLKxCp89unD89izs6PgqDchuhwvZZ@3eC6q81XBogyyJXwmeQTxvrgwL6zgY3ZxFf5LftzgFne4x3eYFIbrPcwdzC3MDQyb8RbLzT8 "Java (JDK) – Try It Online")
returns 0 if a castle, non zero (1 or -1) if a tower;
## Explanation
Starts with an expected minimum "slope" (s) of 1,
Checks if difference between consecutive values matches the expected "direction" by multiplying them by the slope to normalize direction and ensuring next value is greater. If this check fails while the slope is 1, changes the slope to -1 for the remainder of the comparisons. If this fails while the slope isn't 1, changes to a slope of 0. Otherwise keeps the same slope as last iteration. Slope of 0 means a delta in an unexpected direction and therefore not a tower, also ensures all consecutive direction computations are 0 so computed slope of 0 'sticks'. Returns the slope 's'
[Answer]
# [Desmos](https://www.desmos.com/calculator), ~~41~~ 39 bytes
*-2 bytes thanks to [Aiden Chow](https://codegolf.stackexchange.com/users/96039/aiden-chow)*
```
D=sign(l-l[2...])
M(l)=1/max(D-D[2...])
```
The function `M` takes a list and returns `undefined` for tower permutations or `0.5` for non-tower permutations.
[Try it (golfed)](https://www.desmos.com/calculator/fkw3si1wpx)
[Try it (prettified)](https://www.desmos.com/calculator/f2jzik4q0r)
### Explanation
`D` is a helper quantity? macro? that takes the pairwise differences of a list `l` and gets the sign of each. The result will be a list of `1`s and `-1`s. If `l` is a tower permutation, all the `-1`s will come before the `1`s.
`M` then takes the result of `D` and gets *its* pairwise differences. For a tower permutation, this will be a list of `0`s and possibly a `-2`. For a non-tower permutation, there will be a `2` somewhere. Thus, the max of the second-level differences will be `0` for a tower permutation or `2` for a non-tower permutation. But there are also inputs of length 1 or 2 to be considered; they are too short for to have any second-level differences, which means that `max` returns `undefined`. To merge this result with the `0` from longer lists, we invert it, resulting in `undefined` for any tower permutation and `0.5` otherwise.
---
Alternate 39-byte solution that returns `1` instead of `0.5`:
```
D(l)=sign(l-l[2...])
M(l)=1/D(D(l)).max
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 5 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ü›D{Q
```
[Try it online](https://tio.run/##yy9OTMpM/f//8J5HDbtcqgP//4821DHRMdUx1jGKBQA) or [verify all test cases](https://tio.run/##RY4hDsMwDEWvUhWbODEv6QWGo4JNKigaqFQpKhnaAXacaWw36UWy@O8rJbHz/P@37@v1tsxly0PfHc9X1w@5fD/H4z3ulyIlJZ0kqYT6BmEvETWSRvD6O@di7KxpDWp10nwGB1TMMKZARaZ0OjFm/G@oCu7yzsjcYcxVMGSAYYY85JMFXoKLMEWFFxlkgXnY3@50x/QD).
**Explanation:**
```
ü      # For each overlapping pair of the (implicit) input-list:
 ›     #  Check if the first is larger than the second
  D    # Duplicate this list of checks
   {   # Sort the copy
    Q  # Check if the lists are still the same (thus it was sorted)
       # (after which the result is output implicitly)
```
]