Doubled-letter steganography











up vote
18
down vote

favorite
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:




  1. 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.

  2. If the carrier does not contain the message characters in the right order, the program may return nothing, the carrier itself, or an error.

  3. You may assume that the message and carrier are non-empty ASCII strings.

  4. Capitalization matters: A is not equivalent to a.

  5. When more than one package is valid, your program may output any or all of them.

  6. 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.










share|improve this question









New contributor




jkpate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 5




    Not suspicious at all... :P
    – Quintec
    2 days ago










  • Is "oooo oa" (with 2 spaces) a valid output for the last test case?
    – Arnauld
    2 days ago








  • 3




    It 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
    2 days ago












  • Ah yes, that makes sense.
    – Arnauld
    2 days ago






  • 1




    No. 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
    2 days ago















up vote
18
down vote

favorite
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:




  1. 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.

  2. If the carrier does not contain the message characters in the right order, the program may return nothing, the carrier itself, or an error.

  3. You may assume that the message and carrier are non-empty ASCII strings.

  4. Capitalization matters: A is not equivalent to a.

  5. When more than one package is valid, your program may output any or all of them.

  6. 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.










share|improve this question









New contributor




jkpate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 5




    Not suspicious at all... :P
    – Quintec
    2 days ago










  • Is "oooo oa" (with 2 spaces) a valid output for the last test case?
    – Arnauld
    2 days ago








  • 3




    It 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
    2 days ago












  • Ah yes, that makes sense.
    – Arnauld
    2 days ago






  • 1




    No. 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
    2 days ago













up vote
18
down vote

favorite
1









up vote
18
down vote

favorite
1






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:




  1. 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.

  2. If the carrier does not contain the message characters in the right order, the program may return nothing, the carrier itself, or an error.

  3. You may assume that the message and carrier are non-empty ASCII strings.

  4. Capitalization matters: A is not equivalent to a.

  5. When more than one package is valid, your program may output any or all of them.

  6. 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.










share|improve this question









New contributor




jkpate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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:




  1. 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.

  2. If the carrier does not contain the message characters in the right order, the program may return nothing, the carrier itself, or an error.

  3. You may assume that the message and carrier are non-empty ASCII strings.

  4. Capitalization matters: A is not equivalent to a.

  5. When more than one package is valid, your program may output any or all of them.

  6. 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.







code-golf string steganography






share|improve this question









New contributor




jkpate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




jkpate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Jonathan Allan

50.5k534165




50.5k534165






New contributor




jkpate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









jkpate

1914




1914




New contributor




jkpate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





jkpate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






jkpate is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 5




    Not suspicious at all... :P
    – Quintec
    2 days ago










  • Is "oooo oa" (with 2 spaces) a valid output for the last test case?
    – Arnauld
    2 days ago








  • 3




    It 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
    2 days ago












  • Ah yes, that makes sense.
    – Arnauld
    2 days ago






  • 1




    No. 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
    2 days ago














  • 5




    Not suspicious at all... :P
    – Quintec
    2 days ago










  • Is "oooo oa" (with 2 spaces) a valid output for the last test case?
    – Arnauld
    2 days ago








  • 3




    It 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
    2 days ago












  • Ah yes, that makes sense.
    – Arnauld
    2 days ago






  • 1




    No. 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
    2 days ago








5




5




Not suspicious at all... :P
– Quintec
2 days ago




Not suspicious at all... :P
– Quintec
2 days ago












Is "oooo oa" (with 2 spaces) a valid output for the last test case?
– Arnauld
2 days ago






Is "oooo oa" (with 2 spaces) a valid output for the last test case?
– Arnauld
2 days ago






3




3




It 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
2 days ago






It 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
2 days ago














Ah yes, that makes sense.
– Arnauld
2 days ago




Ah yes, that makes sense.
– Arnauld
2 days ago




1




1




No. 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
2 days ago




No. 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
2 days ago










7 Answers
7






active

oldest

votes

















up vote
4
down vote














Jelly, 28 bytes



ẹⱮŒp<ƝẠ$ƇṪ
nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç?


A full program taking carrier and message as command line arguments which prints the result

(For a non-packable message prints the unchanged carrier).



Try it online! Or see the test-suite.



How?



ẹⱮŒp<ƝẠ$ƇṪ - Link 1, helper function to find the indices to double: carrier, message
- e.g. "programming", "rom"
Ɱ - map across message with:
ẹ - indices of [[2,5], [3], [7,8]]
Œp - Cartesian product [[2,3,7],[2,3,8],[5,3,7],[5,3,8]]
Ƈ - filter keep if:
$ - last two links as a monad:
Ɲ - for neighbours:
< - less than? [1,1] [1,1] [0,1] [0,1]
Ạ - all truthy? 1 1 0 0
- [[2,3,7],[2,3,8]]
Ṫ - tail (if empty yields 0) [2,3,8]

nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç? - Main Link: carrier, message
? - if...
ç - ...condition: last Link (the helper function) as a dyad
ð - ...then: perform the dyadic chain to the left (described below)
¹ - ...else: do nothing (yields carrier)
- (the then clause:)
Ɲ - for neighbours in the carrier
n - not equal?
¥ - last two links as a dyad:
ç - call last Link (the helper function) as a dyad
Ṭ - untruth (e.g. [2,5] -> [0,1,0,0,1])
+ - add (vectorises)
a⁸ - logical AND with carrier
ḟ0 - filter out zeros
¦ - sparse application...
ç - ...to indices: call last Link (the helper function) as a dyad
Ḥ - ...do: double (e.g. 'x' -> 'xx')





share|improve this answer






























    up vote
    3
    down vote













    JavaScript (ES6), 75 bytes



    Takes input as (message)(carrier).





    s=>g=([c,...C],p)=>c?(c==s[0]?(s=s.slice(1),p=c)+c:p==c?'':p=c)+g(C,c):s&&X


    Try it online!





    Alternate version, 72 bytes



    If we can take the message as an array of characters:



    s=>g=([c,...C],p)=>c?(c==s[0]?(p=s.shift())+c:p==c?'':p=c)+g(C,c):s+s&&X


    Try it online!






    share|improve this answer























    • You could remove p= since p is passed by a parameter.
      – tsh
      1 hour ago




















    up vote
    2
    down vote













    Haskell, 124 121 107 101 97 95 90 bytes



    (#).(++"ü")
    "ü"#=
    p@(m:n)#e@(c:d)|m/=c=c:p#snd(span(==c)d)|m==n!!0=m:m:n#d|1<2=m:n#e


    Raises the "Non-exhaustive patterns" exception if the carrier does not contain the message.



    Try it online!



    Edit: -5 bytes thanks to @Laikoni.






    share|improve this answer























    • I think switching the cases allows you to drop m==c: Try it online!
      – Laikoni
      yesterday




















    up vote
    1
    down vote














    Retina 0.8.2, 67 bytes



    +`(.)(1*)1*(.*¶)(?(1)(1(2)))(.*)$(?!¶)
    $1$4$5¶$3$6
    M!s`.*¶$




    Try it online! Takes the carrier on the first line and the message on the second line. Explanation:



    +`(.)(1*)1*(.*¶)(?(1)(1(2)))(.*)$(?!¶)
    $1$4$5¶$3$6


    Process runs of 1 or more identical characters of the carrier. If there is also a run of 1 or more of the same characters in the message, then append the shorter of the two runs to the output in duplicate, otherwise append a single character of the carrier to the output. Each run of output characters is terminated with a newline to distinguish it from the input. The (?!¶) at the end prevents the regex from thinking the carrier is the message once the message is exhausted, as normally $ is allowed to match where ¶$ would match.



    M!s`.*¶$


    Delete everything if the message wasn't completely encoded.







    Remove the newlines from the output.






    share|improve this answer























    • I think it does not pass the second to last test case (which, to be fair, I did not have in the initial post).
      – jkpate
      2 days ago










    • @jkpate Thanks for pointing that out; I've had to rewrite my approach slightly.
      – Neil
      2 days ago


















    up vote
    0
    down vote














    Clean, 118 bytes



    import StdEnv,StdLib
    $=
    $[u:v]b#(_,w)=span((==)u)v
    |b%(0,0)==[u]=[u,u: $if(v%(0,0)<>b%(1,1))w v(tl b)]=[u: $w b]


    Try it online!



    Takes the carrier first, then the message.



    Errors with Run time error, rule '$;2' in module 'main' does not match if message won't fit.






    share|improve this answer




























      up vote
      0
      down vote














      Ruby, 73 bytes





      f=->m,c,b=p{x,*c=c;x ?(x==m[0]?x+m.shift: x==b ?'':x)+f[m,c,x]:m[0]?x:''}


      Try it online!



      Recursive function, takes inputs as array of characters.



      For once I was hoping to make use of Ruby's built-in squeeze method that contracts consecutive runs of the same character to a single instance. But unfortunately, nope - the last two test cases screwed everything so badly, that I had to resort to a completely different approach, and this turned out to be basically a port of Arnauld's answer.






      share|improve this answer




























        up vote
        0
        down vote













        Powershell, 134 bytes





        param($m,$c)$c-csplit"([$m])"|%{$i+=$o=$_-ceq$m[+$i]
        if($o-or$_-cne"`0$h"[-1]){$h+=($_-replace'(.)(?=1)')*($o+1)}}
        $h*!($i-$m.Length)


        The script returns the empty string if the carrier does not contain the message characters in the right order.



        Less golfed test script:



        $f = {

        param($message,$carrier)
        $carrier-csplit"([$message])"|%{ # split by chars of the message, chars itself included ()
        $offset=$_-ceq$message[+$i] # 0 or 1 if current substring is a current message char (case-sensitive equality)
        $i+=$offset # move to next message char if need it
        if($offset-or$_-cne"`0$h"[-1]){ # condition to remove redundant doubles after message char: arrrived -> arrived, ooo -> oo, etc
        # `0 to avoid exception error if $h is empty
        $h+=($_-replace'(.)(?=1)')*($offset+1) # accumulate a double message char or a single substring without inner doubles: arried -> arived, anna -> ana, etc
        }
        }
        $h*!($i-$message.Length) # repeat 0 or 1 times to return '' if the carrier does not contain the message characters in the right order

        }

        @(
        ,('hi' ,'has it arrived?' ,'hhas iit arived?', 'hhas it ariived?')
        ,('hi?' ,'has it arrived?' ,'hhas iit arived??', 'hhas it ariived??')
        ,('sir' ,'has it arrived?' ,'hass iit arrived?')
        ,('foo' ,'has it arrived?' ,'')
        ,('Car' ,'Cats are cool.' ,'CCaats arre col.')
        ,('car' ,'Cats are cool.' ,'')
        ,('Couch' ,'Couch' ,'CCoouucchh')
        ,('oo' ,'oooooooooo' ,'oooo')
        ,('o o' ,'oooo oooa' ,'oo ooa')
        ,('er' ,'error' ,'eerorr', 'eerror')
        ,('a+b' ,'anna+bob' ,'aana++bbob')
        ) | % {
        $message,$carrier,$expected = $_
        $result = &$f $message $carrier
        "$($result-in$expected): $result"
        }


        Output:





        True: hhas iit arived?
        True: hhas iit arived??
        True: hass iit arrived?
        True:
        True: CCaats arre col.
        True:
        True: CCoouucchh
        True: oooo
        True: oo ooa
        True: eerror
        True: aana++bbob





        share|improve this answer























          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "200"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          jkpate is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177212%2fdoubled-letter-steganography%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          7 Answers
          7






          active

          oldest

          votes








          7 Answers
          7






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote














          Jelly, 28 bytes



          ẹⱮŒp<ƝẠ$ƇṪ
          nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç?


          A full program taking carrier and message as command line arguments which prints the result

          (For a non-packable message prints the unchanged carrier).



          Try it online! Or see the test-suite.



          How?



          ẹⱮŒp<ƝẠ$ƇṪ - Link 1, helper function to find the indices to double: carrier, message
          - e.g. "programming", "rom"
          Ɱ - map across message with:
          ẹ - indices of [[2,5], [3], [7,8]]
          Œp - Cartesian product [[2,3,7],[2,3,8],[5,3,7],[5,3,8]]
          Ƈ - filter keep if:
          $ - last two links as a monad:
          Ɲ - for neighbours:
          < - less than? [1,1] [1,1] [0,1] [0,1]
          Ạ - all truthy? 1 1 0 0
          - [[2,3,7],[2,3,8]]
          Ṫ - tail (if empty yields 0) [2,3,8]

          nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç? - Main Link: carrier, message
          ? - if...
          ç - ...condition: last Link (the helper function) as a dyad
          ð - ...then: perform the dyadic chain to the left (described below)
          ¹ - ...else: do nothing (yields carrier)
          - (the then clause:)
          Ɲ - for neighbours in the carrier
          n - not equal?
          ¥ - last two links as a dyad:
          ç - call last Link (the helper function) as a dyad
          Ṭ - untruth (e.g. [2,5] -> [0,1,0,0,1])
          + - add (vectorises)
          a⁸ - logical AND with carrier
          ḟ0 - filter out zeros
          ¦ - sparse application...
          ç - ...to indices: call last Link (the helper function) as a dyad
          Ḥ - ...do: double (e.g. 'x' -> 'xx')





          share|improve this answer



























            up vote
            4
            down vote














            Jelly, 28 bytes



            ẹⱮŒp<ƝẠ$ƇṪ
            nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç?


            A full program taking carrier and message as command line arguments which prints the result

            (For a non-packable message prints the unchanged carrier).



            Try it online! Or see the test-suite.



            How?



            ẹⱮŒp<ƝẠ$ƇṪ - Link 1, helper function to find the indices to double: carrier, message
            - e.g. "programming", "rom"
            Ɱ - map across message with:
            ẹ - indices of [[2,5], [3], [7,8]]
            Œp - Cartesian product [[2,3,7],[2,3,8],[5,3,7],[5,3,8]]
            Ƈ - filter keep if:
            $ - last two links as a monad:
            Ɲ - for neighbours:
            < - less than? [1,1] [1,1] [0,1] [0,1]
            Ạ - all truthy? 1 1 0 0
            - [[2,3,7],[2,3,8]]
            Ṫ - tail (if empty yields 0) [2,3,8]

            nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç? - Main Link: carrier, message
            ? - if...
            ç - ...condition: last Link (the helper function) as a dyad
            ð - ...then: perform the dyadic chain to the left (described below)
            ¹ - ...else: do nothing (yields carrier)
            - (the then clause:)
            Ɲ - for neighbours in the carrier
            n - not equal?
            ¥ - last two links as a dyad:
            ç - call last Link (the helper function) as a dyad
            Ṭ - untruth (e.g. [2,5] -> [0,1,0,0,1])
            + - add (vectorises)
            a⁸ - logical AND with carrier
            ḟ0 - filter out zeros
            ¦ - sparse application...
            ç - ...to indices: call last Link (the helper function) as a dyad
            Ḥ - ...do: double (e.g. 'x' -> 'xx')





            share|improve this answer

























              up vote
              4
              down vote










              up vote
              4
              down vote










              Jelly, 28 bytes



              ẹⱮŒp<ƝẠ$ƇṪ
              nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç?


              A full program taking carrier and message as command line arguments which prints the result

              (For a non-packable message prints the unchanged carrier).



              Try it online! Or see the test-suite.



              How?



              ẹⱮŒp<ƝẠ$ƇṪ - Link 1, helper function to find the indices to double: carrier, message
              - e.g. "programming", "rom"
              Ɱ - map across message with:
              ẹ - indices of [[2,5], [3], [7,8]]
              Œp - Cartesian product [[2,3,7],[2,3,8],[5,3,7],[5,3,8]]
              Ƈ - filter keep if:
              $ - last two links as a monad:
              Ɲ - for neighbours:
              < - less than? [1,1] [1,1] [0,1] [0,1]
              Ạ - all truthy? 1 1 0 0
              - [[2,3,7],[2,3,8]]
              Ṫ - tail (if empty yields 0) [2,3,8]

              nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç? - Main Link: carrier, message
              ? - if...
              ç - ...condition: last Link (the helper function) as a dyad
              ð - ...then: perform the dyadic chain to the left (described below)
              ¹ - ...else: do nothing (yields carrier)
              - (the then clause:)
              Ɲ - for neighbours in the carrier
              n - not equal?
              ¥ - last two links as a dyad:
              ç - call last Link (the helper function) as a dyad
              Ṭ - untruth (e.g. [2,5] -> [0,1,0,0,1])
              + - add (vectorises)
              a⁸ - logical AND with carrier
              ḟ0 - filter out zeros
              ¦ - sparse application...
              ç - ...to indices: call last Link (the helper function) as a dyad
              Ḥ - ...do: double (e.g. 'x' -> 'xx')





              share|improve this answer















              Jelly, 28 bytes



              ẹⱮŒp<ƝẠ$ƇṪ
              nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç?


              A full program taking carrier and message as command line arguments which prints the result

              (For a non-packable message prints the unchanged carrier).



              Try it online! Or see the test-suite.



              How?



              ẹⱮŒp<ƝẠ$ƇṪ - Link 1, helper function to find the indices to double: carrier, message
              - e.g. "programming", "rom"
              Ɱ - map across message with:
              ẹ - indices of [[2,5], [3], [7,8]]
              Œp - Cartesian product [[2,3,7],[2,3,8],[5,3,7],[5,3,8]]
              Ƈ - filter keep if:
              $ - last two links as a monad:
              Ɲ - for neighbours:
              < - less than? [1,1] [1,1] [0,1] [0,1]
              Ạ - all truthy? 1 1 0 0
              - [[2,3,7],[2,3,8]]
              Ṫ - tail (if empty yields 0) [2,3,8]

              nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç? - Main Link: carrier, message
              ? - if...
              ç - ...condition: last Link (the helper function) as a dyad
              ð - ...then: perform the dyadic chain to the left (described below)
              ¹ - ...else: do nothing (yields carrier)
              - (the then clause:)
              Ɲ - for neighbours in the carrier
              n - not equal?
              ¥ - last two links as a dyad:
              ç - call last Link (the helper function) as a dyad
              Ṭ - untruth (e.g. [2,5] -> [0,1,0,0,1])
              + - add (vectorises)
              a⁸ - logical AND with carrier
              ḟ0 - filter out zeros
              ¦ - sparse application...
              ç - ...to indices: call last Link (the helper function) as a dyad
              Ḥ - ...do: double (e.g. 'x' -> 'xx')






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 2 days ago

























              answered 2 days ago









              Jonathan Allan

              50.5k534165




              50.5k534165






















                  up vote
                  3
                  down vote













                  JavaScript (ES6), 75 bytes



                  Takes input as (message)(carrier).





                  s=>g=([c,...C],p)=>c?(c==s[0]?(s=s.slice(1),p=c)+c:p==c?'':p=c)+g(C,c):s&&X


                  Try it online!





                  Alternate version, 72 bytes



                  If we can take the message as an array of characters:



                  s=>g=([c,...C],p)=>c?(c==s[0]?(p=s.shift())+c:p==c?'':p=c)+g(C,c):s+s&&X


                  Try it online!






                  share|improve this answer























                  • You could remove p= since p is passed by a parameter.
                    – tsh
                    1 hour ago

















                  up vote
                  3
                  down vote













                  JavaScript (ES6), 75 bytes



                  Takes input as (message)(carrier).





                  s=>g=([c,...C],p)=>c?(c==s[0]?(s=s.slice(1),p=c)+c:p==c?'':p=c)+g(C,c):s&&X


                  Try it online!





                  Alternate version, 72 bytes



                  If we can take the message as an array of characters:



                  s=>g=([c,...C],p)=>c?(c==s[0]?(p=s.shift())+c:p==c?'':p=c)+g(C,c):s+s&&X


                  Try it online!






                  share|improve this answer























                  • You could remove p= since p is passed by a parameter.
                    – tsh
                    1 hour ago















                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  JavaScript (ES6), 75 bytes



                  Takes input as (message)(carrier).





                  s=>g=([c,...C],p)=>c?(c==s[0]?(s=s.slice(1),p=c)+c:p==c?'':p=c)+g(C,c):s&&X


                  Try it online!





                  Alternate version, 72 bytes



                  If we can take the message as an array of characters:



                  s=>g=([c,...C],p)=>c?(c==s[0]?(p=s.shift())+c:p==c?'':p=c)+g(C,c):s+s&&X


                  Try it online!






                  share|improve this answer














                  JavaScript (ES6), 75 bytes



                  Takes input as (message)(carrier).





                  s=>g=([c,...C],p)=>c?(c==s[0]?(s=s.slice(1),p=c)+c:p==c?'':p=c)+g(C,c):s&&X


                  Try it online!





                  Alternate version, 72 bytes



                  If we can take the message as an array of characters:



                  s=>g=([c,...C],p)=>c?(c==s[0]?(p=s.shift())+c:p==c?'':p=c)+g(C,c):s+s&&X


                  Try it online!







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 2 days ago

























                  answered 2 days ago









                  Arnauld

                  70.9k688298




                  70.9k688298












                  • You could remove p= since p is passed by a parameter.
                    – tsh
                    1 hour ago




















                  • You could remove p= since p is passed by a parameter.
                    – tsh
                    1 hour ago


















                  You could remove p= since p is passed by a parameter.
                  – tsh
                  1 hour ago






                  You could remove p= since p is passed by a parameter.
                  – tsh
                  1 hour ago












                  up vote
                  2
                  down vote













                  Haskell, 124 121 107 101 97 95 90 bytes



                  (#).(++"ü")
                  "ü"#=
                  p@(m:n)#e@(c:d)|m/=c=c:p#snd(span(==c)d)|m==n!!0=m:m:n#d|1<2=m:n#e


                  Raises the "Non-exhaustive patterns" exception if the carrier does not contain the message.



                  Try it online!



                  Edit: -5 bytes thanks to @Laikoni.






                  share|improve this answer























                  • I think switching the cases allows you to drop m==c: Try it online!
                    – Laikoni
                    yesterday

















                  up vote
                  2
                  down vote













                  Haskell, 124 121 107 101 97 95 90 bytes



                  (#).(++"ü")
                  "ü"#=
                  p@(m:n)#e@(c:d)|m/=c=c:p#snd(span(==c)d)|m==n!!0=m:m:n#d|1<2=m:n#e


                  Raises the "Non-exhaustive patterns" exception if the carrier does not contain the message.



                  Try it online!



                  Edit: -5 bytes thanks to @Laikoni.






                  share|improve this answer























                  • I think switching the cases allows you to drop m==c: Try it online!
                    – Laikoni
                    yesterday















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  Haskell, 124 121 107 101 97 95 90 bytes



                  (#).(++"ü")
                  "ü"#=
                  p@(m:n)#e@(c:d)|m/=c=c:p#snd(span(==c)d)|m==n!!0=m:m:n#d|1<2=m:n#e


                  Raises the "Non-exhaustive patterns" exception if the carrier does not contain the message.



                  Try it online!



                  Edit: -5 bytes thanks to @Laikoni.






                  share|improve this answer














                  Haskell, 124 121 107 101 97 95 90 bytes



                  (#).(++"ü")
                  "ü"#=
                  p@(m:n)#e@(c:d)|m/=c=c:p#snd(span(==c)d)|m==n!!0=m:m:n#d|1<2=m:n#e


                  Raises the "Non-exhaustive patterns" exception if the carrier does not contain the message.



                  Try it online!



                  Edit: -5 bytes thanks to @Laikoni.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited yesterday

























                  answered 2 days ago









                  nimi

                  31k31985




                  31k31985












                  • I think switching the cases allows you to drop m==c: Try it online!
                    – Laikoni
                    yesterday




















                  • I think switching the cases allows you to drop m==c: Try it online!
                    – Laikoni
                    yesterday


















                  I think switching the cases allows you to drop m==c: Try it online!
                  – Laikoni
                  yesterday






                  I think switching the cases allows you to drop m==c: Try it online!
                  – Laikoni
                  yesterday












                  up vote
                  1
                  down vote














                  Retina 0.8.2, 67 bytes



                  +`(.)(1*)1*(.*¶)(?(1)(1(2)))(.*)$(?!¶)
                  $1$4$5¶$3$6
                  M!s`.*¶$




                  Try it online! Takes the carrier on the first line and the message on the second line. Explanation:



                  +`(.)(1*)1*(.*¶)(?(1)(1(2)))(.*)$(?!¶)
                  $1$4$5¶$3$6


                  Process runs of 1 or more identical characters of the carrier. If there is also a run of 1 or more of the same characters in the message, then append the shorter of the two runs to the output in duplicate, otherwise append a single character of the carrier to the output. Each run of output characters is terminated with a newline to distinguish it from the input. The (?!¶) at the end prevents the regex from thinking the carrier is the message once the message is exhausted, as normally $ is allowed to match where ¶$ would match.



                  M!s`.*¶$


                  Delete everything if the message wasn't completely encoded.







                  Remove the newlines from the output.






                  share|improve this answer























                  • I think it does not pass the second to last test case (which, to be fair, I did not have in the initial post).
                    – jkpate
                    2 days ago










                  • @jkpate Thanks for pointing that out; I've had to rewrite my approach slightly.
                    – Neil
                    2 days ago















                  up vote
                  1
                  down vote














                  Retina 0.8.2, 67 bytes



                  +`(.)(1*)1*(.*¶)(?(1)(1(2)))(.*)$(?!¶)
                  $1$4$5¶$3$6
                  M!s`.*¶$




                  Try it online! Takes the carrier on the first line and the message on the second line. Explanation:



                  +`(.)(1*)1*(.*¶)(?(1)(1(2)))(.*)$(?!¶)
                  $1$4$5¶$3$6


                  Process runs of 1 or more identical characters of the carrier. If there is also a run of 1 or more of the same characters in the message, then append the shorter of the two runs to the output in duplicate, otherwise append a single character of the carrier to the output. Each run of output characters is terminated with a newline to distinguish it from the input. The (?!¶) at the end prevents the regex from thinking the carrier is the message once the message is exhausted, as normally $ is allowed to match where ¶$ would match.



                  M!s`.*¶$


                  Delete everything if the message wasn't completely encoded.







                  Remove the newlines from the output.






                  share|improve this answer























                  • I think it does not pass the second to last test case (which, to be fair, I did not have in the initial post).
                    – jkpate
                    2 days ago










                  • @jkpate Thanks for pointing that out; I've had to rewrite my approach slightly.
                    – Neil
                    2 days ago













                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote










                  Retina 0.8.2, 67 bytes



                  +`(.)(1*)1*(.*¶)(?(1)(1(2)))(.*)$(?!¶)
                  $1$4$5¶$3$6
                  M!s`.*¶$




                  Try it online! Takes the carrier on the first line and the message on the second line. Explanation:



                  +`(.)(1*)1*(.*¶)(?(1)(1(2)))(.*)$(?!¶)
                  $1$4$5¶$3$6


                  Process runs of 1 or more identical characters of the carrier. If there is also a run of 1 or more of the same characters in the message, then append the shorter of the two runs to the output in duplicate, otherwise append a single character of the carrier to the output. Each run of output characters is terminated with a newline to distinguish it from the input. The (?!¶) at the end prevents the regex from thinking the carrier is the message once the message is exhausted, as normally $ is allowed to match where ¶$ would match.



                  M!s`.*¶$


                  Delete everything if the message wasn't completely encoded.







                  Remove the newlines from the output.






                  share|improve this answer















                  Retina 0.8.2, 67 bytes



                  +`(.)(1*)1*(.*¶)(?(1)(1(2)))(.*)$(?!¶)
                  $1$4$5¶$3$6
                  M!s`.*¶$




                  Try it online! Takes the carrier on the first line and the message on the second line. Explanation:



                  +`(.)(1*)1*(.*¶)(?(1)(1(2)))(.*)$(?!¶)
                  $1$4$5¶$3$6


                  Process runs of 1 or more identical characters of the carrier. If there is also a run of 1 or more of the same characters in the message, then append the shorter of the two runs to the output in duplicate, otherwise append a single character of the carrier to the output. Each run of output characters is terminated with a newline to distinguish it from the input. The (?!¶) at the end prevents the regex from thinking the carrier is the message once the message is exhausted, as normally $ is allowed to match where ¶$ would match.



                  M!s`.*¶$


                  Delete everything if the message wasn't completely encoded.







                  Remove the newlines from the output.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 2 days ago

























                  answered 2 days ago









                  Neil

                  78.6k744175




                  78.6k744175












                  • I think it does not pass the second to last test case (which, to be fair, I did not have in the initial post).
                    – jkpate
                    2 days ago










                  • @jkpate Thanks for pointing that out; I've had to rewrite my approach slightly.
                    – Neil
                    2 days ago


















                  • I think it does not pass the second to last test case (which, to be fair, I did not have in the initial post).
                    – jkpate
                    2 days ago










                  • @jkpate Thanks for pointing that out; I've had to rewrite my approach slightly.
                    – Neil
                    2 days ago
















                  I think it does not pass the second to last test case (which, to be fair, I did not have in the initial post).
                  – jkpate
                  2 days ago




                  I think it does not pass the second to last test case (which, to be fair, I did not have in the initial post).
                  – jkpate
                  2 days ago












                  @jkpate Thanks for pointing that out; I've had to rewrite my approach slightly.
                  – Neil
                  2 days ago




                  @jkpate Thanks for pointing that out; I've had to rewrite my approach slightly.
                  – Neil
                  2 days ago










                  up vote
                  0
                  down vote














                  Clean, 118 bytes



                  import StdEnv,StdLib
                  $=
                  $[u:v]b#(_,w)=span((==)u)v
                  |b%(0,0)==[u]=[u,u: $if(v%(0,0)<>b%(1,1))w v(tl b)]=[u: $w b]


                  Try it online!



                  Takes the carrier first, then the message.



                  Errors with Run time error, rule '$;2' in module 'main' does not match if message won't fit.






                  share|improve this answer

























                    up vote
                    0
                    down vote














                    Clean, 118 bytes



                    import StdEnv,StdLib
                    $=
                    $[u:v]b#(_,w)=span((==)u)v
                    |b%(0,0)==[u]=[u,u: $if(v%(0,0)<>b%(1,1))w v(tl b)]=[u: $w b]


                    Try it online!



                    Takes the carrier first, then the message.



                    Errors with Run time error, rule '$;2' in module 'main' does not match if message won't fit.






                    share|improve this answer























                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote










                      Clean, 118 bytes



                      import StdEnv,StdLib
                      $=
                      $[u:v]b#(_,w)=span((==)u)v
                      |b%(0,0)==[u]=[u,u: $if(v%(0,0)<>b%(1,1))w v(tl b)]=[u: $w b]


                      Try it online!



                      Takes the carrier first, then the message.



                      Errors with Run time error, rule '$;2' in module 'main' does not match if message won't fit.






                      share|improve this answer













                      Clean, 118 bytes



                      import StdEnv,StdLib
                      $=
                      $[u:v]b#(_,w)=span((==)u)v
                      |b%(0,0)==[u]=[u,u: $if(v%(0,0)<>b%(1,1))w v(tl b)]=[u: $w b]


                      Try it online!



                      Takes the carrier first, then the message.



                      Errors with Run time error, rule '$;2' in module 'main' does not match if message won't fit.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 23 hours ago









                      Οurous

                      6,11311032




                      6,11311032






















                          up vote
                          0
                          down vote














                          Ruby, 73 bytes





                          f=->m,c,b=p{x,*c=c;x ?(x==m[0]?x+m.shift: x==b ?'':x)+f[m,c,x]:m[0]?x:''}


                          Try it online!



                          Recursive function, takes inputs as array of characters.



                          For once I was hoping to make use of Ruby's built-in squeeze method that contracts consecutive runs of the same character to a single instance. But unfortunately, nope - the last two test cases screwed everything so badly, that I had to resort to a completely different approach, and this turned out to be basically a port of Arnauld's answer.






                          share|improve this answer

























                            up vote
                            0
                            down vote














                            Ruby, 73 bytes





                            f=->m,c,b=p{x,*c=c;x ?(x==m[0]?x+m.shift: x==b ?'':x)+f[m,c,x]:m[0]?x:''}


                            Try it online!



                            Recursive function, takes inputs as array of characters.



                            For once I was hoping to make use of Ruby's built-in squeeze method that contracts consecutive runs of the same character to a single instance. But unfortunately, nope - the last two test cases screwed everything so badly, that I had to resort to a completely different approach, and this turned out to be basically a port of Arnauld's answer.






                            share|improve this answer























                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote










                              Ruby, 73 bytes





                              f=->m,c,b=p{x,*c=c;x ?(x==m[0]?x+m.shift: x==b ?'':x)+f[m,c,x]:m[0]?x:''}


                              Try it online!



                              Recursive function, takes inputs as array of characters.



                              For once I was hoping to make use of Ruby's built-in squeeze method that contracts consecutive runs of the same character to a single instance. But unfortunately, nope - the last two test cases screwed everything so badly, that I had to resort to a completely different approach, and this turned out to be basically a port of Arnauld's answer.






                              share|improve this answer













                              Ruby, 73 bytes





                              f=->m,c,b=p{x,*c=c;x ?(x==m[0]?x+m.shift: x==b ?'':x)+f[m,c,x]:m[0]?x:''}


                              Try it online!



                              Recursive function, takes inputs as array of characters.



                              For once I was hoping to make use of Ruby's built-in squeeze method that contracts consecutive runs of the same character to a single instance. But unfortunately, nope - the last two test cases screwed everything so badly, that I had to resort to a completely different approach, and this turned out to be basically a port of Arnauld's answer.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 15 hours ago









                              Kirill L.

                              3,4051118




                              3,4051118






















                                  up vote
                                  0
                                  down vote













                                  Powershell, 134 bytes





                                  param($m,$c)$c-csplit"([$m])"|%{$i+=$o=$_-ceq$m[+$i]
                                  if($o-or$_-cne"`0$h"[-1]){$h+=($_-replace'(.)(?=1)')*($o+1)}}
                                  $h*!($i-$m.Length)


                                  The script returns the empty string if the carrier does not contain the message characters in the right order.



                                  Less golfed test script:



                                  $f = {

                                  param($message,$carrier)
                                  $carrier-csplit"([$message])"|%{ # split by chars of the message, chars itself included ()
                                  $offset=$_-ceq$message[+$i] # 0 or 1 if current substring is a current message char (case-sensitive equality)
                                  $i+=$offset # move to next message char if need it
                                  if($offset-or$_-cne"`0$h"[-1]){ # condition to remove redundant doubles after message char: arrrived -> arrived, ooo -> oo, etc
                                  # `0 to avoid exception error if $h is empty
                                  $h+=($_-replace'(.)(?=1)')*($offset+1) # accumulate a double message char or a single substring without inner doubles: arried -> arived, anna -> ana, etc
                                  }
                                  }
                                  $h*!($i-$message.Length) # repeat 0 or 1 times to return '' if the carrier does not contain the message characters in the right order

                                  }

                                  @(
                                  ,('hi' ,'has it arrived?' ,'hhas iit arived?', 'hhas it ariived?')
                                  ,('hi?' ,'has it arrived?' ,'hhas iit arived??', 'hhas it ariived??')
                                  ,('sir' ,'has it arrived?' ,'hass iit arrived?')
                                  ,('foo' ,'has it arrived?' ,'')
                                  ,('Car' ,'Cats are cool.' ,'CCaats arre col.')
                                  ,('car' ,'Cats are cool.' ,'')
                                  ,('Couch' ,'Couch' ,'CCoouucchh')
                                  ,('oo' ,'oooooooooo' ,'oooo')
                                  ,('o o' ,'oooo oooa' ,'oo ooa')
                                  ,('er' ,'error' ,'eerorr', 'eerror')
                                  ,('a+b' ,'anna+bob' ,'aana++bbob')
                                  ) | % {
                                  $message,$carrier,$expected = $_
                                  $result = &$f $message $carrier
                                  "$($result-in$expected): $result"
                                  }


                                  Output:





                                  True: hhas iit arived?
                                  True: hhas iit arived??
                                  True: hass iit arrived?
                                  True:
                                  True: CCaats arre col.
                                  True:
                                  True: CCoouucchh
                                  True: oooo
                                  True: oo ooa
                                  True: eerror
                                  True: aana++bbob





                                  share|improve this answer



























                                    up vote
                                    0
                                    down vote













                                    Powershell, 134 bytes





                                    param($m,$c)$c-csplit"([$m])"|%{$i+=$o=$_-ceq$m[+$i]
                                    if($o-or$_-cne"`0$h"[-1]){$h+=($_-replace'(.)(?=1)')*($o+1)}}
                                    $h*!($i-$m.Length)


                                    The script returns the empty string if the carrier does not contain the message characters in the right order.



                                    Less golfed test script:



                                    $f = {

                                    param($message,$carrier)
                                    $carrier-csplit"([$message])"|%{ # split by chars of the message, chars itself included ()
                                    $offset=$_-ceq$message[+$i] # 0 or 1 if current substring is a current message char (case-sensitive equality)
                                    $i+=$offset # move to next message char if need it
                                    if($offset-or$_-cne"`0$h"[-1]){ # condition to remove redundant doubles after message char: arrrived -> arrived, ooo -> oo, etc
                                    # `0 to avoid exception error if $h is empty
                                    $h+=($_-replace'(.)(?=1)')*($offset+1) # accumulate a double message char or a single substring without inner doubles: arried -> arived, anna -> ana, etc
                                    }
                                    }
                                    $h*!($i-$message.Length) # repeat 0 or 1 times to return '' if the carrier does not contain the message characters in the right order

                                    }

                                    @(
                                    ,('hi' ,'has it arrived?' ,'hhas iit arived?', 'hhas it ariived?')
                                    ,('hi?' ,'has it arrived?' ,'hhas iit arived??', 'hhas it ariived??')
                                    ,('sir' ,'has it arrived?' ,'hass iit arrived?')
                                    ,('foo' ,'has it arrived?' ,'')
                                    ,('Car' ,'Cats are cool.' ,'CCaats arre col.')
                                    ,('car' ,'Cats are cool.' ,'')
                                    ,('Couch' ,'Couch' ,'CCoouucchh')
                                    ,('oo' ,'oooooooooo' ,'oooo')
                                    ,('o o' ,'oooo oooa' ,'oo ooa')
                                    ,('er' ,'error' ,'eerorr', 'eerror')
                                    ,('a+b' ,'anna+bob' ,'aana++bbob')
                                    ) | % {
                                    $message,$carrier,$expected = $_
                                    $result = &$f $message $carrier
                                    "$($result-in$expected): $result"
                                    }


                                    Output:





                                    True: hhas iit arived?
                                    True: hhas iit arived??
                                    True: hass iit arrived?
                                    True:
                                    True: CCaats arre col.
                                    True:
                                    True: CCoouucchh
                                    True: oooo
                                    True: oo ooa
                                    True: eerror
                                    True: aana++bbob





                                    share|improve this answer

























                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      Powershell, 134 bytes





                                      param($m,$c)$c-csplit"([$m])"|%{$i+=$o=$_-ceq$m[+$i]
                                      if($o-or$_-cne"`0$h"[-1]){$h+=($_-replace'(.)(?=1)')*($o+1)}}
                                      $h*!($i-$m.Length)


                                      The script returns the empty string if the carrier does not contain the message characters in the right order.



                                      Less golfed test script:



                                      $f = {

                                      param($message,$carrier)
                                      $carrier-csplit"([$message])"|%{ # split by chars of the message, chars itself included ()
                                      $offset=$_-ceq$message[+$i] # 0 or 1 if current substring is a current message char (case-sensitive equality)
                                      $i+=$offset # move to next message char if need it
                                      if($offset-or$_-cne"`0$h"[-1]){ # condition to remove redundant doubles after message char: arrrived -> arrived, ooo -> oo, etc
                                      # `0 to avoid exception error if $h is empty
                                      $h+=($_-replace'(.)(?=1)')*($offset+1) # accumulate a double message char or a single substring without inner doubles: arried -> arived, anna -> ana, etc
                                      }
                                      }
                                      $h*!($i-$message.Length) # repeat 0 or 1 times to return '' if the carrier does not contain the message characters in the right order

                                      }

                                      @(
                                      ,('hi' ,'has it arrived?' ,'hhas iit arived?', 'hhas it ariived?')
                                      ,('hi?' ,'has it arrived?' ,'hhas iit arived??', 'hhas it ariived??')
                                      ,('sir' ,'has it arrived?' ,'hass iit arrived?')
                                      ,('foo' ,'has it arrived?' ,'')
                                      ,('Car' ,'Cats are cool.' ,'CCaats arre col.')
                                      ,('car' ,'Cats are cool.' ,'')
                                      ,('Couch' ,'Couch' ,'CCoouucchh')
                                      ,('oo' ,'oooooooooo' ,'oooo')
                                      ,('o o' ,'oooo oooa' ,'oo ooa')
                                      ,('er' ,'error' ,'eerorr', 'eerror')
                                      ,('a+b' ,'anna+bob' ,'aana++bbob')
                                      ) | % {
                                      $message,$carrier,$expected = $_
                                      $result = &$f $message $carrier
                                      "$($result-in$expected): $result"
                                      }


                                      Output:





                                      True: hhas iit arived?
                                      True: hhas iit arived??
                                      True: hass iit arrived?
                                      True:
                                      True: CCaats arre col.
                                      True:
                                      True: CCoouucchh
                                      True: oooo
                                      True: oo ooa
                                      True: eerror
                                      True: aana++bbob





                                      share|improve this answer














                                      Powershell, 134 bytes





                                      param($m,$c)$c-csplit"([$m])"|%{$i+=$o=$_-ceq$m[+$i]
                                      if($o-or$_-cne"`0$h"[-1]){$h+=($_-replace'(.)(?=1)')*($o+1)}}
                                      $h*!($i-$m.Length)


                                      The script returns the empty string if the carrier does not contain the message characters in the right order.



                                      Less golfed test script:



                                      $f = {

                                      param($message,$carrier)
                                      $carrier-csplit"([$message])"|%{ # split by chars of the message, chars itself included ()
                                      $offset=$_-ceq$message[+$i] # 0 or 1 if current substring is a current message char (case-sensitive equality)
                                      $i+=$offset # move to next message char if need it
                                      if($offset-or$_-cne"`0$h"[-1]){ # condition to remove redundant doubles after message char: arrrived -> arrived, ooo -> oo, etc
                                      # `0 to avoid exception error if $h is empty
                                      $h+=($_-replace'(.)(?=1)')*($offset+1) # accumulate a double message char or a single substring without inner doubles: arried -> arived, anna -> ana, etc
                                      }
                                      }
                                      $h*!($i-$message.Length) # repeat 0 or 1 times to return '' if the carrier does not contain the message characters in the right order

                                      }

                                      @(
                                      ,('hi' ,'has it arrived?' ,'hhas iit arived?', 'hhas it ariived?')
                                      ,('hi?' ,'has it arrived?' ,'hhas iit arived??', 'hhas it ariived??')
                                      ,('sir' ,'has it arrived?' ,'hass iit arrived?')
                                      ,('foo' ,'has it arrived?' ,'')
                                      ,('Car' ,'Cats are cool.' ,'CCaats arre col.')
                                      ,('car' ,'Cats are cool.' ,'')
                                      ,('Couch' ,'Couch' ,'CCoouucchh')
                                      ,('oo' ,'oooooooooo' ,'oooo')
                                      ,('o o' ,'oooo oooa' ,'oo ooa')
                                      ,('er' ,'error' ,'eerorr', 'eerror')
                                      ,('a+b' ,'anna+bob' ,'aana++bbob')
                                      ) | % {
                                      $message,$carrier,$expected = $_
                                      $result = &$f $message $carrier
                                      "$($result-in$expected): $result"
                                      }


                                      Output:





                                      True: hhas iit arived?
                                      True: hhas iit arived??
                                      True: hass iit arrived?
                                      True:
                                      True: CCaats arre col.
                                      True:
                                      True: CCoouucchh
                                      True: oooo
                                      True: oo ooa
                                      True: eerror
                                      True: aana++bbob






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited 6 hours ago

























                                      answered 6 hours ago









                                      mazzy

                                      1,947313




                                      1,947313






















                                          jkpate is a new contributor. Be nice, and check out our Code of Conduct.










                                          draft saved

                                          draft discarded


















                                          jkpate is a new contributor. Be nice, and check out our Code of Conduct.













                                          jkpate is a new contributor. Be nice, and check out our Code of Conduct.












                                          jkpate is a new contributor. Be nice, and check out our Code of Conduct.
















                                          If this is an answer to a challenge…




                                          • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                          • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                            Explanations of your answer make it more interesting to read and are very much encouraged.


                                          • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                          More generally…




                                          • …Please make sure to answer the question and provide sufficient detail.


                                          • …Avoid asking for help, clarification or responding to other answers (use comments instead).






                                          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                          Please pay close attention to the following guidance:


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177212%2fdoubled-letter-steganography%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Plaza Victoria

                                          In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                                          How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...