Skip to main content
8 of 9
Minor editing
Sherlock9
  • 12.4k
  • 1
  • 32
  • 68

Actually, 38 37 35 33 31 30 bytes

This is a simple implementation of the function definition. Golfing suggestions welcome. Try it online!

Edit: -3 bytes thanks to Leaky Nun.

2R#╗,;`1";2±╜tπg@╜í+Y"£╓╖`nD╜E 

Ungolfing:

2R#╗ Push [1,2] and store it in register 0 ,; Take input and duplicate `1 Start function, push 1 " Start string ; Duplicate i 2±╜t Push (list in register 0)[-2:] πg gcd(i, product of list[-2:]) @╜í Rotate the gcd and bring up i, check for i in list (0-based, -1 if not found) +Y Add the gcd and the index, negate (1 if coprime and not found in list, else 0) "£ End string, turn into a function ╓ Push first (1) values where f(x) is truthy, starting with f(0) ╖` Append result to the list in register 0, end function n Run function (input) times D╜E Return (final list)[n-1] 
Sherlock9
  • 12.4k
  • 1
  • 32
  • 68