[Question]
  [
# Can the Tune be Played?
## Explanation
A broken musical keyboard has keys labelled with positive integers. It is broken in two ways:
1. It takes a long time to process key presses: after pressing the key labelled with the number \$n\$, there is a gap of \$n\$ seconds before the \$n\$th note is heard.  
So, for example, the \$5\$th key must be pressed \$5\$ seconds early for its note to sound in the right place.
2. Only one key can be **pressed** at a time.
Because of these problems, some tunes cannot be played on the keyboard. To understand why, let us first define a tune:
A tune will be defined as a list of positive integers representing the order in which notes should be **heard** (not the order in which keys should be pressed). A number \$n\$ represents the note heard when the \$n\$th note on the keyboard is pressed. This definition does not allow for rests, chords or notes of differing lengths, so you can imagine that all notes are played at a speed of exactly one note per second.
## Invalid Tune Example
An example of a tune would be `[3, 1, 2]`. This means that the note \$3\$ should be heard, then, one second later, the note \$1\$, and a second after that, the note \$2\$.
However, when trying to play this tune on the keyboard, there is a problem. To understand why, shift each of the numbers \$n\$ in the tune back by \$n\$ spaces. The result represents the order in which keys must be pressed for the notes to sound in the correct place:
```
Tune                      [            3 , 1 , 2]
Index                      -3  -2  -1  0   1   2
How keys would be pressed [3 ,        1&2       ]
```
The problem here is that keys \$1\$ and \$2\$ must be pressed at the same time for their notes to sound in the right place, but it is impossible to press two keys at once on the keyboard. Therefore, the tune `[3, 1, 2]` cannot be played.
## Valid Tune Example
An example of a valid tune would be `[2, 1, 3]`. To see why, shift the numbers back to find out when the keys must be pressed:
```
Tune                      [        2 , 1 , 3]
Index                      -2  -1  0   1   2
How keys would be pressed [2 , 3 , 1        ]
```
Having shifted each of the numbers back (\$2\$ moved back \$2\$ spaces, \$1\$ moved back \$1\$ space and \$3\$ moved back \$3\$ spaces), none of them have landed in the same position. Therefore, this tune can be played on the broken keyboard: the keys would be pressed in the order `[2, 3, 1]`.
## Task
Your task is to write a program which takes as input a list representing a tune, and outputs a [truthy/falsy](https://codegolf.meta.stackexchange.com/a/19205/110951) value depending on whether or not the tune can be played on the broken keyboard.
## Assumptions
* You can assume that input lists will always contain only positive integers.
* You can assume that input lists will always have at least one element.
* You can assume that inputs will always be lists.
* [Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
## Test Cases
```
[1, 2, 3] -> False
[3, 1, 2] -> False
[3, 2, 1] -> True
[6, 4, 7, 3, 5, 2, 1] -> True
[4, 7, 6, 5, 2, 1, 3] -> False // 6 and 4 land in same position
[4, 6, 4, 2, 1, 4] -> False
[2, 1, 6, 4, 4, 4] -> False // 4 and 1
[2, 1, 6, 4, 2, 4] -> True
```
## Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest answer (as measured in bytes) wins!
  
[Answer]
# JavaScript (ES6), 30 bytes
Returns a Boolean value.
```
a=>a.every(b=(n,i)=>b[i-n]^=1)
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/R1i5RL7UstahSI8lWI08nU9PWLik6UzcvNs7WUPN/cn5ecX5Oql5OfrpGmka0oY6CkY6CcawCEtDUVNDXV3BLzClO5UJTbqyjANJBgnKg6YZYlIcUlWKoNtNRMNFRMAc6R0fBFKoTt2qIUjO4UpAvkJzyHwA "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal/blob/v2.6.0/documents/knowledge/elements.md), 4 [bytes](https://github.com/Vyxal/Vyxal/blob/master/docs/codepage.txt)
```
≈º-√ûu
```
My first Vyxal answer. Similar approach as the other answer.
[Try it online](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLFvC3DnnUiLCIiLCJbNiw0LDcsMyw1LDIsMV0iXQ==) or [verify all test cases](https://vyxal.pythonanywhere.com/#WyIiLCLilqEoROKCtGAgLT4gYOKCtCIsIsW8LcOedSIsIiwiLCJbMywyLDFdXG5bNiw0LDcsMyw1LDIsMV1cblsyLDEsNiw0LDIsNF1cblsxLDIsM11cblszLDEsMl1cbls0LDcsNiw1LDIsMSwzXVxuWzQsNiw0LDIsMSw0XVxuWzIsMSw2LDQsNCw0XSJd).
**Explanation:**
```
≈º     # Push a list in the range [1, input-length]
 -    # Subtract it from the input at the same positions
  √ûu  # Check if all values in this list are unique
      # (after which the result is output implicitly)
```
[Answer]
# [R](https://www.r-project.org/), 34 bytes
Or **[R](https://www.r-project.org/)>=4.1, 27 bytes** by replacing the word `function` with a `\`.
```
function(v)all(table(seq(!v)-v)<2)
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP0@jTDMxJ0ejJDEpJ1WjOLVQQ7FMU7dM08ZI83@aRrKGoY6CkY6CsaamsoKunYJbYk5xKhdI3FhHASSFTRyo3hAqHlJUChE201Ew0VEwB5qko2CKXQlE3gwuj2brfwA "R ‚Äì Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
_JQ∆ë
```
[Try it online!](https://tio.run/##y0rNyan8/z/eK/DYxP@H2x81rfn/P9pQx0jHOFZHIdpYB8iEMIx0DEEMMx0THXMdYx1TmACIawbhAvUAAA "Jelly ‚Äì Try It Online")
```
_J     -- difference between each element and its 1-based index
   ∆ë   -- is this list invariant under:
  Q    --   removing duplicates?
```
[Answer]
# [Python 2](https://docs.python.org/2/), 42 bytes
-7 thanks to Jonathan :)
```
lambda n:n[len({a-n.index(a)for a in n}):]
```
[Try it online!](https://tio.run/##RY7NCoMwEITvPsUcE9gW1P6A4LVP0Jv1kGKCAbuKpqCUPnuatLbdwzLzsbO7w@LanjNvyovv1O3aKHDBVadZPNSGt5YbPQslTT9CwTL4KYva2@k83l27lGtmLoLXsAYzdDdpnFToSRJjTk8uJkWVEjJCXhOqnBDdKgNNozwQdoRjmCHs//jDDj8Wd8giQahhtOzeJwjfp4QREUjpXw "Python 2 ‚Äì Try It Online")
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), ~~52~~ 51 bytes
```
j=>j.Count==j.Select((x,y)=>y-x).Distinct().Count()
```
[Try it online!](https://tio.run/##jc0xC8MgFATgvb/C0QdGMBkbXRI6ZevQvWLgiTyhGppQ@tutUNrZ9fjuzqbOJiyXjey4YMojUjaC3WMMhq1MF6@Nl1PcKGvt5dUFZzPnuzhAm6PbQc61hVRD@DIO5XyaIqUYnLw9MLsFyfGVk3uy/wV7KdGL4Q3QhIeKVTtW7bj/LZcP "C# (Visual C# Interactive Compiler) ‚Äì Try It Online")
Nice thing about how verbose C# is is that it is makes the code relatively self-explanatory. The downside is that it makes it hard to golf in. Interactive Compiler C# lets us cheat a bit by removing all the boilerplate.
A technical breakdown: If we can show that two keys need to play at the same time, we know it cannot be played. This approach tackles this by determining when they should play and checking for any duplicates. If we store when they should play and make that list distinct, all duplicates will be removed, however, the number of elements in the list will decrease as a result. By comparing that count against the original's, we get the true/false value we need.
To do this, we use the index overload of Linq's Select. This use of Select converts our collection of integers into another collection of integers, but with different values, that is, the original value subtracted from its respective index. Distinct and Count are both self-explanatory.
Saved one byte by taking a List instead of int[]. 'Count' is a property on a List; the eqivalent on an array is 'Length,' which is one extra byte. On an IEnumerable, 'Count' is a function, which is why 'Count' at the end requires the parens. It's not the best naming choices, but I have no control over that.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 24 bytes
```
i!=##&@@(i=0;i++-#&/@#)&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7P1PRVllZzcFBI9PWwDpTW1tXWU3fQVlT7X9AUWZeSbSyrl2ag3KsWl1wcmJeXTVXtaGOkY5xrQ5XtbEOkAlhGOkYghhmOiY65jrGOqYwARDXDMIF6uGq/Q8A "Wolfram Language (Mathematica) ‚Äì Try It Online")
```
                  &/@#  for each:
         i=0;i++-#        index minus value
i!=##&@@(             ) all distinct (and unequal to length)
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~9~~ 8 bytes
```
tf-&=sqa
```
[Try it online!](https://tio.run/##y00syfmfkKlQEuWnYK9QoacQq/C/JE1Xzba4MPF/SOz/aEMdBSMdBeNYrmhjHQUQB8ICihkCWWY6CiY6CuZABToKpnBRiJAZXAis30DfAAA "MATL ‚Äì Try It Online")
0 for üéµüé∂üéπ  
1 for broken keyboard leads to broken ‚ù§Ô∏è.
**Explanation**:
`tf-` : Subtract from each input element its (1-based) index  
`&=` : Compare each value against the whole array, giving a boolean matrix  
`s` : sum each column to get a row vector of sums  
`q` : Decrement each sum by 1 to take away the self-equality 1s  
`a` : Check if there are any non-zero values still
---
A more obvious way is `tf- 8#uqa` (count how many times each unique value occurs in `input - indices` and see if it's all 1), but unfortunately the need for space between `-` and `8` pushes it to 9 bytes.  
Edit: [Luis Mendo's answer on another question](https://codegolf.stackexchange.com/a/243745/8774) taught me the trick of `&` at the end, to print only the top of the stack, with which this can instead be `tf-&uqa&` - also 8 bytes. Only works on the current master of MATL though - neither TIO nor [MATL Online](https://matl.suever.net/) have the `&u` feature available yet.
Another 9-byter is `tf-&=XRaa`.
[Answer]
# APL+WIN, 20 bytes
Prompts for tune. 1=true, 0=false
```
0=+/2=/m[‚çãm‚Üên-‚ç≥‚ç¥n‚Üê‚éï]
```
[Try it online! Thanks to Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcQJanP5BlyPWooz3tv4Gttr6RrX5u9KPe7lygcJ7uo97Nj3q35AHZQKWx/4GquP6ncRkqGCkYc6VxGSsAWWDaSMEQSJspmCiYKxgrmEL5IJ4ZhKdgDAA "APL (Dyalog Classic) ‚Äì Try It Online")
[Answer]
# [Julia 1.0](http://julialang.org/), ~~26~~ 23 bytes
```
~v=allunique(v-keys(v))
```
[Try it online!](https://tio.run/##yyrNyUw0rPj/v67MNjEnpzQvs7A0VaNMNzu1slijTFPzv0NxRn65Ql20oY6CkY6CcawCElB2S8wpTuWCKTHWUQCpQlWigKEGaIwhmpqQolKEEjMdBRMdBXOgZToKplDlaEog8mZweZDDYDb9BwA "Julia 1.0 ‚Äì Try It Online")
*-3 bytes thanks to @MarcMush*
`true` for can be played, `false` otherwise.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 33 bytes
```
\d+(?=((,)|.)*)
$*1$#2$*
D`1+
,\B
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wPyZFW8PeVkNDR7NGT1NLk0tFy1BF2UhFi8slwVCbSyfG6f9/Qx0jHWMuYx0gDSSNdAy5zHRMdMx1jHVMwTwQ2wzC1jEGAA "Retina 0.8.2 ‚Äì Try It Online") Link includes test cases. Outputs a truthy value if the tune can't be played and a falsy value if it can. Explanation:
```
\d+(?=((,)|.)*)
```
Match values but also count the number of following values.
```
$*1$#2$*
```
Convert to unary and add on the number of following values. (This is easier to do than subtracting from number of preceding values.)
```
D`1+
```
Delete duplicates.
```
,\B
```
Check for a deletion.
19 bytes in [Retina](https://github.com/m-ender/retina/wiki/The-Language) 1:
```
\d+
*_$;&*
D`_+
,\B
```
[Try it online!](https://tio.run/##K0otycxLNPyvquGe8D8mRZtLK17FWk2LyyUhXptLJ8bp/39DHSMdYy5jHSANJI10DLnMdEx0zHWMdUzBPBDbDMLWMQYA "Retina ‚Äì Try It Online") Link includes test cases. Explanation: In Retina 1 `$;&` automatically counts the number of remaining matches i.e. the number of following values.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 12 bytes
```
ÔºµÔº≠Œ∏‚ÅªŒ∫Œπ‚äôŒ∏‚äñ‚ÑñŒ∏Œπ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/983scA5Pzc3MS9Fo1BHwTczr7RYI1tHIVNT05oroCgzr0TDMa8SJOWSmlyUmpuaV5KaouGcXwqUKAQrAyr8/z862kRHwVxHwUxHwVRHwUhHwVBHwTg29r9uWQ4A "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Outputs a Charcoal boolean, i.e. `-` if the tune can't be played and nothing if it can. Explanation:
```
ÔºµÔº≠Œ∏‚ÅªŒ∫Œπ
```
Subtract each element's value from its index.
```
‚äôŒ∏‚äñ‚ÑñŒ∏Œπ
```
Check whether any of the results were duplicated.
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 11 bytes
```
{x~?x-:!#x}
```
[Try it online!](https://ngn.codeberg.page/k#eJxlj0FPhDAQhe/9Fc/oQRO6FcpCQhO9+Qu8EZKtUBaybIu0JN1s3N9ukajRPc2b781k5rXF2V+ePS1ubv0HIa4435Wny1S0ALzYmYO437WyH4QXJzE9VGGGuDJGAi4eqyA5QvMtE8QiXmSGFDk4tr9oAdkK1l3CSOfcaAvGatOovRnajXWyPihfd1Lv1aY2R/Y+K+t6oy1LUp4nOaulpq5T1M1a0TdFx0GeVEPKOEISgVegT3iRg1Wk5BEW+g+FqfgLvU5zIFmENEIeViNsr9zVyn6sPxfAWIgkdRPSDkvpNaw8KozG9svTn+QEXs8=)
* `!#x` generate `0..len(input)`
* `x-:` subtract the above from the input, "inplace" (i.e. updating `x`)
* `x~?` is the above composed of only distinct/unique values?
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~13~~ ~~12~~ 9 bytes
```
L{I.e-bkb
```
[Try it online!](https://tio.run/##K6gsyfj/36faUy9VNyk76X9ltKGCkYKxJldltLECkAlhGCkYghhmCiYK5grGCqYwARDXDMIF6vn/L7@gJDM/r/g/AA "Pyth ‚Äì Try It Online")
```
L{I.e-bkb
L           # lambda b:
   .e-bkb   # difference between each element in the list b and its index
 {          # removes duplicates in the list
  I         # invariant?
```
[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//SKOuy@GZgf//RxvrGOoYxQIA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/I426LodnBv7X@R8dbaxjpGMYqxNtpmOiY65jrGMK5QNJHZCYkY4JkGcIpI2BtDFQ1AhIg9SaQdSCxU2gag3BqmF6gTA2FgA).
**Explanation:**
```
ƒÅ      # Push a list in the range [1, input-length]
 -     # Subtract it from the values in the input at the same positions
       # Check if all values are unique:
  D    # Duplicate the list
   √ô   # Unquify the copy
    Q  # Check if both lists are still the same
       # (after which the result is output implicitly)
```
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), 7 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py)
```
h‚ïím-_‚ñÄ=
```
[Try it online.](https://tio.run/##y00syUjPz0n7/z/j0dRJubrxj6Y12P7/H22sY6RjGMsVbaZjomOuY6xjCuUDSR2QmJGOCZBnCKSNgbQxUNQISIPUmkHUgsVNoGoNwapheoEwFgA)
**Explanation:**
```
h        # Push the length of the (implicit) input-array
 ‚ïí       # Pop and push a list in the range [1,length]
  m-     # Subtract these values from the input at the same positions
    _    # Duplicate this list
     ‚ñÄ   # Uniquify the values in the copy
      =  # Check if the two lists are still the same
         # (after which the entire stack is output implicitly as result)
```
[Answer]
# [Factor](https://factorcode.org/), 31 bytes
```
[ [ - ] map-index all-unique? ]
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7OnnbqWQm1iSoVCcWliampecWgxklRQrFBSllpRUFhRl5pUoWHNxVXMpAEG1gqGCkYKxQi2UZwzmI3hGQD6MZ6ZgomAOFDNFEQWJmUHFQObU/o9WiFbQVYgFOqJANzMvJbVCITEnR7c0LxPoHHuF2P9AcQW9/wA "Factor ‚Äì Try It Online")
* `[ - ] map-index` Subtract each index from its element.
* `all-unique?` Are they all unique?
[Answer]
# [Haskell](https://www.haskell.org/), 45 bytes
```
f l|j<-zipWith(-)[1..]l=[x|x<-j,y<-j,x==y]==j
```
[Try it online!](https://tio.run/##fZC9DoIwFIV3nuIMDpoUSLXiQh19AhMHwtBEjMXyE8AEje@OLUS0gbi0yffdnN7Tq6hviVJdd4F6paH7lOVJNtelu4qo58WKR@2rDd2UPMzRcv6IOU@7TMgcHOfCQVnJvMECF0SUYE2wiS24ITB8AvUktWFAwAh2OoFgOzcw2GC0k7dYb9nHMtsOcBhgf@3aWHRjIbh7HISqE2esY6N@V4OO1V2TuSZfO1djjIPvI4DIz2BQ5tIfXYssQVnUspFF7kxb/uwy6WgFsz6YOjNlP9u9AQ "Haskell ‚Äì Try It Online")
We put in *j* the tune as it would be played.  
Then we check if its product has only *j* as duplicates using a list comprehension.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 11 bytes
```
g#=UQ$-*ENg
```
Takes the numbers as separate command-line arguments. [Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgwYKlpSVpuhar05VtQwNVdLVc_dIhIlCJrdEmOgrmOgpmOgqmOgpGOgqGOgrGsVBJAA)
### Explanation
```
          g  ; List of command-line args
        EN   ; Enumerate: list of [index; element] pairs
     $-*     ; Fold each on subtraction, giving index-element
   UQ        ; Uniquify
 #=          ; Return truthy if the result is the same length as
g            ; the original list
```
[Answer]
# [Matlab](https://www.gnu.org/software/octave/), 33 bytes
```
K=@(x)all(diff(sort(x-find(x))));
```
find(x) is the array of 1:length(x), and subtracting the index of each note from the notes value produces the new index of when the note is played. By sorting the resulting array and taking the diff of sequential values, we can determine if there is overlap by making sure that there are no 0 differences (indicating two values are overlapping)
[Try it online!](https://tio.run/##y08uSSxL/f/f29ZBo0IzMSdHIyUzLU2jOL@oRKNCNy0zLwUoDATW//8DAA "Octave ‚Äì Try It Online")
]