[Question]
  [
Define a 1-indexed sequence as follows:
* `A083569(1) = 1`
* `A083569(n)` where `n` is an integer greater than `1`, is the smallest integer m not occurring earlier such that `m+n` is a prime number.
Your task is to take in `n` and return `A083569(n)`.
```
 n  A083569(n)
 1  1
 2  3
 3  2
 4  7
 5  6
 6  5
 7  4
 8  9
 9  8
10 13
11 12
12 11
13 10
14 15
15 14
16 21
17 20
18 19
19 18
20 17
```
More testcases can be found [here](https://oeis.org/A083569/b083569.txt). The original sequence on OEIS can be found [here](https://oeis.org/A083569).
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest answer in bytes wins. [Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply.
  
[Answer]
# [Haskell](https://www.haskell.org/), ~~87~~ ~~86~~ ~~83~~ ~~80~~ ~~74~~ 69 bytes
*Thanks to xnor for suggesting some changes that saved 3 bytes!*
```
f n=[m|m<-[1..],all((>0).mod(n+m))[2..n+m-1],all((/=m).f)[1..n-1]]!!0
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hzzY6tybXRjfaUE8vVicxJ0dDw85AUy83P0UjTztXUzPaSE8PyNA1hErq2@Zq6qVpgpTnAQVjFRUN/ucmZuZZWXn6a2hygZgKtgq5iQW@8RoFRZl5JVDFRgax/wE "Haskell – Try It Online")
I'm new to Haskell, and Haskell golfing, feedback is appreciated!
## Explanation
We define a function `f n`. We define `f n` to be the first element `!!0` of the list:
```
[m|m<-[1..],all((>0).mod(n+m))[2..n+m-1],all((/=m).f)[1..n-1]]
```
Broken down that is:
```
[m|          # Numbers m
m<-[1..],    # From the integers greater than 0
all          # Forall x
(>0).mod(n+m)# n+m mod x is not zero
[2..n+m-1]   # from the integers from 2 to n+m-1
all          # Forall
((/=m).f)    # when f is applied the result is not m
[1..n-1]     # from the integers from 1 to n-1
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~16~~ 15 bytes
```
Rɓ²R+⁸ÆPTḟḢṭµ/Ṫ
```
This assumes **A083569(n) ≤ n²** (the sequence appears to be growing linearly).
[Try it online!](https://tio.run/##ATMAzP9qZWxsef//UsmTwrJSK@KBuMOGUFThuJ/huKLhua3CtS/huar/MjBSwrXFvMOH4oKsR/8 "Jelly – Try It Online")
### How it works
```
Rɓ²R+⁸ÆPTḟḢṭµ/Ṫ  Main link. Argument: n
R                Range; yield [1, ..., n].
 ɓ               Begin a dyadic chain with swapped arguments.
            µ/   Reduce the range by that chain.
                 If we call the chain f, this computes f(2,1), then f(3,f(2,1)),
                 then f(4,f(3,f(2,1)), etc.
                 The left argument is an integer k, the right one an array A.
  ²                Square; yield k².
   R               Range; yield [1, ..., k²].
    +⁸             Add k, yielding [1+k, ..., k²+k].
      ÆP           Test each sum for primality.
        T          Truth; get all indices of 1‘s. This finds all m in [1, ..., k²]
                   such that m+k is prime.
         ḟ         Filterfalse; remove all resulting elements that appear in A.
          Ḣ        Head; extract the first remaining result.
           ṭ       Tack; append the extracted integer to A.
                 This computes the first n elements of the sequence.
              Ṫ  Tail; extract the last, n-th element.
```
[Answer]
# Pyth - ~~18~~ ~~17~~ 15 bytes
*Thanks to @isaacg for saving me two bytes!*
Back on this site, after being busy for a while, will hopefully golf this one further.
```
esmaYf&-TYP_+Th
```
[Try it online here](http://pyth.herokuapp.com/?code=esmaYf%26-TYP_%2BTh&input=10&debug=0).
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 169 bytes
```
n=>{if(n<2)return 1;var p=new int[n-1];int i=0,j,s;for(;i<n-1;)p[i]=f(++i);for(i=1;;i++){for(j=2,s=i+n;j<s&&s%j++>0;);if(j==s&!System.Array.Exists(p,e=>e==i))return i;}}
```
[Try it online!](https://tio.run/##fVBNT8MwDL3vV5hJTInSTe0QCJS60oTgAkgIDhymHaIuRa66dEqywTT1t5e04mO94INjvzy/PCd307y2uoUQeaWcg2dbv1u1GXXIsc9dOK885bCvaQ1Pigzjv1d/pC5eD87rzex@Z/KUjI8gpAwKQDC7qpIDboGtwexIBTPpnFvtd9ZAIvfKwhaN/uhml2aarGQogDCOysjJorZMUhpwybdLWmHBhCDe44SJlCQEP3ZdifPIIQkjy9RNJu68FCKLJZfhxRLRTc6@3S6sVYfZ3Sc579g20phpROI/lkg2TTu0PtyjtsB6i2HNRIYjRZjHoQhOBsyTH7qtjasrPXuz5PUjGc3Gi/j64vLqho1BBA0BYx70uqZgwYwc/aPyotX6QR/YCavpq6b9Ag "C# (.NET Core) – Try It Online")
By far the most inefficient way to calculate the results, so please refrain from calculating `f(n)` for `n>=30` with this code. The first step is to recursively calculate the values from `f(1)` to `f(n-1)` and then proceed to calculate `f(n)` by searching for the first `i` such that `n+i` is prime and `i` is not in the previous values list.
[Answer]
# x86-64 Assembly, ~~57~~ 55 bytes
I'm new to golfing, so comments/feedback are appreciated.
Note: this is optimized for machine code length, not for source length.
```
0: 89 f8 ff cf 74 32 97 89 fe 89 f1 ff c6 89 f0 99
1: f7 f1 85 d2 e0 f7 85 c9 75 ed 89 f9 ff c9 56 29
2: fe 56 57 51 89 fc e8 d3 ff ff ff 59 5f 5e 39 c6
3: e0 ef 96 5e 74 d1 c3
```
Defines a function, using the standard convention (i.e. return value in eax, first argument in edi, all registers caller-saved except ebx) that takes an unsigned 32-bit integer and returns the smallest m etc.
Source:
```
    .globl a083569
    // edi = original, probably don't touch
    // esi = candidate prime, if it's not a repeat we return edi-this
a083569:
    mov %edi, %eax
    dec %edi
    jz end
    xchg %eax, %edi
    mov %edi, %esi
primecheck:
    mov %esi, %ecx
    inc %esi
primeloop:
    mov %esi, %eax
    cdq
    div %ecx
    test %edx, %edx
    loopnz primeloop
/* end */
    // if esi isn't prime, then ecx is now one or greater.
    test %ecx, %ecx
    jnz primecheck
    // esi is now our target prime: check if it's not already one
    mov %edi, %ecx
    dec %ecx
    push %rsi   /* we need a flag-safe way to restore this later */
    sub %edi, %esi
chkdup:
    push %rsi
    push %rdi
    push %rcx
    mov %ecx, %edi
    call a083569
    pop %rcx
    pop %rdi
    pop %rsi
    cmp %eax, %esi
    loopne chkdup
/* end loop - chkdup */
    xchg %esi, %eax
    pop %rsi
    je primecheck
/* end outer loop - primecheck */
end:
    ret
```
[Try it online!](https://tio.run/##VVTbUtswEH22vmKHaYYEcoG2MG0oT7zyCZ1hFEm2FWzJSDJxYPj1pruy7CR@8Eir1Tm756zNvVf1ptovCiEOh@Xz082aZUsfnDZFdjGRMJF/zQXDWFHZTQX85tePu/vfLFutQEkNj2CdLrTh1RwaZzccsUBacxkg2FaUfaKnRMGN1JIHhYm6VnPQOehw6cHYABycahQPsFO4Cq0zBL8IpfYscWJhtX2HCcbn@OYdy6QScc@y7QcoI1nWibKIh/N0cHrFaxapRanEK8JpI/poyvIxS4zAuIr5lbXN@jyJ2IV8w0z9nu4E5QNR9dQYoGvmA0YItrqiIuFqFVXB9kkY7UmsJEkoFTYuOoyiLDuwRqHAUDiURrnlSCK6odLtwBCbGuUe7rcOAneFSgxriGnn0leILvfEdS7XmRBZ0/oSJs7rDNtAl4xSEm3LK14sPM8V7PgePUf3fLBOAVkHFZUdG/bt5tQHUb7KlkQdYcelPC6Jt69IjIYKXp2MYWOblNev4uW4IkRRN@Mw0D46oqAnH@ygICxSMNaahujo9BFxq07VTgi2pS4TzvGYsPAYm8SJZpTM22BrHjT1sIdCGeVQIAm5szV5D7mtKrvDbw@eQFip1oypDsENtMbrwpDkfevTITB7YEybADXXZjr7ZIAP7fVDXOY4PlP9ePsA@s/tHb6vr2fwiS3hFx7y6fiJ4@c4H7H1bNbf/mJfjGEbkJ70FyAuRq9k4Fs2cZveqyr7dkuy4Xb5/H2dYrQ/NTAbDTw/7sYAHye8B6Vf02BjZ90xhZ/zEgOX8qSMnvDlpe/4BX2Og0EZd0PK1qgMy41OD82QaYfDP0ET7g@L@v7nfw "Assembly (x64, Linux, gcc) – Try It Online")
[Answer]
## Clojure, ~~158~~ 155 bytes
```
#(loop[r[0 1]i 1](if(= i %)(last r)(recur(conj r(nth(for[j(range):when(=((set r)j)(seq(for[k(range 2(+ 1 i j)):when(=(mod(+ 1 i j)k)0)]j)))]j)0))(inc i))))
```
This might still have some fat, I'm not quite happy with `(+ 1 i j)` but this was the easiest way to handle base case `n = 1` and the rest. `((set r)j)` returns `nil` if `j` is not in the set, and `(seq ())` on an empty list returns nil as well. Calculates `n = 1000` in 48 seconds.
Update: removed `nil` from `=` check as the code works correctly also without it.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 62+8 = 70 bytes
Uses the `-rprime` flag.
```
f=->n,o=[]{o<<f[n-1,o]if n>1;Prime.find{|i|i>n&&o|[i-n]!=o}-n}
```
[Try it online!](https://tio.run/##FcrLCoJQFEbh@f8UOysp8Ehby676DM1FpNJTG@yc8EJE9uxWk/VNVt2dX8N4VP8gVT9quZeDjlViPBun2dseDjo1ij2biSaT8P74X3wtpnj30ktiXNf2qSiTjWL7UeYzPG9SlXQt2wYkFNMk91ubC@jRtQ0506DY0S8OTSkVj7R/OVXVTOYZSlMMjAAhllghwhobbMELMIMDcAheglfgCLwGb8BbBIsv "Ruby – Try It Online")
[Answer]
# Python, 194 170 110 bytes
*84 bytes saved by Leaky Nun*
*2 bytes saved by mathmandan*
```
def s(n):
 a=[s(j)for j in range(1,n)];i=1
 while(i in a)|any((i+n)%j<1for j in range(2,i+n)):i+=1
 return i
```
Defines a function s(n) that takes a number as input and returns A083569(n).
[Try it Online](https://tio.run/##XY4xCsJAEEX7nGIaYYakGe1WcxKxWHBjZpGfsFmRgHdfmU6s33@Pv@51XnBq7Z4m2hgSOorjdeMs01Iok4FKxCOxDpDb2Ubt6D3bM7E5i/KJ2JmthxzyRf@k4@BAgvXulVRfBWTNV/hNq0pYi6Gyf5D2BQ)
[Answer]
# [Husk](https://github.com/barbuz/Husk), 16 bytes
```
!¡λḟȯṗ+→L¹`-N);1
```
[Try it online!](https://tio.run/##ASwA0/9odXNr/23igoHhuKMxMDD/IcKhzrvhuJ/Ir@G5lyvihpJMwrlgLU4pOzH//w "Husk – Try It Online")
1-indexed.
]