Skip to content

Instantly share code, notes, and snippets.

@brownag
Last active April 25, 2023 01:21
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 brownag/f651c99bc9983452e02964e2a2e4d1d4 to your computer and use it in GitHub Desktop.
Save brownag/f651c99bc9983452e02964e2a2e4d1d4 to your computer and use it in GitHub Desktop.
alphanumeric sequence counts
c("abcd123", "abcd124", "abcd133", "acbd123", "dbac312", "dcba321") |>
(\(x) {
strsplit(x, "") |>
lapply(\(x) sapply(x, charToRaw)) |>
sapply(\(x) c(0, diff(as.integer(x)) == 1)) |>
colSums()
})()
#> [1] 5 4 3 2 1 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment