One of the lesser known programming paradigms which seems rather fitting for code golfing is Overlapping Oriented Programming (OOP) *. When writing partly identical code, many bytes can be saved by simply overlapping the identical parts and remembering in some way where the two original code lines start. Your task is to write two overlapping programs or functions
decompress with the following specification:
*Do not use in production code, probably.
compress takes two strings in any convenient format and overlaps them as much as possible. That is a string
s with minimal length is returned such that both input strings are substrings of
s. Additionally, some output which identifies the start and end indices of both string is returned.
Examples: (The exact IO-format is up to you)
compress("abcd", "deab") -> "deabcd" ((2,5),(0,3)) compress("abcd", "bc") -> "abcd" ((0,3),(1,2)) compress("abc", "def") -> "abcdef" ((0,2),(3,5)) or "defabc" ((3,5),(0,2))
decompress computes the inverse function of
compress, that is given a string and two start and end indices (in the format in which they are returned by your
compress), return the two original strings. You need only handle valid inputs.
The following equality should hold for all strings
(s1, s2) == decompress (compress (s1, s2))
Examples: (inverses of
decompress "deabcd" ((2,5),(0,3)) -> "abcd" "deab" decompress "abcd" ((0,3),(1,2)) -> "abcd" "bc" decompress "abcdef" ((0,2),(3,5)) -> "abc" "def" or (whichever version your "compress" generates) decompress "defabc" ((3,5),(0,2)) -> "abc" "def"
Your score is the size of the string returned by calling
compress("<code of compress>", "<code of decompress>"). As this is code-golf a lower score is better.
Assume the code for your function
c=abcd and the code for
compress("c=abcd", "d=efghi") yields
"c=abcd=efghi" (and the indices, but those don't affect scoring) so the score is
length "c=abcd=efghi" = 12.
- In the spirit of this challenge, your
decompressmust overlap in at least one character. You may achieve this trivially by adding a comment, but note that doing so will increase your score and there might be shorter solutions using inherently overlapping code.
decompressshould be able to handle strings containing any printable ASCII characters as well as all characters you used to define
- The indices can be zero- or one-indexed.
- Your programs or functions don't have to actually be named