Challenge
Given a string describing a cutting rule and another string, cut parts out of the second string using the rule described by the first string.
Both strings will consist of letters a-z
or A-Z
, whichever one you choose (they don't have to be represented the same way). The way the second string is to be modified is described below:
Algorithm
Take the first string and imagine filling in the gaps between non-adjacent (increasing) letters with =
; for example, abcfg
=> abc==fg
. Then, line up the two strings and return all characters from the first string that aren't above an equal sign. For example, given abcfg
and qrstuvw
as inputs:
qrstuvw - Modify
abc==fg - Modifier
qrs--vw -> qrsvw
If the modifier is shorter after filling with equal signs, all trailing characters in the second string should be included. If the modifier is longer, the trailing characters are ignored.
The modifier isn't guaranteed to be sorted.
Test Cases
abcfg, qrstuvw -> qrsvw
abqrs, qwertyuiopasdfghjklzxcvbnm -> qwjklzxcvbnm
za, qr -> qr
azazaz, qwertyuioplkjhgfdsazxcvbnmnbvcxzasdfghjklpoiuytrewq -> qmn
Reference Implementation (used to generate test cases) -> TIO
Rules
- Standard Loopholes Apply
- You may take input as two strings, two lists of characters, a matrix of characters, etc. (any other reasonable format is acceptable)
- You may output as a string or a list of characters (or some other standard format for strings)
- This is code-golf, so the shortest answer in bytes in each language is declared the winner for its language. No answer will be accepted.
- Either string may be empty.
Happy Golfing!
Inspired by Kevin Cruijssen's recent two challenges, "There, I fixed it (with tape/rope)"
There, I blew it up (with a segfault)
\$\endgroup\$