19
1
Steganography hides a given message inside a given carrier, producing a package that does not look suspicious. For this challenge, you will write a program that takes an ASCII message and an ASCII carrier as input, and return or print a package that is identical to the carrier except characters corresponding to the message are doubled, in the same order that they appear in the message.
Rules:
- If the carrier already contains sequences of the same character more than once, and they are not used to encode a character of the message, the program will reduce them to a single character.
- If the carrier does not contain the message characters in the right order, the program may return nothing, the carrier itself, or an error.
- You may assume that the message and carrier are non-empty ASCII strings.
- Capitalization matters: A is not equivalent to a.
- When more than one package is valid, your program may output any or all of them.
- Space is a character like any other character.
Test cases:
Message Carrier Package "hi" "has it arrived?" "hhas iit arived?" OR "hhas it ariived?" "sir" "has it arrived?" "hass iit arrived?" "foo" "has it arrived?" "" OR "has it arrived?" OR an error. "Car" "Cats are cool." "CCaats arre col." "car" "Cats are cool." "" OR "Cats are cool." OR an error. "Couch" "Couch" "CCoouucchh" "oo" "oooooooooo" "oooo" "o o" "oooo oooa" "oo ooa"
This is code golf, so fewest bytes wins.
5Not suspicious at all... :P – Quintec – 2018-12-08T20:59:01.457
Is
"oooo oa"
(with 2 spaces) a valid output for the last test case? – Arnauld – 2018-12-08T21:36:29.2373It is not a valid output because the order of doubled characters in the package must match the order of the characters in the message. In the message, we have an 'o', then an ' ', then an 'o', but your package has the space after the o's – jkpate – 2018-12-08T21:58:15.347
Ah yes, that makes sense. – Arnauld – 2018-12-08T21:59:11.090
"If the carrier does not contain the message characters in the right order, the program may return nothing, the carrier itself, or an error." May it instead return the reduced carrier (with double characters converted to single characters)? – trichoplax – 2018-12-08T23:33:12.573
1No. My reasoning behind this rule is that the program's output in the case of no solution should be unambiguous that no solution is possible. The three allowed outputs are unambiguous, but more extensive checking would be required for the deduplicated case. – jkpate – 2018-12-08T23:46:45.597
Is
"eerorr"
a correct output for"er" "error"
? – tsh – 2018-12-10T02:39:12.147@tsh yes, "eerorr" is a valid output for message "er" and carrier "error" I.e. there is no requirement to use existing doubled characters when possible. – jkpate – 2018-12-10T14:14:00.680
To be clear, "eerror" is also a valid output. Your program can produce either or both – jkpate – 2018-12-10T14:39:28.067