Last active
April 25, 2023 01:21
-
-
Save brownag/f651c99bc9983452e02964e2a2e4d1d4 to your computer and use it in GitHub Desktop.
alphanumeric sequence counts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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