79
\$\begingroup\$

Super simple challenge today, or is it?

I feel like we've heard a fair bit about double speak recently, well let's define it in a codable way...

Double speak is when each and every character in a string of text is immediately repeated. For example:

"DDoouubbllee  ssppeeaakk!!"

The Rules

  • Write code which accepts one argument, a string.
  • It will modify this string, duplicating every character.
  • Then it will return the double speak version of the string.
  • It's code golf, try to achieve this in the smallest number of bytes.
  • Please include a link to an online interpreter for your code.
  • Input strings will only contain characters in the printable ASCII range. Reference: http://www.asciitable.com/mobile/

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

var QUESTION_ID=188988;
var OVERRIDE_USER=53748;
var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=asc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(d,e){return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=asc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){answers.push.apply(answers,d.items),answers_hash=[],answer_ids=[],d.items.forEach(function(e){e.comments=[];var f=+e.share_link.match(/\d+/);answer_ids.push(f),answers_hash[f]=e}),d.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){d.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),d.has_more?getComments():more_answers?getAnswers():process()}})}getAnswers();var SCORE_REG=function(){var d=String.raw`h\d`,e=String.raw`\-?\d+\.?\d*`,f=String.raw`[^\n<>]*`,g=String.raw`<s>${f}</s>|<strike>${f}</strike>|<del>${f}</del>`,h=String.raw`[^\n\d<>]*`,j=String.raw`<[^\n<>]+>`;return new RegExp(String.raw`<${d}>`+String.raw`\s*([^\n,]*[^\s,]),.*?`+String.raw`(${e})`+String.raw`(?=`+String.raw`${h}`+String.raw`(?:(?:${g}|${j})${h})*`+String.raw`</${d}>`+String.raw`)`)}(),OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(d){return d.owner.display_name}function process(){var d=[];answers.forEach(function(n){var o=n.body;n.comments.forEach(function(q){OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>")});var p=o.match(SCORE_REG);p&&d.push({user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link})}),d.sort(function(n,o){var p=n.size,q=o.size;return p-q});var e={},f=1,g=null,h=1;d.forEach(function(n){n.size!=g&&(h=f),g=n.size,++f;var o=jQuery("#answer-template").html();o=o.replace("{{PLACE}}",h+".").replace("{{NAME}}",n.user).replace("{{LANGUAGE}}",n.language).replace("{{SIZE}}",n.size).replace("{{LINK}}",n.link),o=jQuery(o),jQuery("#answers").append(o);var p=n.language;p=jQuery("<i>"+n.language+"</i>").text().toLowerCase(),e[p]=e[p]||{lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p}});var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o){return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0});for(var l=0;l<j.length;++l){var m=jQuery("#language-template").html(),k=j[l];m=m.replace("{{LANGUAGE}}",k.lang).replace("{{NAME}}",k.user).replace("{{SIZE}}",k.size).replace("{{LINK}}",k.link),m=jQuery(m),jQuery("#languages").append(m)}}
body{text-align:left!important}#answer-list{padding:10px;float:left}#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> 

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, [Other information] N bytes

where N is the size of your submission. Other information may include flags set and if you've improved your score (usually a struck out number like <s>M</s>). N should be the right-most number in this heading, and everything before the first , is the name of the language you've used. The language name and the word bytes may be links.

For example:

# [><>](http://esolangs.org/wiki/Fish), <s>162</s> 121 [bytes](https://esolangs.org/wiki/Fish#Instructions)
\$\endgroup\$
10
  • 3
    \$\begingroup\$ It will modify this string. Are you intentionally requiring pass-by-reference and modify in-place? And then return a copy or reference to that modified string? If so, languages like asm or C would need to accept an explicit-length string (pointer + length) where the length is either the current string length (with the buffer being twice that size), or it's the total size and you need to duplicate the low half. Thus you need to start from the end and work backwards, or allocate scratch space and then copy back. But there are answers in C and 8086 asm that totally violate all that. \$\endgroup\$ Aug 3 '19 at 1:49
  • 4
    \$\begingroup\$ @PeterCordes I do not care if it modifies the same object or builds a new one. \$\endgroup\$
    – AJFaraday
    Aug 3 '19 at 5:08
  • 3
    \$\begingroup\$ I'd suggest wording it as "modify (or produce a modified copy) of the string" to explicitly allow answers that do or don't modify in-place. Simplifying the wording to "return a string that's twice as long, with each character repeated" would be nice but then it's not clear if void foo(char *c, size_t len) is legal that takes one input/output buffer and a length, and doesn't have any return value, just a side-effect on the object it has a pointer to. \$\endgroup\$ Aug 3 '19 at 5:16
  • \$\begingroup\$ Can the string be empty? \$\endgroup\$ Aug 6 '19 at 19:58
  • 1
    \$\begingroup\$ @cschultz2048 it says the string will only contain printable ascii characters, so that implies that they’ll always be populated. I’d expect that any code for this challenge would leave an empty string empty... anyway, I don’t think it’s a test case that I’d use for this. \$\endgroup\$
    – AJFaraday
    Aug 6 '19 at 22:36

198 Answers 198

1 2
3
4 5
7
3
\$\begingroup\$

!@#$%^&*()_+, 12 bytes

*^(_^_!@@*^)

Try it online! If programs could terminate with an error, *(!@@*) works for 7 bytes.

Explanation

*^(_^_!@@*^)
*^                 take input, add 1
  (        )       loop until top of stack is 0
   _^_             subtract 1
      !            duplicate
       @@          output twice
         *^        take input, add 1
\$\endgroup\$
2
  • \$\begingroup\$ How do you pronounce !@#$%^&*()_+ ?? 😛 \$\endgroup\$
    – roblogic
    Aug 1 '19 at 20:45
  • 2
    \$\begingroup\$ @roblogic There are two canonical pronunciations. (1) "ek-nid-puc-ay-al-rulp" (2) "dang" \$\endgroup\$ Aug 1 '19 at 20:49
3
\$\begingroup\$

Zsh, 29 bytes

s=(${(s::)1})
<<<${(j::)s:^s}

Try it online!

I love parameter expansion flags:

s=(${(s::)1})
   ${     1}    # first argument
     (s::)      # split into characters: (s:foo:) splits on the string "foo"
s=(         )   # capture as array $s

<<<${(j::)s:^s}
   ${     s:^s} # zip array s with array s
     (j::)      # join on empty string (opposite of s::)
<<<             # print to stdout

Honorable mention, which would be 27 bytes... if not for the required 20 extra bytes to setopt extendedglob:

setopt extendedglob
<<<${1//(#m)?/$MATCH$MATCH}

This is basically the same as sed 's/./&&/g'<<<$1, but with builtins only.

Try it online!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ I was all set up to try zsh but then you made this! 🤯 \$\endgroup\$
    – roblogic
    Aug 2 '19 at 0:18
  • \$\begingroup\$ You don't need to include the setopt extendedglob - you can add it as a command line flag to zsh: --extendedglob for no extra bytes \$\endgroup\$
    – pxeger
    Jan 26 at 8:44
  • \$\begingroup\$ Alternative (29) \$\endgroup\$
    – pxeger
    Jan 26 at 10:08
  • \$\begingroup\$ @pxeger Yeah, I didn't start answering with zsh -oextendedglob with that rule until a little after this answer. Also, your alternative doesn't double backslashes. \$\endgroup\$ Jan 26 at 17:58
  • 1
    \$\begingroup\$ @GammaFunction that can be fixed with -o bsd_echo \$\endgroup\$
    – pxeger
    Jan 26 at 18:03
3
\$\begingroup\$

Swift 5, 30 bytes

thanks to @Mr.Xcoder for -14 bytes

{a in a.flatMap{"\($0)\($0)"}}

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to PPCG, nice answer! You can drop let x= and put it in the header for -6 bytes. \$\endgroup\$
    – Mr. Xcoder
    Aug 1 '19 at 8:43
  • \$\begingroup\$ @Mr.Xcoder like this? Try it online! \$\endgroup\$ Aug 1 '19 at 9:31
  • 2
    \$\begingroup\$ Yes, precisely. \$\endgroup\$
    – Mr. Xcoder
    Aug 1 '19 at 9:31
3
\$\begingroup\$

Ook!, 48 bytes

Ook.Ook!Ook!Ook?Ook!Ook.Ook!Ook.Ook.Ook!Ook?Ook!

This is just a port of my brainfuck answer. Unfortunately there is no support for Ook! on TIO, but you can use this online interpreter.

\$\endgroup\$
3
\$\begingroup\$

K (oK), 5 bytes

Solution:

,/2#'

Try it online!

Explanation:

,/2#' / the solution
  2#' / 2 take (#) each
,/    / flatten
\$\endgroup\$
3
  • 1
    \$\begingroup\$ {2}# also works \$\endgroup\$
    – ngn
    Aug 5 '19 at 17:26
  • \$\begingroup\$ Will update once I'm off mobile, can you explain how/why this one works? Why doesn't the lambda just return 2? \$\endgroup\$
    – mkst
    Aug 5 '19 at 20:01
  • \$\begingroup\$ m#l is filter (m monad, l list) - equivalent to l@&m'l \$\endgroup\$
    – ngn
    Aug 6 '19 at 6:20
3
\$\begingroup\$

Kotlin, 44 bytes

{s:String->s.map{"$it$it"}.joinToString("")}

Try it online!

\$\endgroup\$
3
\$\begingroup\$

PHP, 37 32 bytes

-2 bytes by removing PHP start tag <? and adding it in header per gwaugh's suggestion

-3 bytes thanks to great idea of gwaugh and eliminating the need for !='' check

for(;$l.=$l=$argn[$i++];)echo$l;

Try it online!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ You don't need to include the opening <? in your byte count (-2 bytes). You can also -3 more bytes this way for 32 bytes. \$\endgroup\$
    – 640KB
    Aug 3 '19 at 19:59
  • \$\begingroup\$ @gwaugh Thanks for the great idea, edited. \$\endgroup\$
    – Night2
    Aug 5 '19 at 4:07
  • \$\begingroup\$ I don't believe you can omit the ending semicolon. As a standalone, it must still be legal PHP and run as php -r "echo 'foo';". \$\endgroup\$
    – 640KB
    Aug 5 '19 at 16:54
  • \$\begingroup\$ @gwaugh I assumed that since we can remove the starting tag, same goes for the end tag. Added semicolon and 1 byte back. \$\endgroup\$
    – Night2
    Aug 6 '19 at 6:06
  • 1
    \$\begingroup\$ The semicolon is part of the preceeding statement, so is required syntax. There is nothing to prohibit from using a close tag ?> as long as it's included in your score. If you do, then yes it's valid to omit the last semicolon, however the general consensus is you can't use a close tag unless you have a corresponding open tag. Occasionally this is helpful: example because in that case it's shorter than an echo. \$\endgroup\$
    – 640KB
    Aug 6 '19 at 15:06
3
\$\begingroup\$

MathGolf, 1 byte

^

Try it online!

Same as the Jelly answer, zip works on a character level for strings. Implicitly pops the input twice, and zips it with itself to produce a string. The first idea I had was m_ (map each character to duplicate), which produces identical output.

\$\endgroup\$
3
\$\begingroup\$

Lua, 32 31 bytes

print(((...):gsub('.','%0%0')))

Try it online!

Full program, take input as command line argument. Explanation is fairly trivial:

print(             -- Print result
    (              -- Drop second result (count of replacements, length of string for us)
        (...)      -- Take first cmd argument
        :gsub(     -- Do replacement:
            '.',   -- Take each character
            '%0%0' -- and replace it with itself (whole match) repeated twice
        )

    )
)
```
\$\endgroup\$
3
\$\begingroup\$

Gaia, 4 3 bytes

:¦$

Basically just maps the duplicate instruction to the input string, then turns the returned list into a string

Edit: turns out there was already a 1 byte answer in Gaia for this question that I missed, so my solution isn't that great

How it works

:   Duplicate
¦   Map to each character of the input string
$   Convert the returned list to a string
Auto outputs stack

Try it Online!

\$\endgroup\$
5
  • \$\begingroup\$ You don't need @ because the interpreter will implicitly push values onto the stack if needed, which is why Z works just fine. \$\endgroup\$
    – Giuseppe
    Aug 13 '19 at 10:57
  • \$\begingroup\$ Oh wow, I didn't realise that, my solution is really sub-optimal \$\endgroup\$
    – EdgyNerd
    Aug 13 '19 at 12:45
  • \$\begingroup\$ Well, I've been golfing in Gaia a bit; this is still quite good! \$\endgroup\$
    – Giuseppe
    Aug 13 '19 at 12:56
  • \$\begingroup\$ there's also 2&. \$\endgroup\$
    – Giuseppe
    Aug 13 '19 at 17:12
  • \$\begingroup\$ reading through the docs for Gaia is annoying, especially since the interpreter is rather buggy. \$\endgroup\$
    – Giuseppe
    Aug 13 '19 at 17:12
3
\$\begingroup\$

C (gcc), 57 56 bytes

Thanks to ceilingcat and gastropher for the suggestions.

The string is modified in-place, so the buffer holding the string needs to be big enough first.

i;f(char*s){for(i=strlen(s)+1;i--;s[i-~i]=s[i*2]=s[i]);}

Try it online!

C version with allocated string, 73 71 bytes

If the string buffer can't be assumed to be big enough (or writable), this version allocates a buffer to return.

f(s,t,u)char*s,*t;{for(u=t=malloc(strlen(s)*3);*t++=*s;*t++=*s++);s=u;}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Far as I could tell, there is no rule against wastefulness, so you could do malloc(strlen(s)*3) in the allocated string version to save two bytes. \$\endgroup\$
    – gastropner
    Aug 20 '19 at 2:42
  • \$\begingroup\$ You can save 13 bytes by using recursion in your in place modified version: x;f(char*s){x++;*s&&f(s+1);s[--x]=s[x]=*s;} \$\endgroup\$
    – xibu
    Dec 1 '19 at 19:39
3
\$\begingroup\$

Poetic, 46 49 bytes

+3 bytes to account for inputs that are longer than the tape will allow (unlikely, but possible).

enduring a tragedy,knowing a way i am,troubles me

Try it online!

Poetic is an esolang I created in 2018 for a class project. It's basically brainfuck with word-lengths instead of symbols.

The point of the language is to allow for programs to be written in free-verse poetry. I encourage you all to try it out sometime!

\$\endgroup\$
3
\$\begingroup\$

Keg, 11 7 6 4 3 bytes

(⑩,

Explanation

(   # Repeat length of stack times:
 ⑩  # Print without popping the top of the stack
  , # Print with popping

Try It Online!

\$\endgroup\$
7
  • \$\begingroup\$ I'm impressed! Could not have golfed it that much! About TIO for Keg: how would I go around doing that... I know that it is to be done via the chat room, but I don't know if a direct request from someone who has never had any involvement in the room would be perceived as rude. \$\endgroup\$
    – lyxal
    Jul 31 '19 at 10:37
  • \$\begingroup\$ Also, how would implicit input for Keg sound? \$\endgroup\$
    – lyxal
    Jul 31 '19 at 10:38
  • 3
    \$\begingroup\$ @Jono2906 That definitely wouldn't be rude! Leaving a ping to Dennis in talk.tryitonline.net with a link to the interpreter should be enough to get Keg on tio :) \$\endgroup\$
    – Mr. Xcoder
    Jul 31 '19 at 12:14
  • \$\begingroup\$ @A__ Try it online! \$\endgroup\$
    – lyxal
    Aug 9 '19 at 23:04
  • 2
    \$\begingroup\$ This doesn't output anything now? \$\endgroup\$
    – EdgyNerd
    Nov 3 '19 at 15:48
3
\$\begingroup\$

QBasic, 58 bytes

LINE INPUT s$
FOR i=1TO LEN(s$)*2
?MID$(s$,i/2+.1,1);
NEXT

Explanation

LINE INPUT reads all input characters until a newline into s$. We loop i from 1 up to twice the length of the string and output the i/2th character (rounded up) at each iteration. There's a slight hitch, in that QBasic rounds numbers with a fractional part of .5 up sometimes and down other times; adding a small amount like .1 is sufficient to round the halves up, while the whole numbers still get rounded back down.

\$\endgroup\$
3
\$\begingroup\$

Acc!!, 42 bytes

N
Count i while _/32 {
Write _
Write _
N
}

Try it online!

Reads one character at a time into the accumulator and outputs the accumulator twice for each character. Loops until it encounters something with an ASCII code less than 32 (newline or EOF).

\$\endgroup\$
3
\$\begingroup\$

Burlesque, 2 bytes

)J

Try it online!

) # Map (implicitly explode and apply to each character then concatenate)
J # Duplicate
\$\endgroup\$
3
\$\begingroup\$

Fortran (GFortran), 71 65 bytes

character(99)a
read*,a
print*,(a(i:i),a(i:i),i=1,len_trim(a))
end

Try it online!

Saved 6 bytes thanks to @roblogic pointing out that if the input is quoted it can be read as list-directed.

If we don't care about extra whitespace:

Fortran (GFortran), 56 bytes

character(99)a
read*,a
print*,(a(i:i),a(i:i),i=1,99)
end

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ Nice, I tried to use "proper" syntax for 100 bytes. codegolf.stackexchange.com/a/189152/15940 \$\endgroup\$
    – roblogic
    Jan 19 '20 at 9:30
  • 1
    \$\begingroup\$ @roblogic I saw, that's what inspired me to beat it. To me, there's nothing wrong with implicit loops in very rare situations (Array assignment and printing), but in golf, anything goes. \$\endgroup\$ Jan 19 '20 at 10:10
  • \$\begingroup\$ the 56-byte solution will work correctly if you assume the input string is quoted. example \$\endgroup\$
    – roblogic
    Jan 19 '20 at 10:34
  • \$\begingroup\$ @roblogic Still prints out excess whitespace, but saves bytes on the main one. \$\endgroup\$ Jan 19 '20 at 10:56
3
\$\begingroup\$

Pip, 17 16 13 11 bytes

Fi,#aL2Oa@i

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ (belatedly) You can save two more bytes by getting rid of the curly braces. \$\endgroup\$
    – DLosc
    Dec 21 '19 at 9:00
3
\$\begingroup\$

Brainetry, 85 bytes

Golfed version inspired in the program that comes after:

a b c d e f
a b c d e f g h
a b c d e f g
a b c d e f g
a b c d e f
a b c d e f g h i

To try this online, head over to this link, copy&paste the code in the btry/replit.btry file and hit the green "Run" button.

Golfed from this program:

This is almost a cat program.
This is a double speak Brainetry cat program:
For every single character of input gotten
I am supposed to output two characters.
Doing this in Brainetry is easy.
Can I get a more difficult challenge, please ?
\$\endgroup\$
3
\$\begingroup\$

MAWP, 8 bytes

|0~[!;;]

Clones each character, pops from stack twice.

Try it!

\$\endgroup\$
0
3
\$\begingroup\$

Python 3, 36 35 bytes

print(''.join(x*2for x in input()))

Try it online!

Edit 1: Saved a byte

\$\endgroup\$
2
  • 3
    \$\begingroup\$ I think you can save one byte removing the space in x*2 for. \$\endgroup\$ Sep 18 '20 at 15:24
  • \$\begingroup\$ @DomHastings Brilliant. Did the change. Thanks! \$\endgroup\$ Jan 15 at 21:42
3
\$\begingroup\$

Scala, 21 bytes

_./:("")(_+"".+(_)*2)

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ You might want to flatMap \$\endgroup\$
    – user
    Jan 18 at 15:35
  • \$\begingroup\$ @user here is already an answer using flatMap and when refactored into a lambda expression I think it has 22 bytes. \$\endgroup\$ Jan 18 at 15:44
  • 1
    \$\begingroup\$ Oops, I didn't see that. I think you can still use flatMap, in fact you can make it 20 bytes that way. It's okay if you don't want to use it, though \$\endgroup\$
    – user
    Jan 18 at 15:47
3
\$\begingroup\$

BRASCA, 6 bytes

As of writing, there's no online interpreter yet.
EDIT: There is now.

,[:oo]

Try it online!

Explanation

<implicit input>      - Push STDIN to the stack
,                     - Reverse stack
 [   ]                - While non-zero:
  :oo                 -     Output the current character twice
\$\endgroup\$
3
\$\begingroup\$

naz, 34 32 bytes

2x1v1x1f0a0x1x2f1r3x1v1e2o2f0x2f

Works for any null-terminated input string.

Try it online!

Explanation (with 0x instructions removed)

2x1v             # Set variable 1 equal to 0
1x1f0a           # Function 1
                 # Add 0 to the register
1x2f1r3x1v1e2o2f # Function 2
                 # Read a byte of input and goto function 1 if it equals variable 1
                 # Otherwise, output twice and call function 2
2f               # Call function 2
\$\endgroup\$
3
\$\begingroup\$

Python 3, 43 bytes

def d(s,o=""):
	for c in s:o+=c+c
	return o

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ 32 bytes \$\endgroup\$
    – lyxal
    Feb 15 at 2:14
  • \$\begingroup\$ FYI there's already a few Python 3 solutions. (although we don't prohibit posting your own attempts) codegolf.stackexchange.com/search?q=inquestion%3A188988+Python (I think there's also the graduation userscript that shows a leader board under every questions, but I don't use it myself) cc @Lyxal \$\endgroup\$
    – DELETE_ME
    Feb 15 at 10:12
3
\$\begingroup\$

Labyrinth, 9 8 bytes

 ,
.:@
:

Try it online!

Wins over Jonathan Allan's answer.

How it works

,    Start at the first meaningful instruction; push a char from stdin
:    Duplicate; on EOF, top is -1 so turn left and exit (@)
     otherwise, top is positive (printable ASCII) so turn right
.:.  Pop-print as char, dup, pop-print as char. Top is still the input char
:    Duplicate; turn to (,) since top is nonzero
,    This is a dead end so it runs again from the start, until EOF
\$\endgroup\$
3
\$\begingroup\$

Taxi, 390 342 335 bytes

Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Chop Suey.[A]Go to Chop Suey:n 1 r 1 l 4 r 1 l.Switch to plan B i.Pickup a passenger going to Cyclone.Go to Zoom Zoom:n 1 l 3 r.Go to Cyclone:w.[C]Pickup a passenger going to Post Office.Switch to plan B i.Switch to plan C.[B]Go to Post Office:s 1 l 2 r 1 l.Switch to plan A.

Try it online!

Explanation/Ungolfed

    [Take input string]
Go to Post Office: west 1st left, 1st right, 1st left.
Pickup a passenger going to Chop Suey.

[loop]
    [If string as a passenger, split it]
Go to Chop Suey: north 1st right, 1st left, 4th right, 1st left.
    [At the end of the string, end the program]
Switch to plan end_loop if noone is waiting.
        [any character after end_loop is fine]
    [Duplicate first character left]
Pickup a passenger going to Cyclone.
Go to Zoom Zoom: north 1st left, 3rd right.
Go to Cyclone: west.
    [Pickup character twice]
[two]
Pickup a passenger going to the Post Office.
Switch to plan end_loop if noone is waiting.
Switch to plan two.
    [Prints characters or crashes program, you can't drive that way]
[end_loop]
Go to the Post Office: south 1st left, 2nd right, 1st left.
Switch to plan loop.

Comment

It does not even matter whether we tank at Zoom Zoom or Fueler Up, both are 335 bytes.

By tanking at Fueler Up we pay so much that we don't earn enough and are out of gas for string of length 86 or more. However, even tanking at Zoom Zoom does not allow to drive infinitely, it probably stops at strings of a length around 129, I didn't test or solve this because it's an old answer.

Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Chop Suey.[A]Go to Fueler Up:n 1 r 1 l.Go to Chop Suey:n 3 r 1 l.Switch to plan B i.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 3 l.[C]Pickup a passenger going to Post Office.Switch to plan B i.Switch to plan C.[B]Go to Post Office:s 1 l 2 r 1 l.Switch to plan A.

Try it online! (With a long string)

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can save four bytes by removing the quotation marks in the "Switch to plan" commands. \$\endgroup\$
    – Dorian
    Nov 12 '19 at 10:12
3
\$\begingroup\$

Python 3.8, 31 bytes

for x in input():print(end=x*2)

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Excel, 43 bytes

=CONCAT(MID(A1,SEQUENCE(LEN(A1),2,,0.5),1))

Link to Spreadsheet

\$\endgroup\$
3
\$\begingroup\$

Vyxal, 1 byte

Y

Try it Online!

Yet another trivial answer. Y interleaves the input string with itself. It’s good that Vyxal can tie with Jelly and beat 05AB1E in matters of triviality.

\$\endgroup\$
1
  • \$\begingroup\$ Due to the way Y works, the s flag is unnecessary. \$\endgroup\$
    – emanresu A
    Sep 12 at 10:36
1 2
3
4 5
7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.