Skip to content

Instantly share code, notes, and snippets.

@jcmorrow
Last active December 27, 2020 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcmorrow/e33ca5d59c5a4e376992d298d0752d8c to your computer and use it in GitHub Desktop.
Save jcmorrow/e33ca5d59c5a4e376992d298d0752d8c to your computer and use it in GitHub Desktop.
input =: 15 5 1 4 7 0
nth =: dyad define
last =. _1{y
allP =. _1}.y
prev =. allP i: last
if. prev = # allP do.
new =. allP,last,0
else.
new =. allP,last,((# allP) - prev)
end.
if. (#new) = x do.
new return.
else.
x nth new
end.
)
{. |. 2020 nth input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment